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#include <linux/types.h>
34#include <linux/pci.h>
35#include <linux/kernel.h>
36#include <linux/init.h>
37#include <linux/mm.h>
38#include <linux/console.h>
39#include <linux/tty.h>
40#include <linux/vt.h>
41
42#include <asm/io.h>
43
44#include <asm/sibyte/sb1250_defs.h>
45#include <asm/sibyte/sb1250_regs.h>
46#include <asm/sibyte/sb1250_scd.h>
47#include <asm/sibyte/board.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 LDT_BUS_ENABLED 2
60#define PCI_DEVICE_MODE 4
61
62static int sb1250_bus_status;
63
64#define PCI_BRIDGE_DEVICE 0
65#define LDT_BRIDGE_DEVICE 1
66
67#ifdef CONFIG_SIBYTE_HAS_LDT
68
69
70
71
72unsigned long ldt_eoi_space;
73#endif
74
75
76
77
78static inline u32 READCFG32(u32 addr)
79{
80 return *(u32 *) (cfg_space + (addr & ~3));
81}
82
83static inline void WRITECFG32(u32 addr, u32 data)
84{
85 *(u32 *) (cfg_space + (addr & ~3)) = data;
86}
87
88int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
89{
90 return dev->irq;
91}
92
93
94int pcibios_plat_dev_init(struct pci_dev *dev)
95{
96 return 0;
97}
98
99
100
101
102
103
104static int sb1250_pci_can_access(struct pci_bus *bus, int devfn)
105{
106 u32 devno;
107
108 if (!(sb1250_bus_status & (PCI_BUS_ENABLED | PCI_DEVICE_MODE)))
109 return 0;
110
111 if (bus->number == 0) {
112 devno = PCI_SLOT(devfn);
113 if (devno == LDT_BRIDGE_DEVICE)
114 return (sb1250_bus_status & LDT_BUS_ENABLED) != 0;
115 else if (sb1250_bus_status & PCI_DEVICE_MODE)
116 return 0;
117 else
118 return 1;
119 } else
120 return 1;
121}
122
123
124
125
126
127
128
129static int sb1250_pcibios_read(struct pci_bus *bus, unsigned int devfn,
130 int where, int size, u32 * val)
131{
132 u32 data = 0;
133
134 if ((size == 2) && (where & 1))
135 return PCIBIOS_BAD_REGISTER_NUMBER;
136 else if ((size == 4) && (where & 3))
137 return PCIBIOS_BAD_REGISTER_NUMBER;
138
139 if (sb1250_pci_can_access(bus, devfn))
140 data = READCFG32(CFGADDR(bus, devfn, where));
141 else
142 data = 0xFFFFFFFF;
143
144 if (size == 1)
145 *val = (data >> ((where & 3) << 3)) & 0xff;
146 else if (size == 2)
147 *val = (data >> ((where & 3) << 3)) & 0xffff;
148 else
149 *val = data;
150
151 return PCIBIOS_SUCCESSFUL;
152}
153
154static int sb1250_pcibios_write(struct pci_bus *bus, unsigned int devfn,
155 int where, int size, u32 val)
156{
157 u32 cfgaddr = CFGADDR(bus, devfn, where);
158 u32 data = 0;
159
160 if ((size == 2) && (where & 1))
161 return PCIBIOS_BAD_REGISTER_NUMBER;
162 else if ((size == 4) && (where & 3))
163 return PCIBIOS_BAD_REGISTER_NUMBER;
164
165 if (!sb1250_pci_can_access(bus, devfn))
166 return PCIBIOS_BAD_REGISTER_NUMBER;
167
168 data = READCFG32(cfgaddr);
169
170 if (size == 1)
171 data = (data & ~(0xff << ((where & 3) << 3))) |
172 (val << ((where & 3) << 3));
173 else if (size == 2)
174 data = (data & ~(0xffff << ((where & 3) << 3))) |
175 (val << ((where & 3) << 3));
176 else
177 data = val;
178
179 WRITECFG32(cfgaddr, data);
180
181 return PCIBIOS_SUCCESSFUL;
182}
183
184struct pci_ops sb1250_pci_ops = {
185 .read = sb1250_pcibios_read,
186 .write = sb1250_pcibios_write,
187};
188
189static struct resource sb1250_mem_resource = {
190 .name = "SB1250 PCI MEM",
191 .start = 0x40000000UL,
192 .end = 0x5fffffffUL,
193 .flags = IORESOURCE_MEM,
194};
195
196static struct resource sb1250_io_resource = {
197 .name = "SB1250 PCI I/O",
198 .start = 0x00000000UL,
199 .end = 0x01ffffffUL,
200 .flags = IORESOURCE_IO,
201};
202
203struct pci_controller sb1250_controller = {
204 .pci_ops = &sb1250_pci_ops,
205 .mem_resource = &sb1250_mem_resource,
206 .io_resource = &sb1250_io_resource,
207};
208
209static int __init sb1250_pcibios_init(void)
210{
211 void __iomem *io_map_base;
212 uint32_t cmdreg;
213 uint64_t reg;
214
215
216 pci_set_flags(PCI_PROBE_ONLY);
217
218
219 PCIBIOS_MIN_IO = 0x00008000UL;
220 PCIBIOS_MIN_MEM = 0x01000000UL;
221
222
223 ioport_resource.end = 0x01ffffffUL;
224 iomem_resource.end = 0xffffffffUL;
225
226 cfg_space =
227 ioremap(A_PHYS_LDTPCI_CFG_MATCH_BITS, 16 * 1024 * 1024);
228
229
230
231
232 reg = __raw_readq(IOADDR(A_SCD_SYSTEM_CFG));
233 if (!(reg & M_SYS_PCI_HOST)) {
234 sb1250_bus_status |= PCI_DEVICE_MODE;
235 } else {
236 cmdreg =
237 READCFG32(CFGOFFSET
238 (0, PCI_DEVFN(PCI_BRIDGE_DEVICE, 0),
239 PCI_COMMAND));
240 if (!(cmdreg & PCI_COMMAND_MASTER)) {
241 printk
242 ("PCI: Skipping PCI probe. Bus is not initialized.\n");
243 iounmap(cfg_space);
244 return 0;
245 }
246 sb1250_bus_status |= PCI_BUS_ENABLED;
247 }
248
249
250
251
252
253
254
255
256
257 io_map_base = ioremap(A_PHYS_LDTPCI_IO_MATCH_BYTES, 1024 * 1024);
258 sb1250_controller.io_map_base = (unsigned long)io_map_base;
259 set_io_port_base((unsigned long)io_map_base);
260
261#ifdef CONFIG_SIBYTE_HAS_LDT
262
263
264
265
266
267 cmdreg = READCFG32(CFGOFFSET(0, PCI_DEVFN(LDT_BRIDGE_DEVICE, 0),
268 PCI_COMMAND));
269 if (cmdreg & PCI_COMMAND_MASTER) {
270 sb1250_bus_status |= LDT_BUS_ENABLED;
271
272
273
274
275
276
277 ldt_eoi_space = (unsigned long)
278 ioremap(A_PHYS_LDT_SPECIAL_MATCH_BYTES,
279 4 * 1024 * 1024);
280 }
281#endif
282
283 register_pci_controller(&sb1250_controller);
284
285#ifdef CONFIG_VGA_CONSOLE
286 console_lock();
287 do_take_over_console(&vga_con, 0, MAX_NR_CONSOLES - 1, 1);
288 console_unlock();
289#endif
290 return 0;
291}
292arch_initcall(sb1250_pcibios_init);
293