Uwe Hermann | b4dcb71 | 2009-05-13 11:36:06 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de> |
| 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; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | #include <errno.h> |
| 24 | #include <sys/io.h> |
| 25 | #include <pci/pci.h> |
| 26 | #include "flash.h" |
| 27 | |
| 28 | #define BIOS_ROM_ADDR 0x04 |
| 29 | #define BIOS_ROM_DATA 0x08 |
| 30 | #define INT_STATUS 0x0e |
| 31 | #define SELECT_REG_WINDOW 0x800 |
| 32 | |
| 33 | #define PCI_IO_BASE_ADDRESS 0x10 |
| 34 | |
| 35 | #define PCI_VENDOR_ID_3COM 0x10b7 |
| 36 | |
| 37 | uint32_t io_base_addr; |
| 38 | struct pci_access *pacc; |
| 39 | |
| 40 | #define OK 0 |
| 41 | #define NT 1 /* Not tested */ |
| 42 | |
| 43 | static struct nic_status { |
| 44 | uint16_t device_id; |
| 45 | int status; |
| 46 | const char *device_name; |
| 47 | } nics[] = { |
| 48 | /* 3C90xB */ |
| 49 | {0x9055, NT, "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-TX"}, |
| 50 | {0x9001, NT, "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-T4" }, |
| 51 | {0x9004, NT, "3C90xB: PCI 10BASE-T (TPO)" }, |
| 52 | {0x9005, NT, "3C90xB: PCI 10BASE-T/10BASE2/AUI (COMBO)" }, |
| 53 | {0x9006, NT, "3C90xB: PCI 10BASE-T/10BASE2 (TPC)" }, |
| 54 | {0x900a, NT, "3C90xB: PCI 10BASE-FL" }, |
| 55 | {0x905a, NT, "3C90xB: PCI 10BASE-FX" }, |
| 56 | |
| 57 | /* 3C905C */ |
| 58 | {0x9200, OK, "3C905C: EtherLink 10/100 PCI (TX)" }, |
| 59 | |
| 60 | /* 3C980C */ |
| 61 | {0x9805, NT, "3C980C: EtherLink Server 10/100 PCI (TX)" }, |
| 62 | |
| 63 | {}, |
| 64 | }; |
| 65 | |
| 66 | int nic3com_init(void) |
| 67 | { |
| 68 | int i, found = 0; |
| 69 | struct pci_dev *dev; |
| 70 | |
| 71 | #if defined (__sun) && (defined(__i386) || defined(__amd64)) |
| 72 | if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0) { |
| 73 | #elif defined(__FreeBSD__) || defined (__DragonFly__) |
| 74 | if ((io_fd = open("/dev/io", O_RDWR)) < 0) { |
| 75 | #else |
| 76 | if (iopl(3) != 0) { |
| 77 | #endif |
| 78 | fprintf(stderr, "ERROR: Could not get IO privileges (%s).\n" |
| 79 | "You need to be root.\n", strerror(errno)); |
| 80 | exit(1); |
| 81 | } |
| 82 | |
| 83 | pacc = pci_alloc(); /* Get the pci_access structure */ |
| 84 | pci_init(pacc); /* Initialize the PCI library */ |
| 85 | pci_scan_bus(pacc); /* We want to get the list of devices */ |
| 86 | |
| 87 | for (i = 0; nics[i].device_name != NULL; i++) { |
| 88 | dev = pci_dev_find(PCI_VENDOR_ID_3COM, nics[i].device_id); |
| 89 | if (!dev) |
| 90 | continue; |
| 91 | |
| 92 | io_base_addr = pci_read_long(dev, PCI_IO_BASE_ADDRESS) & ~0x03; |
| 93 | |
| 94 | printf("Found NIC \"3COM %s\" (%04x:%04x), addr = 0x%x\n", |
| 95 | nics[i].device_name, PCI_VENDOR_ID_3COM, |
| 96 | nics[i].device_id, io_base_addr); |
| 97 | |
| 98 | if (nics[i].status == NT) { |
| 99 | printf("===\nThis NIC is UNTESTED. Please email a " |
| 100 | "report including the 'flashrom -p nic3com'\n" |
| 101 | "output to flashrom@coreboot.org if it works " |
| 102 | "for you. Thank you for your help!\n===\n"); |
| 103 | } |
| 104 | |
| 105 | found = 1; |
| 106 | break; |
| 107 | } |
| 108 | |
| 109 | if (!found) { |
| 110 | fprintf(stderr, "Error: No supported 3COM NIC found.\n"); |
| 111 | exit(1); |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | * The lowest 16 bytes of the I/O mapped register space of (most) 3COM |
| 116 | * cards form a 'register window' into one of multiple (usually 8) |
| 117 | * register banks. For 3C90xB/3C90xC we need register window/bank 0. |
| 118 | */ |
| 119 | OUTW(SELECT_REG_WINDOW + 0, io_base_addr + INT_STATUS); |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | int nic3com_shutdown(void) |
| 125 | { |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | void *nic3com_map(const char *descr, unsigned long phys_addr, size_t len) |
| 130 | { |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | void nic3com_unmap(void *virt_addr, size_t len) |
| 135 | { |
| 136 | } |
| 137 | |
| 138 | void nic3com_chip_writeb(uint8_t val, volatile void *addr) |
| 139 | { |
| 140 | OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR); |
| 141 | OUTB(val, io_base_addr + BIOS_ROM_DATA); |
| 142 | } |
| 143 | |
| 144 | void nic3com_chip_writew(uint16_t val, volatile void *addr) |
| 145 | { |
| 146 | } |
| 147 | |
| 148 | void nic3com_chip_writel(uint32_t val, volatile void *addr) |
| 149 | { |
| 150 | } |
| 151 | |
| 152 | uint8_t nic3com_chip_readb(const volatile void *addr) |
| 153 | { |
| 154 | uint8_t val; |
| 155 | |
| 156 | OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR); |
| 157 | val = INB(io_base_addr + BIOS_ROM_DATA); |
| 158 | |
| 159 | return val; |
| 160 | } |
| 161 | |
| 162 | uint16_t nic3com_chip_readw(const volatile void *addr) |
| 163 | { |
| 164 | return 0xffff; |
| 165 | } |
| 166 | |
| 167 | uint32_t nic3com_chip_readl(const volatile void *addr) |
| 168 | { |
| 169 | return 0xffffffff; |
| 170 | } |