blob: 4672890f7ecf9de58a18a020b8ec041bd7ea286e [file] [log] [blame]
hailfinger7949b652011-05-08 00:24:18 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2011 Carl-Daniel Hailfinger
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; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
hailfinger7949b652011-05-08 00:24:18 +000014 */
15
16/* Datasheet: http://download.intel.com/design/network/datashts/82559_Fast_Ethernet_Multifunction_PCI_Cardbus_Controller_Datasheet.pdf */
17
18#include <stdlib.h>
19#include "flash.h"
20#include "programmer.h"
Patrick Georgi5dc3d882017-03-31 16:57:08 +020021#include "hwaccess.h"
hailfinger7949b652011-05-08 00:24:18 +000022
Edward O'Callaghanef4e28b2019-06-28 13:18:41 +100023static uint8_t *nicintel_bar;
24static uint8_t *nicintel_control_bar;
hailfinger7949b652011-05-08 00:24:18 +000025
Patrick Georgi8ae16572017-03-09 15:59:25 +010026const struct dev_entry nics_intel[] = {
hailfinger7949b652011-05-08 00:24:18 +000027 {PCI_VENDOR_ID_INTEL, 0x1209, NT, "Intel", "8255xER/82551IT Fast Ethernet Controller"},
stefanctd6efe1a2011-09-03 11:22:27 +000028 {PCI_VENDOR_ID_INTEL, 0x1229, OK, "Intel", "82557/8/9/0/1 Ethernet Pro 100"},
hailfinger7949b652011-05-08 00:24:18 +000029
Patrick Georgi8ddfee92017-03-20 14:54:28 +010030 {0},
hailfinger7949b652011-05-08 00:24:18 +000031};
32
33/* Arbitrary limit, taken from the datasheet I just had lying around.
34 * 128 kByte on the 82559 device. Or not. Depends on whom you ask.
35 */
36#define NICINTEL_MEMMAP_SIZE (128 * 1024)
37#define NICINTEL_MEMMAP_MASK (NICINTEL_MEMMAP_SIZE - 1)
38
Edward O'Callaghanb034b3f2019-08-02 17:03:51 +100039#define NICINTEL_CONTROL_MEMMAP_SIZE 0x10
dhendrix0ffc2eb2011-06-14 01:35:36 +000040
hailfinger7949b652011-05-08 00:24:18 +000041#define CSR_FCR 0x0c
42
Souvik Ghoshd75cd672016-06-17 14:21:39 -070043static void nicintel_chip_writeb(const struct flashctx *flash, uint8_t val,
44 chipaddr addr);
45static uint8_t nicintel_chip_readb(const struct flashctx *flash,
46 const chipaddr addr);
Patrick Georgi0a9533a2017-02-03 19:28:38 +010047static const struct par_master par_master_nicintel = {
hailfinger76bb7e92011-11-09 23:40:00 +000048 .chip_readb = nicintel_chip_readb,
49 .chip_readw = fallback_chip_readw,
50 .chip_readl = fallback_chip_readl,
51 .chip_readn = fallback_chip_readn,
52 .chip_writeb = nicintel_chip_writeb,
53 .chip_writew = fallback_chip_writew,
54 .chip_writel = fallback_chip_writel,
55 .chip_writen = fallback_chip_writen,
56};
57
David Hendricksac1d25c2016-08-09 17:00:58 -070058int nicintel_init(void)
hailfinger7949b652011-05-08 00:24:18 +000059{
Patrick Georgi7c30fa92017-03-28 22:47:12 +020060 struct pci_dev *dev = NULL;
hailfinger7949b652011-05-08 00:24:18 +000061 uintptr_t addr;
62
63 /* Needed only for PCI accesses on some platforms.
Patrick Georgi5dc3d882017-03-31 16:57:08 +020064 * FIXME: Refactor that into get_mem_perms/rget_io_perms/get_pci_perms?
hailfinger7949b652011-05-08 00:24:18 +000065 */
Patrick Georgi2a2d67f2017-03-09 10:15:39 +010066 if (rget_io_perms())
67 return 1;
hailfinger7949b652011-05-08 00:24:18 +000068
Patrick Georgi7c30fa92017-03-28 22:47:12 +020069 /* FIXME: BAR2 is not available if the device uses the CardBus function. */
70 dev = pcidev_init(nics_intel, PCI_BASE_ADDRESS_2);
71 if (!dev)
72 return 1;
73
74 addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_2);
75 if (!addr)
76 return 1;
77
Patrick Georgi124bd002017-03-21 17:25:59 +010078 nicintel_bar = rphysmap("Intel NIC flash", addr, NICINTEL_MEMMAP_SIZE);
hailfinger7949b652011-05-08 00:24:18 +000079 if (nicintel_bar == ERROR_PTR)
Patrick Georgi124bd002017-03-21 17:25:59 +010080 return 1;
hailfinger7949b652011-05-08 00:24:18 +000081
Patrick Georgi5dc3d882017-03-31 16:57:08 +020082 addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_0);
83 if (!addr)
84 return 1;
85
Patrick Georgi124bd002017-03-21 17:25:59 +010086 nicintel_control_bar = rphysmap("Intel NIC control/status reg", addr, NICINTEL_CONTROL_MEMMAP_SIZE);
hailfinger7949b652011-05-08 00:24:18 +000087 if (nicintel_control_bar == ERROR_PTR)
dhendrix0ffc2eb2011-06-14 01:35:36 +000088 return 1;
89
hailfinger7949b652011-05-08 00:24:18 +000090 /* FIXME: This register is pretty undocumented in all publicly available
91 * documentation from Intel. Let me quote the complete info we have:
92 * "Flash Control Register: The Flash Control register allows the CPU to
93 * enable writes to an external Flash. The Flash Control Register is a
94 * 32-bit field that allows access to an external Flash device."
95 * Ah yes, we also know where it is, but we have absolutely _no_ idea
96 * what we should do with it. Write 0x0001 because we have nothing
97 * better to do with our time.
98 */
99 pci_rmmio_writew(0x0001, nicintel_control_bar + CSR_FCR);
100
hailfinger7949b652011-05-08 00:24:18 +0000101 max_rom_decode.parallel = NICINTEL_MEMMAP_SIZE;
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100102 register_par_master(&par_master_nicintel, BUS_PARALLEL);
hailfinger7949b652011-05-08 00:24:18 +0000103
104 return 0;
hailfinger7949b652011-05-08 00:24:18 +0000105}
106
Patrick Georgid4caa6b2017-03-28 21:22:55 +0200107static void nicintel_chip_writeb(const struct flashctx *flash, uint8_t val,
108 chipaddr addr)
hailfinger7949b652011-05-08 00:24:18 +0000109{
110 pci_mmio_writeb(val, nicintel_bar + (addr & NICINTEL_MEMMAP_MASK));
111}
112
Patrick Georgid4caa6b2017-03-28 21:22:55 +0200113static uint8_t nicintel_chip_readb(const struct flashctx *flash,
114 const chipaddr addr)
hailfinger7949b652011-05-08 00:24:18 +0000115{
116 return pci_mmio_readb(nicintel_bar + (addr & NICINTEL_MEMMAP_MASK));
117}