blob: 3d50e5401259ec6bf27b8ad7a1efa904ac3b2c04 [file] [log] [blame]
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2015 Joseph C. Lehner <joseph.c.lehner@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +000015 */
16
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +000017#include <string.h>
18#include <stdlib.h>
19#include "flash.h"
20#include "programmer.h"
Thomas Heijligena0655202021-12-14 16:36:05 +010021#include "hwaccess_x86_io.h"
Thomas Heijligen74b4aa02021-12-14 17:52:30 +010022#include "hwaccess_physmap.h"
Thomas Heijligend96c97c2021-11-02 21:03:00 +010023#include "platform/pci.h"
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +000024
25#define MAX_ROM_DECODE (32 * 1024)
26#define ADDR_MASK (MAX_ROM_DECODE - 1)
27
28/*
29 * In the absence of any public docs on the PDC2026x family, this programmer was created through a mix of
30 * reverse-engineering and trial and error.
31 *
32 * The only device tested is an Ultra100 controller, but the logic for programming the other 2026x controllers
33 * is the same, so it should, in theory, work for those as well.
34 *
35 * While the tested Ultra100 controller used a 128 kB MX29F001T chip, A16 and A15 showed continuity to ground,
36 * thus limiting the the programmer on this card to 32 kB. Without other controllers to test this programmer on,
37 * this is currently a hard limit. Note that ROM files for these controllers are 16 kB only.
38 *
Nico Huberc3b02dc2023-08-12 01:13:45 +020039 * Since flashprog does not support accessing flash chips larger than the size limit of the programmer (the
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +000040 * tested Ultra100 uses a 128 kB MX29F001T chip), the chip size is hackishly adjusted in atapromise_limit_chip.
41 */
42
43static uint32_t io_base_addr = 0;
44static uint32_t rom_base_addr = 0;
45
46static uint8_t *atapromise_bar = NULL;
47static size_t rom_size = 0;
48
Thomas Heijligencc853d82021-05-04 15:32:17 +020049static const struct dev_entry ata_promise[] = {
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +000050 {0x105a, 0x4d38, NT, "Promise", "PDC20262 (FastTrak66/Ultra66)"},
51 {0x105a, 0x0d30, NT, "Promise", "PDC20265 (FastTrak100 Lite/Ultra100)"},
52 {0x105a, 0x4d30, OK, "Promise", "PDC20267 (FastTrak100/Ultra100)"},
53 {0},
54};
55
56static void atapromise_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
57static uint8_t atapromise_chip_readb(const struct flashctx *flash, const chipaddr addr);
Nico Huber0e76d992023-01-12 20:22:55 +010058static void *atapromise_map(const char *descr, uintptr_t phys_addr, size_t len);
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +000059
60static const struct par_master par_master_atapromise = {
Thomas Heijligen43040f22022-06-23 14:38:35 +020061 .chip_readb = atapromise_chip_readb,
62 .chip_readw = fallback_chip_readw,
63 .chip_readl = fallback_chip_readl,
64 .chip_readn = fallback_chip_readn,
65 .chip_writeb = atapromise_chip_writeb,
66 .chip_writew = fallback_chip_writew,
67 .chip_writel = fallback_chip_writel,
68 .chip_writen = fallback_chip_writen,
Nico Huber0e76d992023-01-12 20:22:55 +010069 .map_flash = atapromise_map,
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +000070};
71
Thomas Heijligencc853d82021-05-04 15:32:17 +020072static void *atapromise_map(const char *descr, uintptr_t phys_addr, size_t len)
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +000073{
74 /* In case fallback_map ever returns something other than NULL. */
75 return NULL;
76}
77
Nico Hubere3a26882023-01-11 21:45:51 +010078static int atapromise_init(struct flashprog_programmer *const prog)
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +000079{
80 struct pci_dev *dev = NULL;
81
82 if (rget_io_perms())
83 return 1;
84
85 dev = pcidev_init(ata_promise, PCI_BASE_ADDRESS_4);
86 if (!dev)
87 return 1;
88
89 io_base_addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_4) & 0xfffe;
90 if (!io_base_addr) {
91 return 1;
92 }
93
94 /* Not exactly sure what this does, because flashing seems to work
95 * well without it. However, PTIFLASH does it, so we do it too.
96 */
97 OUTB(1, io_base_addr + 0x10);
98
99 rom_base_addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_5);
100 if (!rom_base_addr) {
101 msg_pdbg("Failed to read BAR5\n");
102 return 1;
103 }
104
105 rom_size = dev->rom_size > MAX_ROM_DECODE ? MAX_ROM_DECODE : dev->rom_size;
106 atapromise_bar = (uint8_t*)rphysmap("Promise", rom_base_addr, rom_size);
107 if (atapromise_bar == ERROR_PTR) {
108 return 1;
109 }
110
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +0000111 msg_pwarn("Do not use this device as a generic programmer. It will leave anything outside\n"
112 "the first %zu kB of the flash chip in an undefined state. It works fine for the\n"
Elyes HAOUASe2c90c42018-08-18 09:04:41 +0200113 "purpose of updating the firmware of this device (padding may necessary).\n",
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +0000114 rom_size / 1024);
115
Nico Huber47aa85c2026-02-21 14:57:20 +0100116 return register_par_master(&par_master_atapromise, BUS_PARALLEL, 0, rom_size, NULL);
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +0000117}
118
119static void atapromise_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
120{
121 uint32_t data;
122
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +0000123 data = (rom_base_addr + (addr & ADDR_MASK)) << 8 | val;
124 OUTL(data, io_base_addr + 0x14);
125}
126
127static uint8_t atapromise_chip_readb(const struct flashctx *flash, const chipaddr addr)
128{
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +0000129 return pci_mmio_readb(atapromise_bar + (addr & ADDR_MASK));
130}
131
Thomas Heijligencc853d82021-05-04 15:32:17 +0200132const struct programmer_entry programmer_atapromise = {
133 .name = "atapromise",
134 .type = PCI,
135 .devs.dev = ata_promise,
136 .init = atapromise_init,
Thomas Heijligencc853d82021-05-04 15:32:17 +0200137};