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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | /* Datasheet: http://download.intel.com/design/network/datashts/82559_Fast_Ethernet_Multifunction_PCI_Cardbus_Controller_Datasheet.pdf */ |
| 21 | |
| 22 | #include <stdlib.h> |
| 23 | #include "flash.h" |
| 24 | #include "programmer.h" |
Patrick Georgi | 32508eb | 2012-07-20 20:35:14 +0000 | [diff] [blame] | 25 | #include "hwaccess.h" |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 26 | |
| 27 | uint8_t *nicintel_bar; |
| 28 | uint8_t *nicintel_control_bar; |
| 29 | |
Stefan Tauner | 4b24a2d | 2012-12-27 18:40:36 +0000 | [diff] [blame] | 30 | const struct dev_entry nics_intel[] = { |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 31 | {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] | 32 | {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] | 33 | |
Carl-Daniel Hailfinger | 1c6d2ff | 2012-08-27 00:44:42 +0000 | [diff] [blame] | 34 | {0}, |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | /* Arbitrary limit, taken from the datasheet I just had lying around. |
| 38 | * 128 kByte on the 82559 device. Or not. Depends on whom you ask. |
| 39 | */ |
| 40 | #define NICINTEL_MEMMAP_SIZE (128 * 1024) |
| 41 | #define NICINTEL_MEMMAP_MASK (NICINTEL_MEMMAP_SIZE - 1) |
| 42 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 43 | #define NICINTEL_CONTROL_MEMMAP_SIZE 0x10 |
| 44 | |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 45 | #define CSR_FCR 0x0c |
| 46 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 47 | static void nicintel_chip_writeb(const struct flashctx *flash, uint8_t val, |
| 48 | chipaddr addr); |
| 49 | static uint8_t nicintel_chip_readb(const struct flashctx *flash, |
| 50 | const chipaddr addr); |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 51 | static const struct par_programmer par_programmer_nicintel = { |
| 52 | .chip_readb = nicintel_chip_readb, |
| 53 | .chip_readw = fallback_chip_readw, |
| 54 | .chip_readl = fallback_chip_readl, |
| 55 | .chip_readn = fallback_chip_readn, |
| 56 | .chip_writeb = nicintel_chip_writeb, |
| 57 | .chip_writew = fallback_chip_writew, |
| 58 | .chip_writel = fallback_chip_writel, |
| 59 | .chip_writen = fallback_chip_writen, |
| 60 | }; |
| 61 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 62 | static int nicintel_shutdown(void *data) |
| 63 | { |
| 64 | physunmap(nicintel_control_bar, NICINTEL_CONTROL_MEMMAP_SIZE); |
| 65 | physunmap(nicintel_bar, NICINTEL_MEMMAP_SIZE); |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 66 | return 0; |
| 67 | } |
| 68 | |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 69 | int nicintel_init(void) |
| 70 | { |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame^] | 71 | struct pci_dev *dev = NULL; |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 72 | uintptr_t addr; |
| 73 | |
| 74 | /* Needed only for PCI accesses on some platforms. |
Carl-Daniel Hailfinger | d6bb828 | 2012-07-21 17:27:08 +0000 | [diff] [blame] | 75 | * FIXME: Refactor that into get_mem_perms/rget_io_perms/get_pci_perms? |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 76 | */ |
Carl-Daniel Hailfinger | d6bb828 | 2012-07-21 17:27:08 +0000 | [diff] [blame] | 77 | if (rget_io_perms()) |
| 78 | return 1; |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 79 | |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame^] | 80 | /* FIXME: BAR2 is not available if the device uses the CardBus function. */ |
| 81 | dev = pcidev_init(nics_intel, PCI_BASE_ADDRESS_2); |
| 82 | if (!dev) |
| 83 | return 1; |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 84 | |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame^] | 85 | addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_2); |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 86 | nicintel_bar = physmap("Intel NIC flash", addr, NICINTEL_MEMMAP_SIZE); |
| 87 | if (nicintel_bar == ERROR_PTR) |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 88 | goto error_out_unmap; |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 89 | |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame^] | 90 | addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_0); |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 91 | /* FIXME: This is not an aligned mapping. Use 4k? */ |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 92 | nicintel_control_bar = physmap("Intel NIC control/status reg", |
| 93 | addr, NICINTEL_CONTROL_MEMMAP_SIZE); |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 94 | if (nicintel_control_bar == ERROR_PTR) |
| 95 | goto error_out; |
| 96 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 97 | if (register_shutdown(nicintel_shutdown, NULL)) |
| 98 | return 1; |
| 99 | |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 100 | /* FIXME: This register is pretty undocumented in all publicly available |
| 101 | * documentation from Intel. Let me quote the complete info we have: |
| 102 | * "Flash Control Register: The Flash Control register allows the CPU to |
| 103 | * enable writes to an external Flash. The Flash Control Register is a |
| 104 | * 32-bit field that allows access to an external Flash device." |
| 105 | * Ah yes, we also know where it is, but we have absolutely _no_ idea |
| 106 | * what we should do with it. Write 0x0001 because we have nothing |
| 107 | * better to do with our time. |
| 108 | */ |
| 109 | pci_rmmio_writew(0x0001, nicintel_control_bar + CSR_FCR); |
| 110 | |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 111 | max_rom_decode.parallel = NICINTEL_MEMMAP_SIZE; |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 112 | register_par_programmer(&par_programmer_nicintel, BUS_PARALLEL); |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 113 | |
| 114 | return 0; |
| 115 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 116 | error_out_unmap: |
| 117 | physunmap(nicintel_bar, NICINTEL_MEMMAP_SIZE); |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 118 | error_out: |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 119 | return 1; |
| 120 | } |
| 121 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 122 | static void nicintel_chip_writeb(const struct flashctx *flash, uint8_t val, |
| 123 | chipaddr addr) |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 124 | { |
| 125 | pci_mmio_writeb(val, nicintel_bar + (addr & NICINTEL_MEMMAP_MASK)); |
| 126 | } |
| 127 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 128 | static uint8_t nicintel_chip_readb(const struct flashctx *flash, |
| 129 | const chipaddr addr) |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 130 | { |
| 131 | return pci_mmio_readb(nicintel_bar + (addr & NICINTEL_MEMMAP_MASK)); |
| 132 | } |