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" |
| 25 | |
| 26 | uint8_t *nicintel_bar; |
| 27 | uint8_t *nicintel_control_bar; |
| 28 | |
| 29 | const struct pcidev_status nics_intel[] = { |
| 30 | {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] | 31 | {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] | 32 | |
| 33 | {}, |
| 34 | }; |
| 35 | |
| 36 | /* Arbitrary limit, taken from the datasheet I just had lying around. |
| 37 | * 128 kByte on the 82559 device. Or not. Depends on whom you ask. |
| 38 | */ |
| 39 | #define NICINTEL_MEMMAP_SIZE (128 * 1024) |
| 40 | #define NICINTEL_MEMMAP_MASK (NICINTEL_MEMMAP_SIZE - 1) |
| 41 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 42 | #define NICINTEL_CONTROL_MEMMAP_SIZE 0x10 |
| 43 | |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 44 | #define CSR_FCR 0x0c |
| 45 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 46 | static int nicintel_shutdown(void *data) |
| 47 | { |
| 48 | physunmap(nicintel_control_bar, NICINTEL_CONTROL_MEMMAP_SIZE); |
| 49 | physunmap(nicintel_bar, NICINTEL_MEMMAP_SIZE); |
| 50 | pci_cleanup(pacc); |
| 51 | release_io_perms(); |
| 52 | return 0; |
| 53 | } |
| 54 | |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 55 | int nicintel_init(void) |
| 56 | { |
| 57 | uintptr_t addr; |
| 58 | |
| 59 | /* Needed only for PCI accesses on some platforms. |
| 60 | * FIXME: Refactor that into get_mem_perms/get_io_perms/get_pci_perms? |
| 61 | */ |
| 62 | get_io_perms(); |
| 63 | |
| 64 | /* No need to check for errors, pcidev_init() will not return in case |
| 65 | * of errors. |
| 66 | * FIXME: BAR2 is not available if the device uses the CardBus function. |
| 67 | */ |
| 68 | addr = pcidev_init(PCI_BASE_ADDRESS_2, nics_intel); |
| 69 | |
| 70 | nicintel_bar = physmap("Intel NIC flash", addr, NICINTEL_MEMMAP_SIZE); |
| 71 | if (nicintel_bar == ERROR_PTR) |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 72 | goto error_out_unmap; |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 73 | |
| 74 | /* FIXME: Using pcidev_dev _will_ cause pretty explosions in the future. */ |
| 75 | addr = pcidev_validate(pcidev_dev, PCI_BASE_ADDRESS_0, nics_intel); |
| 76 | /* FIXME: This is not an aligned mapping. Use 4k? */ |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 77 | nicintel_control_bar = physmap("Intel NIC control/status reg", |
| 78 | addr, NICINTEL_CONTROL_MEMMAP_SIZE); |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 79 | if (nicintel_control_bar == ERROR_PTR) |
| 80 | goto error_out; |
| 81 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 82 | if (register_shutdown(nicintel_shutdown, NULL)) |
| 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 | |
Carl-Daniel Hailfinger | 1a22795 | 2011-07-27 07:13:06 +0000 | [diff] [blame] | 96 | buses_supported = BUS_PARALLEL; |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 97 | |
| 98 | max_rom_decode.parallel = NICINTEL_MEMMAP_SIZE; |
| 99 | |
| 100 | return 0; |
| 101 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 102 | error_out_unmap: |
| 103 | physunmap(nicintel_bar, NICINTEL_MEMMAP_SIZE); |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 104 | error_out: |
| 105 | pci_cleanup(pacc); |
| 106 | release_io_perms(); |
| 107 | return 1; |
| 108 | } |
| 109 | |
Carl-Daniel Hailfinger | b713d2e | 2011-05-08 00:24:18 +0000 | [diff] [blame] | 110 | void nicintel_chip_writeb(uint8_t val, chipaddr addr) |
| 111 | { |
| 112 | pci_mmio_writeb(val, nicintel_bar + (addr & NICINTEL_MEMMAP_MASK)); |
| 113 | } |
| 114 | |
| 115 | uint8_t nicintel_chip_readb(const chipaddr addr) |
| 116 | { |
| 117 | return pci_mmio_readb(nicintel_bar + (addr & NICINTEL_MEMMAP_MASK)); |
| 118 | } |