1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#include <linux/types.h>
36#include <linux/pci.h>
37#include <linux/kernel.h>
38#include <linux/init.h>
39#include <linux/mm.h>
40#include <linux/console.h>
41#include <linux/tty.h>
42#include <linux/vt.h>
43
44#include <asm/sibyte/bcm1480_regs.h>
45#include <asm/sibyte/bcm1480_scd.h>
46#include <asm/sibyte/board.h>
47#include <asm/io.h>
48
49
50
51
52
53#define CFGOFFSET(bus, devfn, where) (((bus)<<16)+((devfn)<<8)+(where))
54#define CFGADDR(bus, devfn, where) CFGOFFSET((bus)->number, (devfn), where)
55
56static void *cfg_space;
57
58#define PCI_BUS_ENABLED 1
59#define PCI_DEVICE_MODE 2
60
61static int bcm1480_bus_status;
62
63#define PCI_BRIDGE_DEVICE 0
64
65
66
67
68static inline u32 READCFG32(u32 addr)
69{
70 return *(u32 *)(cfg_space + (addr&~3));
71}
72
73static inline void WRITECFG32(u32 addr, u32 data)
74{
75 *(u32 *)(cfg_space + (addr & ~3)) = data;
76}
77
78int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
79{
80 if (pin == 0)
81 return -1;
82
83 return K_BCM1480_INT_PCI_INTA - 1 + pin;
84}
85
86
87int pcibios_plat_dev_init(struct pci_dev *dev)
88{
89 return 0;
90}
91
92
93
94
95
96
97static int bcm1480_pci_can_access(struct pci_bus *bus, int devfn)
98{
99 u32 devno;
100
101 if (!(bcm1480_bus_status & (PCI_BUS_ENABLED | PCI_DEVICE_MODE)))
102 return 0;
103
104 if (bus->number == 0) {
105 devno = PCI_SLOT(devfn);
106 if (bcm1480_bus_status & PCI_DEVICE_MODE)
107 return 0;
108 else
109 return 1;
110 } else
111 return 1;
112}
113
114
115
116
117
118
119
120static int bcm1480_pcibios_read(struct pci_bus *bus, unsigned int devfn,
121 int where, int size, u32 * val)
122{
123 u32 data = 0;
124
125 if ((size == 2) && (where & 1))
126 return PCIBIOS_BAD_REGISTER_NUMBER;
127 else if ((size == 4) && (where & 3))
128 return PCIBIOS_BAD_REGISTER_NUMBER;
129
130 if (bcm1480_pci_can_access(bus, devfn))
131 data = READCFG32(CFGADDR(bus, devfn, where));
132 else
133 data = 0xFFFFFFFF;
134
135 if (size == 1)
136 *val = (data >> ((where & 3) << 3)) & 0xff;
137 else if (size == 2)
138 *val = (data >> ((where & 3) << 3)) & 0xffff;
139 else
140 *val = data;
141
142 return PCIBIOS_SUCCESSFUL;
143}
144
145static int bcm1480_pcibios_write(struct pci_bus *bus, unsigned int devfn,
146 int where, int size, u32 val)
147{
148 u32 cfgaddr = CFGADDR(bus, devfn, where);
149 u32 data = 0;
150
151 if ((size == 2) && (where & 1))
152 return PCIBIOS_BAD_REGISTER_NUMBER;
153 else if ((size == 4) && (where & 3))
154 return PCIBIOS_BAD_REGISTER_NUMBER;
155
156 if (!bcm1480_pci_can_access(bus, devfn))
157 return PCIBIOS_BAD_REGISTER_NUMBER;
158
159 data = READCFG32(cfgaddr);
160
161 if (size == 1)
162 data = (data & ~(0xff << ((where & 3) << 3))) |
163 (val << ((where & 3) << 3));
164 else if (size == 2)
165 data = (data & ~(0xffff << ((where & 3) << 3))) |
166 (val << ((where & 3) << 3));
167 else
168 data = val;
169
170 WRITECFG32(cfgaddr, data);
171
172 return PCIBIOS_SUCCESSFUL;
173}
174
175struct pci_ops bcm1480_pci_ops = {
176 .read = bcm1480_pcibios_read,
177 .write = bcm1480_pcibios_write,
178};
179
180static struct resource bcm1480_mem_resource = {
181 .name = "BCM1480 PCI MEM",
182 .start = A_BCM1480_PHYS_PCI_MEM_MATCH_BYTES,
183 .end = A_BCM1480_PHYS_PCI_MEM_MATCH_BYTES + 0xfffffffUL,
184 .flags = IORESOURCE_MEM,
185};
186
187static struct resource bcm1480_io_resource = {
188 .name = "BCM1480 PCI I/O",
189 .start = A_BCM1480_PHYS_PCI_IO_MATCH_BYTES,
190 .end = A_BCM1480_PHYS_PCI_IO_MATCH_BYTES + 0x1ffffffUL,
191 .flags = IORESOURCE_IO,
192};
193
194struct pci_controller bcm1480_controller = {
195 .pci_ops = &bcm1480_pci_ops,
196 .mem_resource = &bcm1480_mem_resource,
197 .io_resource = &bcm1480_io_resource,
198 .io_offset = A_BCM1480_PHYS_PCI_IO_MATCH_BYTES,
199};
200
201
202static int __init bcm1480_pcibios_init(void)
203{
204 uint32_t cmdreg;
205 uint64_t reg;
206
207
208 pci_set_flags(PCI_PROBE_ONLY);
209
210
211 PCIBIOS_MIN_IO = 0x00008000UL;
212 PCIBIOS_MIN_MEM = 0x01000000UL;
213
214
215 ioport_resource.end = 0xffffffffUL;
216 iomem_resource.end = 0xffffffffUL;
217
218 cfg_space = ioremap(A_BCM1480_PHYS_PCI_CFG_MATCH_BITS, 16*1024*1024);
219
220
221
222
223 reg = __raw_readq(IOADDR(A_SCD_SYSTEM_CFG));
224 if (!(reg & M_BCM1480_SYS_PCI_HOST)) {
225 bcm1480_bus_status |= PCI_DEVICE_MODE;
226 } else {
227 cmdreg = READCFG32(CFGOFFSET(0, PCI_DEVFN(PCI_BRIDGE_DEVICE, 0),
228 PCI_COMMAND));
229 if (!(cmdreg & PCI_COMMAND_MASTER)) {
230 printk
231 ("PCI: Skipping PCI probe. Bus is not initialized.\n");
232 iounmap(cfg_space);
233 return 1;
234 }
235 bcm1480_bus_status |= PCI_BUS_ENABLED;
236 }
237
238
239 cmdreg = READCFG32(CFGOFFSET(0, PCI_DEVFN(PCI_BRIDGE_DEVICE, 0), 0x40));
240 WRITECFG32(CFGOFFSET(0, PCI_DEVFN(PCI_BRIDGE_DEVICE, 0), 0x40),
241 cmdreg | 0x10);
242 cmdreg = READCFG32(CFGOFFSET(0, PCI_DEVFN(PCI_BRIDGE_DEVICE, 0), 0x40));
243
244
245
246
247
248
249
250
251
252
253 bcm1480_controller.io_map_base = (unsigned long)
254 ioremap(A_BCM1480_PHYS_PCI_IO_MATCH_BYTES, 65536);
255 bcm1480_controller.io_map_base -= bcm1480_controller.io_offset;
256 set_io_port_base(bcm1480_controller.io_map_base);
257
258 register_pci_controller(&bcm1480_controller);
259
260#ifdef CONFIG_VGA_CONSOLE
261 console_lock();
262 do_take_over_console(&vga_con, 0, MAX_NR_CONSOLES-1, 1);
263 console_unlock();
264#endif
265 return 0;
266}
267
268arch_initcall(bcm1480_pcibios_init);
269