blob: bc85ce5bca9e6f625dba924b16f0b7fa01ae9e43 [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 Hermann92c53ee2009-05-13 12:01:57 +000042#if defined(__FreeBSD__) || defined(__DragonFly__)
43int io_fd;
44#endif
45
Uwe Hermannb4dcb712009-05-13 11:36:06 +000046#define OK 0
47#define NT 1 /* Not tested */
48
49static struct nic_status {
50 uint16_t device_id;
51 int status;
52 const char *device_name;
53} nics[] = {
54 /* 3C90xB */
55 {0x9055, NT, "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-TX"},
56 {0x9001, NT, "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-T4" },
57 {0x9004, NT, "3C90xB: PCI 10BASE-T (TPO)" },
58 {0x9005, NT, "3C90xB: PCI 10BASE-T/10BASE2/AUI (COMBO)" },
59 {0x9006, NT, "3C90xB: PCI 10BASE-T/10BASE2 (TPC)" },
60 {0x900a, NT, "3C90xB: PCI 10BASE-FL" },
61 {0x905a, NT, "3C90xB: PCI 10BASE-FX" },
62
63 /* 3C905C */
64 {0x9200, OK, "3C905C: EtherLink 10/100 PCI (TX)" },
65
66 /* 3C980C */
67 {0x9805, NT, "3C980C: EtherLink Server 10/100 PCI (TX)" },
68
69 {},
70};
71
Christian Ruppert0cdb0312009-05-14 18:57:26 +000072uint32_t nic3com_validate(struct pci_dev *dev)
73{
74 int i = 0;
75 uint32_t addr = -1;
76
77 for (i = 0; nics[i].device_name != NULL; i++) {
78 if (dev->device_id != nics[i].device_id)
79 continue;
80
81 addr = pci_read_long(dev, PCI_IO_BASE_ADDRESS) & ~0x03;
82
83 printf("Found NIC \"3COM %s\" (%04x:%04x), addr = 0x%x\n",
84 nics[i].device_name, PCI_VENDOR_ID_3COM,
85 nics[i].device_id, addr);
86
87 if (nics[i].status == NT) {
88 printf("===\nThis NIC is UNTESTED. Please email a "
89 "report including the 'flashrom -p nic3com'\n"
90 "output to flashrom@coreboot.org if it works "
91 "for you. Thank you for your help!\n===\n");
92 }
93
94 return addr;
95 }
96
97 return addr;
98}
99
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000100int nic3com_init(void)
101{
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000102 struct pci_dev *dev;
Christian Ruppert0cdb0312009-05-14 18:57:26 +0000103 char *msg = NULL;
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000104
105#if defined (__sun) && (defined(__i386) || defined(__amd64))
106 if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0) {
107#elif defined(__FreeBSD__) || defined (__DragonFly__)
108 if ((io_fd = open("/dev/io", O_RDWR)) < 0) {
109#else
110 if (iopl(3) != 0) {
111#endif
112 fprintf(stderr, "ERROR: Could not get IO privileges (%s).\n"
113 "You need to be root.\n", strerror(errno));
114 exit(1);
115 }
116
117 pacc = pci_alloc(); /* Get the pci_access structure */
118 pci_init(pacc); /* Initialize the PCI library */
119 pci_scan_bus(pacc); /* We want to get the list of devices */
120
Christian Ruppert0cdb0312009-05-14 18:57:26 +0000121 if (nic_pcidev != NULL) {
122 pci_filter_init(pacc, &filter);
123
124 if ((msg = pci_filter_parse_slot(&filter, nic_pcidev))) {
125 fprintf(stderr, "Error: %s\n", msg);
126 exit(1);
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000127 }
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000128 }
129
Christian Ruppert0cdb0312009-05-14 18:57:26 +0000130 if (!filter.vendor && !filter.device) {
131 pci_filter_init(pacc, &filter);
132 filter.vendor = PCI_VENDOR_ID_3COM;
133 }
134
135 dev = pci_dev_find_filter(filter);
136
137 if (dev && (dev->vendor_id == PCI_VENDOR_ID_3COM))
138 io_base_addr = nic3com_validate(dev);
139 else {
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000140 fprintf(stderr, "Error: No supported 3COM NIC found.\n");
141 exit(1);
142 }
143
144 /*
145 * The lowest 16 bytes of the I/O mapped register space of (most) 3COM
146 * cards form a 'register window' into one of multiple (usually 8)
147 * register banks. For 3C90xB/3C90xC we need register window/bank 0.
148 */
149 OUTW(SELECT_REG_WINDOW + 0, io_base_addr + INT_STATUS);
150
151 return 0;
152}
153
154int nic3com_shutdown(void)
155{
Christian Ruppert0cdb0312009-05-14 18:57:26 +0000156 free(nic_pcidev);
157 pci_cleanup(pacc);
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000158 return 0;
159}
160
161void *nic3com_map(const char *descr, unsigned long phys_addr, size_t len)
162{
163 return 0;
164}
165
166void nic3com_unmap(void *virt_addr, size_t len)
167{
168}
169
170void nic3com_chip_writeb(uint8_t val, volatile void *addr)
171{
172 OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
173 OUTB(val, io_base_addr + BIOS_ROM_DATA);
174}
175
176void nic3com_chip_writew(uint16_t val, volatile void *addr)
177{
178}
179
180void nic3com_chip_writel(uint32_t val, volatile void *addr)
181{
182}
183
184uint8_t nic3com_chip_readb(const volatile void *addr)
185{
186 uint8_t val;
187
188 OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
189 val = INB(io_base_addr + BIOS_ROM_DATA);
190
191 return val;
192}
193
194uint16_t nic3com_chip_readw(const volatile void *addr)
195{
196 return 0xffff;
197}
198
199uint32_t nic3com_chip_readl(const volatile void *addr)
200{
201 return 0xffffffff;
202}