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"}, |
| 31 | {PCI_VENDOR_ID_INTEL, 0x1229, NT, "Intel", "82557/8/9/0/1 Ethernet Pro 100"}, |
| 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 | |
| 42 | #define CSR_FCR 0x0c |
| 43 | |
| 44 | int nicintel_init(void) |
| 45 | { |
| 46 | uintptr_t addr; |
| 47 | |
| 48 | /* Needed only for PCI accesses on some platforms. |
| 49 | * FIXME: Refactor that into get_mem_perms/get_io_perms/get_pci_perms? |
| 50 | */ |
| 51 | get_io_perms(); |
| 52 | |
| 53 | /* No need to check for errors, pcidev_init() will not return in case |
| 54 | * of errors. |
| 55 | * FIXME: BAR2 is not available if the device uses the CardBus function. |
| 56 | */ |
| 57 | addr = pcidev_init(PCI_BASE_ADDRESS_2, nics_intel); |
| 58 | |
| 59 | nicintel_bar = physmap("Intel NIC flash", addr, NICINTEL_MEMMAP_SIZE); |
| 60 | if (nicintel_bar == ERROR_PTR) |
| 61 | goto error_out; |
| 62 | |
| 63 | /* FIXME: Using pcidev_dev _will_ cause pretty explosions in the future. */ |
| 64 | addr = pcidev_validate(pcidev_dev, PCI_BASE_ADDRESS_0, nics_intel); |
| 65 | /* FIXME: This is not an aligned mapping. Use 4k? */ |
| 66 | nicintel_control_bar = physmap("Intel NIC control/status reg", addr, 0x10); |
| 67 | if (nicintel_control_bar == ERROR_PTR) |
| 68 | goto error_out; |
| 69 | |
| 70 | /* FIXME: This register is pretty undocumented in all publicly available |
| 71 | * documentation from Intel. Let me quote the complete info we have: |
| 72 | * "Flash Control Register: The Flash Control register allows the CPU to |
| 73 | * enable writes to an external Flash. The Flash Control Register is a |
| 74 | * 32-bit field that allows access to an external Flash device." |
| 75 | * Ah yes, we also know where it is, but we have absolutely _no_ idea |
| 76 | * what we should do with it. Write 0x0001 because we have nothing |
| 77 | * better to do with our time. |
| 78 | */ |
| 79 | pci_rmmio_writew(0x0001, nicintel_control_bar + CSR_FCR); |
| 80 | |
| 81 | buses_supported = CHIP_BUSTYPE_PARALLEL; |
| 82 | |
| 83 | max_rom_decode.parallel = NICINTEL_MEMMAP_SIZE; |
| 84 | |
| 85 | return 0; |
| 86 | |
| 87 | error_out: |
| 88 | pci_cleanup(pacc); |
| 89 | release_io_perms(); |
| 90 | return 1; |
| 91 | } |
| 92 | |
| 93 | int nicintel_shutdown(void) |
| 94 | { |
| 95 | physunmap(nicintel_bar, NICINTEL_MEMMAP_SIZE); |
| 96 | pci_cleanup(pacc); |
| 97 | release_io_perms(); |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | void nicintel_chip_writeb(uint8_t val, chipaddr addr) |
| 102 | { |
| 103 | pci_mmio_writeb(val, nicintel_bar + (addr & NICINTEL_MEMMAP_MASK)); |
| 104 | } |
| 105 | |
| 106 | uint8_t nicintel_chip_readb(const chipaddr addr) |
| 107 | { |
| 108 | return pci_mmio_readb(nicintel_bar + (addr & NICINTEL_MEMMAP_MASK)); |
| 109 | } |