blob: a60f594b429f71501175de93ad5f36e7f26a0311 [file] [log] [blame]
Uwe Hermannb4dcb712009-05-13 11:36:06 +00001/*
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>
Uwe Hermann92c53ee2009-05-13 12:01:57 +000023#include <fcntl.h>
24#include <sys/types.h>
25#include <sys/stat.h>
Uwe Hermannb4dcb712009-05-13 11:36:06 +000026#include <errno.h>
Uwe Hermannb4dcb712009-05-13 11:36:06 +000027#include "flash.h"
28
29#define BIOS_ROM_ADDR 0x04
30#define BIOS_ROM_DATA 0x08
31#define INT_STATUS 0x0e
32#define SELECT_REG_WINDOW 0x800
33
34#define PCI_IO_BASE_ADDRESS 0x10
35
36#define PCI_VENDOR_ID_3COM 0x10b7
37
38uint32_t io_base_addr;
39struct pci_access *pacc;
Christian Ruppert0cdb0312009-05-14 18:57:26 +000040struct pci_filter filter;
Uwe Hermannb4dcb712009-05-13 11:36:06 +000041
Uwe Hermannb4dcb712009-05-13 11:36:06 +000042#define OK 0
43#define NT 1 /* Not tested */
44
45static struct nic_status {
46 uint16_t device_id;
47 int status;
48 const char *device_name;
49} nics[] = {
50 /* 3C90xB */
51 {0x9055, NT, "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-TX"},
52 {0x9001, NT, "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-T4" },
53 {0x9004, NT, "3C90xB: PCI 10BASE-T (TPO)" },
54 {0x9005, NT, "3C90xB: PCI 10BASE-T/10BASE2/AUI (COMBO)" },
55 {0x9006, NT, "3C90xB: PCI 10BASE-T/10BASE2 (TPC)" },
56 {0x900a, NT, "3C90xB: PCI 10BASE-FL" },
57 {0x905a, NT, "3C90xB: PCI 10BASE-FX" },
58
59 /* 3C905C */
60 {0x9200, OK, "3C905C: EtherLink 10/100 PCI (TX)" },
61
62 /* 3C980C */
63 {0x9805, NT, "3C980C: EtherLink Server 10/100 PCI (TX)" },
64
65 {},
66};
67
Christian Ruppert0cdb0312009-05-14 18:57:26 +000068uint32_t nic3com_validate(struct pci_dev *dev)
69{
70 int i = 0;
71 uint32_t addr = -1;
72
73 for (i = 0; nics[i].device_name != NULL; i++) {
74 if (dev->device_id != nics[i].device_id)
75 continue;
76
77 addr = pci_read_long(dev, PCI_IO_BASE_ADDRESS) & ~0x03;
78
79 printf("Found NIC \"3COM %s\" (%04x:%04x), addr = 0x%x\n",
80 nics[i].device_name, PCI_VENDOR_ID_3COM,
81 nics[i].device_id, addr);
82
83 if (nics[i].status == NT) {
84 printf("===\nThis NIC is UNTESTED. Please email a "
85 "report including the 'flashrom -p nic3com'\n"
86 "output to flashrom@coreboot.org if it works "
87 "for you. Thank you for your help!\n===\n");
88 }
89
90 return addr;
91 }
92
93 return addr;
94}
95
Uwe Hermannb4dcb712009-05-13 11:36:06 +000096int nic3com_init(void)
97{
Uwe Hermannb4dcb712009-05-13 11:36:06 +000098 struct pci_dev *dev;
Christian Ruppert0cdb0312009-05-14 18:57:26 +000099 char *msg = NULL;
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000100
Uwe Hermanna0869322009-05-14 20:41:57 +0000101 get_io_perms();
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000102
103 pacc = pci_alloc(); /* Get the pci_access structure */
104 pci_init(pacc); /* Initialize the PCI library */
105 pci_scan_bus(pacc); /* We want to get the list of devices */
106
Christian Ruppert0cdb0312009-05-14 18:57:26 +0000107 if (nic_pcidev != NULL) {
108 pci_filter_init(pacc, &filter);
109
110 if ((msg = pci_filter_parse_slot(&filter, nic_pcidev))) {
111 fprintf(stderr, "Error: %s\n", msg);
112 exit(1);
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000113 }
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000114 }
115
Christian Ruppert0cdb0312009-05-14 18:57:26 +0000116 if (!filter.vendor && !filter.device) {
117 pci_filter_init(pacc, &filter);
118 filter.vendor = PCI_VENDOR_ID_3COM;
119 }
120
121 dev = pci_dev_find_filter(filter);
122
123 if (dev && (dev->vendor_id == PCI_VENDOR_ID_3COM))
124 io_base_addr = nic3com_validate(dev);
125 else {
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000126 fprintf(stderr, "Error: No supported 3COM NIC found.\n");
127 exit(1);
128 }
129
130 /*
131 * The lowest 16 bytes of the I/O mapped register space of (most) 3COM
132 * cards form a 'register window' into one of multiple (usually 8)
133 * register banks. For 3C90xB/3C90xC we need register window/bank 0.
134 */
135 OUTW(SELECT_REG_WINDOW + 0, io_base_addr + INT_STATUS);
136
137 return 0;
138}
139
140int nic3com_shutdown(void)
141{
Christian Ruppert0cdb0312009-05-14 18:57:26 +0000142 free(nic_pcidev);
143 pci_cleanup(pacc);
Uwe Hermanna0869322009-05-14 20:41:57 +0000144#if defined(__FreeBSD__) || defined(__DragonFly__)
145 close(io_fd);
146#endif
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000147 return 0;
148}
149
150void *nic3com_map(const char *descr, unsigned long phys_addr, size_t len)
151{
152 return 0;
153}
154
155void nic3com_unmap(void *virt_addr, size_t len)
156{
157}
158
159void nic3com_chip_writeb(uint8_t val, volatile void *addr)
160{
161 OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
162 OUTB(val, io_base_addr + BIOS_ROM_DATA);
163}
164
165void nic3com_chip_writew(uint16_t val, volatile void *addr)
166{
167}
168
169void nic3com_chip_writel(uint32_t val, volatile void *addr)
170{
171}
172
173uint8_t nic3com_chip_readb(const volatile void *addr)
174{
175 uint8_t val;
176
177 OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
178 val = INB(io_base_addr + BIOS_ROM_DATA);
179
180 return val;
181}
182
183uint16_t nic3com_chip_readw(const volatile void *addr)
184{
185 return 0xffff;
186}
187
188uint32_t nic3com_chip_readl(const volatile void *addr)
189{
190 return 0xffffffff;
191}