This source file includes following definitions.
- pcibios_present
- layout_dev
- layout_bus
- pcibios_find_device
- pcibios_find_class
- pcibios_present
- pcibios_init
- noname_fixup
- pcibios_fixup
- pcibios_strerror
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 #include <linux/config.h>
27
28 #ifndef CONFIG_PCI
29
30 int pcibios_present(void)
31 {
32 return 0;
33 }
34
35 #else
36
37 #include <linux/kernel.h>
38 #include <linux/bios32.h>
39 #include <linux/pci.h>
40 #include <linux/malloc.h>
41 #include <linux/mm.h>
42
43 #include <asm/hwrpb.h>
44 #include <asm/io.h>
45
46
47 #define KB 1024
48 #define MB (1024*KB)
49 #define GB (1024*MB)
50
51 #define MAJOR_REV 0
52 #define MINOR_REV 2
53
54
55
56
57 #define ALIGN(val,align) (((val) + ((align) - 1)) & ~((align) - 1))
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 #define PCI_MODIFY 1
78
79
80 extern struct hwrpb_struct *hwrpb;
81
82
83 #if PCI_MODIFY
84
85 static unsigned int io_base = 64*KB;
86 static unsigned int mem_base = 16*MB;
87
88
89
90
91
92 static void layout_dev(struct pci_dev *dev)
93 {
94 struct pci_bus *bus;
95 unsigned short cmd;
96 unsigned int base, mask, size, reg;
97
98 bus = dev->bus;
99 pcibios_read_config_word(bus->number, dev->devfn, PCI_COMMAND, &cmd);
100
101 for (reg = PCI_BASE_ADDRESS_0; reg <= PCI_BASE_ADDRESS_5; reg += 4) {
102
103
104
105
106 pcibios_write_config_dword(bus->number, dev->devfn, reg,
107 0xffffffff);
108 pcibios_read_config_dword(bus->number, dev->devfn, reg, &base);
109 if (!base) {
110
111 continue;
112 }
113
114
115
116
117 if (base & PCI_BASE_ADDRESS_SPACE_IO) {
118
119
120
121 cmd |= PCI_COMMAND_IO;
122
123 base &= PCI_BASE_ADDRESS_IO_MASK;
124 mask = (~base << 1) | 0x1;
125 size = (mask & base) & 0xffffffff;
126 base = ALIGN(io_base, size);
127 io_base = base + size;
128 pcibios_write_config_dword(bus->number, dev->devfn,
129 reg, base | 0x1);
130 } else {
131 unsigned int type;
132
133
134
135 cmd |= PCI_COMMAND_MEMORY;
136
137 type = base & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
138 base &= PCI_BASE_ADDRESS_MEM_MASK;
139 mask = (~base << 1) | 0x1;
140 size = (mask & base) & 0xffffffff;
141 switch (type) {
142 case PCI_BASE_ADDRESS_MEM_TYPE_32:
143 break;
144
145 case PCI_BASE_ADDRESS_MEM_TYPE_64:
146 printk("bios32 WARNING: "
147 "ignoring 64-bit device in "
148 "slot %d, function %d: \n",
149 PCI_SLOT(dev->devfn),
150 PCI_FUNC(dev->devfn));
151 reg += 4;
152 continue;
153
154 case PCI_BASE_ADDRESS_MEM_TYPE_1M:
155
156
157
158
159
160
161
162
163
164 printk("bios32 WARNING: slot %d, function %d "
165 "requests memory below 1MB---don't "
166 "know how to do that.\n",
167 PCI_SLOT(dev->devfn),
168 PCI_FUNC(dev->devfn));
169 continue;
170 }
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186 base = ALIGN(mem_base, size);
187 if (size > 7 * 16*MB) {
188 printk("bios32 WARNING: slot %d, function %d "
189 "requests %dB of contiguous address "
190 " space---don't use sparse memory "
191 " accesses on this device!!\n",
192 PCI_SLOT(dev->devfn),
193 PCI_FUNC(dev->devfn), size);
194 } else {
195 if (((base / 16*MB) & 0x7) == 0) {
196 base &= ~(128*MB - 1);
197 base += 16*MB;
198 base = ALIGN(base, size);
199 }
200 if (base / 128*MB != (base + size) / 128*MB) {
201 base &= ~(128*MB - 1);
202 base += (128 + 16)*MB;
203 base = ALIGN(base, size);
204 }
205 }
206 mem_base = base + size;
207 pcibios_write_config_dword(bus->number, dev->devfn,
208 reg, base);
209 }
210 }
211
212 pcibios_write_config_word(bus->number, dev->devfn, PCI_COMMAND,
213 cmd | PCI_COMMAND_MASTER);
214 }
215
216
217 static void layout_bus(struct pci_bus *bus)
218 {
219 unsigned int l, tio, bio, tmem, bmem;
220 struct pci_bus *child;
221 struct pci_dev *dev;
222
223 if (!bus->devices && !bus->children)
224 return;
225
226
227
228
229
230 bio = io_base = ALIGN(io_base, 4*KB);
231 bmem = mem_base = ALIGN(mem_base, 1*MB);
232
233
234
235
236 for (dev = bus->devices; dev; dev = dev->sibling) {
237 if (dev->class >> 16 != PCI_BASE_CLASS_BRIDGE) {
238 layout_dev(dev);
239 }
240 }
241
242
243
244 for (child = bus->children; child; child = child->next) {
245 layout_bus(child);
246 }
247
248
249
250 tio = io_base = ALIGN(io_base, 4*KB);
251 tmem = mem_base = ALIGN(mem_base, 1*MB);
252
253 if (bus->self) {
254 struct pci_dev *bridge = bus->self;
255
256
257
258
259 pcibios_read_config_dword(bridge->bus->number, bridge->devfn,
260 0x1c, &l);
261 l = l | (bio >> 8) | ((tio - 1) & 0xf000);
262 pcibios_write_config_dword(bridge->bus->number, bridge->devfn,
263 0x1c, l);
264
265 l = ((bmem & 0xfff00000) >> 16) | ((tmem - 1) & 0xfff00000);
266 pcibios_write_config_dword(bridge->bus->number, bridge->devfn,
267 0x20, l);
268
269
270
271 pcibios_write_config_dword(bridge->bus->number, bridge->devfn,
272 0x24, 0x0000ffff);
273
274
275
276 pcibios_write_config_dword(bridge->bus->number, bridge->devfn,
277 0x3c, 0x00040000);
278
279
280
281
282
283
284 pcibios_write_config_dword(bridge->bus->number, bridge->devfn,
285 0x4, 0xffff0007);
286 }
287 }
288
289 #endif
290
291
292
293
294
295
296 int pcibios_find_device (unsigned short vendor, unsigned short device_id,
297 unsigned short index, unsigned char *bus,
298 unsigned char *devfn)
299 {
300 unsigned int current = 0;
301 struct pci_dev *dev;
302
303 for (dev = pci_devices; dev; dev = dev->next) {
304 if (dev->vendor == vendor && dev->device == device_id) {
305 if (current == index) {
306 *devfn = dev->devfn;
307 *bus = dev->bus->number;
308 return PCIBIOS_SUCCESSFUL;
309 }
310 ++current;
311 }
312 }
313 return PCIBIOS_DEVICE_NOT_FOUND;
314 }
315
316
317
318
319
320
321 int pcibios_find_class (unsigned int class_code, unsigned short index,
322 unsigned char *bus, unsigned char *devfn)
323 {
324 unsigned int current = 0;
325 struct pci_dev *dev;
326
327 for (dev = pci_devices; dev; dev = dev->next) {
328 if (dev->class == class_code) {
329 if (current == index) {
330 *devfn = dev->devfn;
331 *bus = dev->bus->number;
332 return PCIBIOS_SUCCESSFUL;
333 }
334 ++current;
335 }
336 }
337 return PCIBIOS_DEVICE_NOT_FOUND;
338 }
339
340
341 int pcibios_present(void)
342 {
343 return 1;
344 }
345
346
347 unsigned long pcibios_init(unsigned long mem_start,
348 unsigned long mem_end)
349 {
350 printk("Alpha PCI BIOS32 revision %x.%02x\n", MAJOR_REV, MINOR_REV);
351
352 #if !PCI_MODIFY
353 printk("...NOT modifying existing (SRM) PCI configuration\n");
354 #endif
355 return mem_start;
356 }
357
358
359
360
361
362 static void noname_fixup(void)
363 {
364 struct pci_dev *dev;
365
366
367
368
369
370
371
372
373 static const char pirq_tab[5][4] = {
374 { 3, -1, -1, -1},
375 {-1, -1, -1, -1},
376 { 2, -1, -1, -1},
377 { 1, -1, -1, -1},
378 { 0, -1, -1, -1},
379 };
380
381
382
383
384
385
386
387 const unsigned int route_tab = 0x0b0a090f;
388 unsigned char pin;
389 int pirq;
390
391 pcibios_write_config_dword(0, PCI_DEVFN(7, 0), 0x60, route_tab);
392
393
394 outb((1<<(9-8)) | (1<<(10-8)) | (1<<(11-8)) | (1<<(15-8)), 0x4d1);
395
396
397
398
399 for (dev = pci_devices; dev; dev = dev->next) {
400 dev->irq = 0;
401 if (dev->bus->number != 0 ||
402 PCI_SLOT(dev->devfn) < 6 || PCI_SLOT(dev->devfn) > 10)
403 {
404 printk("noname_set_irq: no dev on bus %d, slot %d!!\n",
405 dev->bus->number, PCI_SLOT(dev->devfn));
406 continue;
407 }
408
409 pcibios_read_config_byte(dev->bus->number, dev->devfn,
410 PCI_INTERRUPT_PIN, &pin);
411 if (!pin) {
412 if (dev->vendor == PCI_VENDOR_ID_S3 &&
413 (dev->device == PCI_DEVICE_ID_S3_864_1 ||
414 dev->device == PCI_DEVICE_ID_S3_864_2))
415 {
416 pin = 1;
417 } else {
418 continue;
419 }
420 }
421 pirq = pirq_tab[PCI_SLOT(dev->devfn) - 6][pin - 1];
422 if (pirq < 0) {
423 continue;
424 }
425 dev->irq = (route_tab >> (8 * pirq)) & 0xff;
426 #if PCI_MODIFY
427
428 pcibios_write_config_byte(dev->bus->number, dev->devfn,
429 PCI_INTERRUPT_LINE, dev->irq);
430 #endif
431 }
432
433 #if PCI_MODIFY
434 {
435 unsigned char hostid;
436
437
438
439
440
441
442
443
444 if (pcibios_read_config_byte(0, PCI_DEVFN(6, 0), 0x84, &hostid)
445 == PCIBIOS_SUCCESSFUL && (hostid == 0))
446 {
447 pcibios_write_config_byte(0, PCI_DEVFN(6, 0),
448 0x84, 7);
449 }
450 }
451 #endif
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471 {
472 long flags;
473 int data;
474
475
476
477 save_flags(flags);
478 cli();
479
480 outb(0, 0x26e);
481 data = inb(0x26f);
482 #ifdef DEBUG
483 printk("base @ 0x26e: reg#0 0x%x\n", data);
484 #endif
485 outb(0, 0x26e);
486 outb(data | 0x40, 0x26f);
487 outb(data | 0x40, 0x26f);
488 #ifdef DEBUG
489 outb(0, 0x26e); data = inb(0x26f);
490 printk("base @ 0x26e: reg#0 0x%x\n", data);
491 #endif
492 restore_flags(flags);
493 }
494 }
495
496
497 unsigned long pcibios_fixup(unsigned long mem_start, unsigned long mem_end)
498 {
499 #if PCI_MODIFY
500
501
502
503 layout_bus(&pci_root);
504 #endif
505
506
507
508
509 switch (hwrpb->sys_type) {
510 case ST_DEC_AXPPCI_33: noname_fixup(); break;
511
512 default:
513 printk("pcibios_fixup: don't know how to fixup sys type %ld\n",
514 hwrpb->sys_type);
515 break;
516 }
517 return mem_start;
518 }
519
520
521 char *pcibios_strerror (int error)
522 {
523 static char buf[80];
524
525 switch (error) {
526 case PCIBIOS_SUCCESSFUL:
527 return "SUCCESSFUL";
528
529 case PCIBIOS_FUNC_NOT_SUPPORTED:
530 return "FUNC_NOT_SUPPORTED";
531
532 case PCIBIOS_BAD_VENDOR_ID:
533 return "SUCCESSFUL";
534
535 case PCIBIOS_DEVICE_NOT_FOUND:
536 return "DEVICE_NOT_FOUND";
537
538 case PCIBIOS_BAD_REGISTER_NUMBER:
539 return "BAD_REGISTER_NUMBER";
540
541 default:
542 sprintf (buf, "UNKNOWN RETURN 0x%x", error);
543 return buf;
544 }
545 }
546
547 #endif