blob: 0b5433ebcac17ec349caef64d05231a91b465d25 [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 <pci/pci.h>
28#include "flash.h"
29
30#define BIOS_ROM_ADDR 0x04
31#define BIOS_ROM_DATA 0x08
32#define INT_STATUS 0x0e
33#define SELECT_REG_WINDOW 0x800
34
35#define PCI_IO_BASE_ADDRESS 0x10
36
37#define PCI_VENDOR_ID_3COM 0x10b7
38
39uint32_t io_base_addr;
40struct pci_access *pacc;
41
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
72int nic3com_init(void)
73{
74 int i, found = 0;
75 struct pci_dev *dev;
76
77#if defined (__sun) && (defined(__i386) || defined(__amd64))
78 if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0) {
79#elif defined(__FreeBSD__) || defined (__DragonFly__)
80 if ((io_fd = open("/dev/io", O_RDWR)) < 0) {
81#else
82 if (iopl(3) != 0) {
83#endif
84 fprintf(stderr, "ERROR: Could not get IO privileges (%s).\n"
85 "You need to be root.\n", strerror(errno));
86 exit(1);
87 }
88
89 pacc = pci_alloc(); /* Get the pci_access structure */
90 pci_init(pacc); /* Initialize the PCI library */
91 pci_scan_bus(pacc); /* We want to get the list of devices */
92
93 for (i = 0; nics[i].device_name != NULL; i++) {
94 dev = pci_dev_find(PCI_VENDOR_ID_3COM, nics[i].device_id);
95 if (!dev)
96 continue;
97
98 io_base_addr = pci_read_long(dev, PCI_IO_BASE_ADDRESS) & ~0x03;
99
100 printf("Found NIC \"3COM %s\" (%04x:%04x), addr = 0x%x\n",
101 nics[i].device_name, PCI_VENDOR_ID_3COM,
102 nics[i].device_id, io_base_addr);
103
104 if (nics[i].status == NT) {
105 printf("===\nThis NIC is UNTESTED. Please email a "
106 "report including the 'flashrom -p nic3com'\n"
107 "output to flashrom@coreboot.org if it works "
108 "for you. Thank you for your help!\n===\n");
109 }
110
111 found = 1;
112 break;
113 }
114
115 if (!found) {
116 fprintf(stderr, "Error: No supported 3COM NIC found.\n");
117 exit(1);
118 }
119
120 /*
121 * The lowest 16 bytes of the I/O mapped register space of (most) 3COM
122 * cards form a 'register window' into one of multiple (usually 8)
123 * register banks. For 3C90xB/3C90xC we need register window/bank 0.
124 */
125 OUTW(SELECT_REG_WINDOW + 0, io_base_addr + INT_STATUS);
126
127 return 0;
128}
129
130int nic3com_shutdown(void)
131{
132 return 0;
133}
134
135void *nic3com_map(const char *descr, unsigned long phys_addr, size_t len)
136{
137 return 0;
138}
139
140void nic3com_unmap(void *virt_addr, size_t len)
141{
142}
143
144void nic3com_chip_writeb(uint8_t val, volatile void *addr)
145{
146 OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
147 OUTB(val, io_base_addr + BIOS_ROM_DATA);
148}
149
150void nic3com_chip_writew(uint16_t val, volatile void *addr)
151{
152}
153
154void nic3com_chip_writel(uint32_t val, volatile void *addr)
155{
156}
157
158uint8_t nic3com_chip_readb(const volatile void *addr)
159{
160 uint8_t val;
161
162 OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
163 val = INB(io_base_addr + BIOS_ROM_DATA);
164
165 return val;
166}
167
168uint16_t nic3com_chip_readw(const volatile void *addr)
169{
170 return 0xffff;
171}
172
173uint32_t nic3com_chip_readl(const volatile void *addr)
174{
175 return 0xffffffff;
176}