Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 1 | /* |
| 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. |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 14 | */ |
| 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" |
Thomas Heijligen | 74b4aa0 | 2021-12-14 17:52:30 +0100 | [diff] [blame] | 21 | #include "hwaccess_physmap.h" |
Thomas Heijligen | d96c97c | 2021-11-02 21:03:00 +0100 | [diff] [blame] | 22 | #include "platform/pci.h" |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 23 | |
Jacob Garber | afc3ad6 | 2019-06-24 16:05:28 -0600 | [diff] [blame] | 24 | static uint8_t *nicintel_bar; |
| 25 | static uint8_t *nicintel_control_bar; |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 26 | |
Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 27 | static const struct dev_entry nics_intel[] = { |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 28 | {PCI_VENDOR_ID_INTEL, 0x1209, NT, "Intel", "8255xER/82551IT Fast Ethernet Controller"}, |
Sylvain "ythier" Hitier | 3093f8f | 2011-09-03 11:22:27 +0000 | [diff] [blame] | 29 | {PCI_VENDOR_ID_INTEL, 0x1229, OK, "Intel", "82557/8/9/0/1 Ethernet Pro 100"}, |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 30 | |
Carl-Daniel Hailfinger | 1c6d2ff | 2012-08-27 00:44:42 +0000 | [diff] [blame] | 31 | {0}, |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | /* Arbitrary limit, taken from the datasheet I just had lying around. |
| 35 | * 128 kByte on the 82559 device. Or not. Depends on whom you ask. |
| 36 | */ |
| 37 | #define NICINTEL_MEMMAP_SIZE (128 * 1024) |
| 38 | #define NICINTEL_MEMMAP_MASK (NICINTEL_MEMMAP_SIZE - 1) |
| 39 | |
Elyes HAOUAS | 124ef38 | 2018-03-27 12:15:09 +0200 | [diff] [blame] | 40 | #define NICINTEL_CONTROL_MEMMAP_SIZE 0x10 |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 41 | |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 42 | #define CSR_FCR 0x0c |
| 43 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 44 | static void nicintel_chip_writeb(const struct flashctx *flash, uint8_t val, |
| 45 | chipaddr addr); |
| 46 | static uint8_t nicintel_chip_readb(const struct flashctx *flash, |
| 47 | const chipaddr addr); |
Carl-Daniel Hailfinger | a5bcbce | 2014-07-19 22:03:29 +0000 | [diff] [blame] | 48 | static const struct par_master par_master_nicintel = { |
Thomas Heijligen | 43040f2 | 2022-06-23 14:38:35 +0200 | [diff] [blame] | 49 | .chip_readb = nicintel_chip_readb, |
| 50 | .chip_readw = fallback_chip_readw, |
| 51 | .chip_readl = fallback_chip_readl, |
| 52 | .chip_readn = fallback_chip_readn, |
| 53 | .chip_writeb = nicintel_chip_writeb, |
| 54 | .chip_writew = fallback_chip_writew, |
| 55 | .chip_writel = fallback_chip_writel, |
| 56 | .chip_writen = fallback_chip_writen, |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Nico Huber | e3a2688 | 2023-01-11 21:45:51 +0100 | [diff] [blame] | 59 | static int nicintel_init(struct flashprog_programmer *const prog) |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 60 | { |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame] | 61 | struct pci_dev *dev = NULL; |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 62 | uintptr_t addr; |
| 63 | |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame] | 64 | /* FIXME: BAR2 is not available if the device uses the CardBus function. */ |
| 65 | dev = pcidev_init(nics_intel, PCI_BASE_ADDRESS_2); |
| 66 | if (!dev) |
| 67 | return 1; |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 68 | |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame] | 69 | addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_2); |
Niklas Söderlund | 89edf36 | 2013-08-23 23:29:23 +0000 | [diff] [blame] | 70 | if (!addr) |
| 71 | return 1; |
| 72 | |
Stefan Tauner | 7fb5aa0 | 2013-08-14 15:48:44 +0000 | [diff] [blame] | 73 | nicintel_bar = rphysmap("Intel NIC flash", addr, NICINTEL_MEMMAP_SIZE); |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 74 | if (nicintel_bar == ERROR_PTR) |
Stefan Tauner | 7fb5aa0 | 2013-08-14 15:48:44 +0000 | [diff] [blame] | 75 | return 1; |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 76 | |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame] | 77 | addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_0); |
Niklas Söderlund | 89edf36 | 2013-08-23 23:29:23 +0000 | [diff] [blame] | 78 | if (!addr) |
| 79 | return 1; |
| 80 | |
Stefan Tauner | 7fb5aa0 | 2013-08-14 15:48:44 +0000 | [diff] [blame] | 81 | nicintel_control_bar = rphysmap("Intel NIC control/status reg", addr, NICINTEL_CONTROL_MEMMAP_SIZE); |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 82 | if (nicintel_control_bar == ERROR_PTR) |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 83 | return 1; |
| 84 | |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 85 | /* FIXME: This register is pretty undocumented in all publicly available |
| 86 | * documentation from Intel. Let me quote the complete info we have: |
| 87 | * "Flash Control Register: The Flash Control register allows the CPU to |
| 88 | * enable writes to an external Flash. The Flash Control Register is a |
| 89 | * 32-bit field that allows access to an external Flash device." |
| 90 | * Ah yes, we also know where it is, but we have absolutely _no_ idea |
| 91 | * what we should do with it. Write 0x0001 because we have nothing |
| 92 | * better to do with our time. |
| 93 | */ |
| 94 | pci_rmmio_writew(0x0001, nicintel_control_bar + CSR_FCR); |
| 95 | |
Nico Huber | 89569d6 | 2023-01-12 23:31:40 +0100 | [diff] [blame] | 96 | return register_par_master(&par_master_nicintel, BUS_PARALLEL, NICINTEL_MEMMAP_SIZE, NULL); |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 99 | static void nicintel_chip_writeb(const struct flashctx *flash, uint8_t val, |
| 100 | chipaddr addr) |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 101 | { |
| 102 | pci_mmio_writeb(val, nicintel_bar + (addr & NICINTEL_MEMMAP_MASK)); |
| 103 | } |
| 104 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 105 | static uint8_t nicintel_chip_readb(const struct flashctx *flash, |
| 106 | const chipaddr addr) |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 107 | { |
| 108 | return pci_mmio_readb(nicintel_bar + (addr & NICINTEL_MEMMAP_MASK)); |
| 109 | } |
Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 110 | |
| 111 | const struct programmer_entry programmer_nicintel = { |
| 112 | .name = "nicintel", |
| 113 | .type = PCI, |
| 114 | .devs.dev = nics_intel, |
| 115 | .init = nicintel_init, |
Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 116 | }; |