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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
|
/*
* PCI support
* -- rough emulation of "PCI BIOS" functions
*
* Note: these are very motherboard specific! Some way needs to
* be worked out to handle the differences.
*/
#include <linux/config.h>
#include <linux/types.h>
#include <linux/bios32.h>
#include <linux/pci.h>
/*
* PCI interrupt configuration. This is motherboard specific.
*/
/* Which PCI interrupt line does a given device [slot] use? */
/* Note: This really should be two dimensional based in slot/pin used */
unsigned char *Motherboard_map;
/* How is the 82378 PIRQ mapping setup? */
unsigned char *Motherboard_routes;
/* Tables for known hardware */
/* Motorola PowerStack */
static char Blackhawk_pci_IRQ_map[16] =
{
0, /* Slot 0 - unused */
0, /* Slot 1 - unused */
0, /* Slot 2 - unused */
0, /* Slot 3 - unused */
0, /* Slot 4 - unused */
0, /* Slot 5 - unused */
0, /* Slot 6 - unused */
0, /* Slot 7 - unused */
0, /* Slot 8 - unused */
0, /* Slot 9 - unused */
0, /* Slot 10 - unused */
0, /* Slot 11 - unused */
3, /* Slot 12 - SCSI */
0, /* Slot 13 - unused */
1, /* Slot 14 - Ethernet */
0, /* Slot 15 - unused */
};
static char Blackhawk_pci_IRQ_routes[] =
{
0, /* Line 0 - Unused */
9, /* Line 1 */
11, /* Line 2 */
14, /* Line 3 */
15 /* Line 4 */
};
/* Motorola MVME16xx */
static char Genesis_pci_IRQ_map[16] =
{
0, /* Slot 0 - unused */
0, /* Slot 1 - unused */
0, /* Slot 2 - unused */
0, /* Slot 3 - unused */
0, /* Slot 4 - unused */
0, /* Slot 5 - unused */
0, /* Slot 6 - unused */
0, /* Slot 7 - unused */
0, /* Slot 8 - unused */
0, /* Slot 9 - unused */
0, /* Slot 10 - unused */
0, /* Slot 11 - unused */
3, /* Slot 12 - SCSI */
0, /* Slot 13 - unused */
1, /* Slot 14 - Ethernet */
0, /* Slot 15 - unused */
};
static char Genesis_pci_IRQ_routes[] =
{
0, /* Line 0 - Unused */
10, /* Line 1 */
11, /* Line 2 */
14, /* Line 3 */
15 /* Line 4 */
};
/* Motorola Series-E */
static char Comet_pci_IRQ_map[16] =
{
0, /* Slot 0 - unused */
0, /* Slot 1 - unused */
0, /* Slot 2 - unused */
0, /* Slot 3 - unused */
0, /* Slot 4 - unused */
0, /* Slot 5 - unused */
0, /* Slot 6 - unused */
0, /* Slot 7 - unused */
0, /* Slot 8 - unused */
0, /* Slot 9 - unused */
0, /* Slot 10 - unused */
0, /* Slot 11 - unused */
3, /* Slot 12 - SCSI */
0, /* Slot 13 - unused */
1, /* Slot 14 - Ethernet */
0, /* Slot 15 - unused */
};
static char Comet_pci_IRQ_routes[] =
{
0, /* Line 0 - Unused */
10, /* Line 1 */
11, /* Line 2 */
14, /* Line 3 */
15 /* Line 4 */
};
/* BeBox */
static char BeBox_pci_IRQ_map[16] =
{
0, /* Slot 0 - unused */
0, /* Slot 1 - unused */
0, /* Slot 2 - unused */
0, /* Slot 3 - unused */
0, /* Slot 4 - unused */
0, /* Slot 5 - unused */
0, /* Slot 6 - unused */
0, /* Slot 7 - unused */
0, /* Slot 8 - unused */
0, /* Slot 9 - unused */
0, /* Slot 10 - unused */
0, /* Slot 11 - unused */
16, /* Slot 12 - SCSI */
0, /* Slot 13 - unused */
0, /* Slot 14 - unused */
0, /* Slot 15 - unused */
};
static char BeBox_pci_IRQ_routes[] =
{
0, /* Line 0 - Unused */
9, /* Line 1 */
11, /* Line 2 */
14, /* Line 3 */
15 /* Line 4 */
};
/* #define PCI_DEBUG */
#ifdef PCI_STATS
int PCI_conversions[2];
#endif
unsigned long pcibios_init(unsigned long mem_start,
unsigned long mem_end)
{
return mem_start;
}
unsigned long pcibios_fixup(unsigned long mem_start, unsigned long mem_end)
{
return mem_start;
}
unsigned long
_LE_to_BE_long(unsigned long val)
{
unsigned char *p = (unsigned char *)&val;
#ifdef PCI_STATS
PCI_conversions[0]++;
#endif
return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | (p[0] << 0));
}
unsigned short
_LE_to_BE_short(unsigned long val)
{
unsigned char *p = (unsigned char *)&val;
#ifdef PCI_STATS
PCI_conversions[1]++;
#endif
return ((p[3] << 8) | (p[2] << 0));
}
int
pcibios_present (void)
{
#ifdef PCI_DEBUG
printk("PCI [BIOS] present?\n");
#endif
return (1);
}
int
pcibios_read_config_dword (unsigned char bus,
unsigned char dev, unsigned char offset, unsigned int *val)
{
unsigned long _val;
unsigned long *ptr;
dev >>= 3;
#ifdef PCI_DEBUG
printk("PCI Read config dword[%d.%d.%x] = ", bus, dev, offset);
#endif
if ((bus != 0) || (dev < 11) || (dev > 16))
{
*val = 0xFFFFFFFF;
return PCIBIOS_DEVICE_NOT_FOUND;
} else
{
ptr = (unsigned long *)(0x80800000 | (1<<dev) | offset);
#ifdef PCI_DEBUG
printk("[%x] ", ptr);
#endif
_val = _LE_to_BE_long(*ptr);
}
#ifdef PCI_DEBUG
printk("%x\n", _val);
#endif
*val = _val;
return PCIBIOS_SUCCESSFUL;
}
int
pcibios_read_config_word (unsigned char bus,
unsigned char dev, unsigned char offset, unsigned short *val)
{
unsigned short _val;
unsigned short *ptr;
dev >>= 3;
#ifdef PCI_DEBUG
printk("PCI Read config word[%d.%d.%x] = ", bus, dev, offset);
#endif
if ((bus != 0) || (dev < 11) || (dev > 16))
{
*val = 0xFFFFFFFF;
return PCIBIOS_DEVICE_NOT_FOUND;
} else
{
ptr = (unsigned short *)(0x80800000 | (1<<dev) | offset);
#ifdef PCI_DEBUG
printk("[%x] ", ptr);
#endif
_val = _LE_to_BE_short(*ptr);
}
#ifdef PCI_DEBUG
printk("%x\n", _val);
#endif
*val = _val;
return PCIBIOS_SUCCESSFUL;
}
int
pcibios_read_config_byte (unsigned char bus,
unsigned char dev, unsigned char offset, unsigned char *val)
{
unsigned char _val;
volatile unsigned char *ptr;
dev >>= 3;
/* Note: the configuration registers don't always have this right! */
if (offset == PCI_INTERRUPT_LINE)
{
if (Motherboard_map[dev] <= 4)
{
*val = Motherboard_routes[Motherboard_map[dev]];
} else
{ /* Pseudo interrupts [for BeBox] */
*val = Motherboard_map[dev];
}
#ifdef PCI_DEBUG
printk("PCI Read Interrupt Line[%d.%d] = %d\n", bus, dev, *val);
#endif
return PCIBIOS_SUCCESSFUL;
}
#ifdef PCI_DEBUG
printk("PCI Read config byte[%d.%d.%x] = ", bus, dev, offset);
#endif
if ((bus != 0) || (dev < 11) || (dev > 16))
{
*val = 0xFFFFFFFF;
return PCIBIOS_DEVICE_NOT_FOUND;
} else
{
ptr = (unsigned char *)(0x80800000 | (1<<dev) | offset ^ 1);
#ifdef PCI_DEBUG
printk("[%x] ", ptr);
#endif
_val = *ptr;
}
#ifdef PCI_DEBUG
printk("%x\n", _val);
#endif
*val = _val;
return PCIBIOS_SUCCESSFUL;
}
int
pcibios_write_config_dword (unsigned char bus,
unsigned char dev, unsigned char offset, unsigned int val)
{
unsigned long _val;
unsigned long *ptr;
dev >>= 3;
_val = _LE_to_BE_long(val);
#ifdef PCI_DEBUG
printk("PCI Write config dword[%d.%d.%x] = %x\n", bus, dev, offset, _val);
#endif
if ((bus != 0) || (dev < 11) || (dev > 16))
{
return PCIBIOS_DEVICE_NOT_FOUND;
} else
{
ptr = (unsigned long *)(0x80800000 | (1<<dev) | offset);
*ptr = _val;
}
return PCIBIOS_SUCCESSFUL;
}
int
pcibios_write_config_word (unsigned char bus,
unsigned char dev, unsigned char offset, unsigned short val)
{
unsigned short _val;
unsigned short *ptr;
dev >>= 3;
_val = _LE_to_BE_short(val);
#ifdef PCI_DEBUG
printk("PCI Write config word[%d.%d.%x] = %x\n", bus, dev, offset, _val);
#endif
if ((bus != 0) || (dev < 11) || (dev > 16))
{
return PCIBIOS_DEVICE_NOT_FOUND;
} else
{
ptr = (unsigned short *)(0x80800000 | (1<<dev) | offset);
*ptr = _val;
}
return PCIBIOS_SUCCESSFUL;
}
int
pcibios_write_config_byte (unsigned char bus,
unsigned char dev, unsigned char offset, unsigned char val)
{
unsigned char _val;
unsigned char *ptr;
dev >>= 3;
_val = val;
#ifdef PCI_DEBUG
printk("PCI Write config byte[%d.%d.%x] = %x\n", bus, dev, offset, _val);
#endif
if ((bus != 0) || (dev < 11) || (dev > 16))
{
return PCIBIOS_DEVICE_NOT_FOUND;
} else
{
ptr = (unsigned char *)(0x80800000 | (1<<dev) | offset ^ 1);
*ptr = _val;
}
return PCIBIOS_SUCCESSFUL;
}
int
pcibios_find_device (unsigned short vendor, unsigned short device_id,
unsigned short index, unsigned char *bus,
unsigned char *dev)
{
unsigned long w, desired = (device_id << 16) | vendor;
int devnr;
if (vendor == 0xffff) {
return PCIBIOS_BAD_VENDOR_ID;
}
for (devnr = 11; devnr < 16; devnr++)
{
pcibios_read_config_dword(0, devnr<<3, PCI_VENDOR_ID, &w);
if (w == desired) {
if (index == 0) {
*bus = 0;
*dev = devnr<<3;
return PCIBIOS_SUCCESSFUL;
}
--index;
}
}
return PCIBIOS_DEVICE_NOT_FOUND;
}
int
pcibios_find_class (unsigned int class_code, unsigned short index,
unsigned char *bus, unsigned char *dev)
{
int dev_nr, class, indx;
indx = 0;
#ifdef PCI_DEBUG
printk("pcibios_find_class - class: %x, index: %x", class_code, index);
#endif
for (dev_nr = 11; dev_nr < 16; dev_nr++)
{
pcibios_read_config_dword(0, dev_nr<<3, PCI_CLASS_REVISION, &class);
if ((class>>8) == class_code)
{
if (index == indx)
{
*bus = 0;
*dev = dev_nr<<3;
#ifdef PCI_DEBUG
printk(" - device: %x\n", dev_nr);
#endif
return (0);
}
indx++;
}
}
#ifdef PCI_DEBUG
printk(" - not found\n");
#endif
return PCIBIOS_DEVICE_NOT_FOUND;
}
const char *pcibios_strerror(int error)
{
static char buf[32];
switch (error)
{ case PCIBIOS_SUCCESSFUL:
return ("PCI BIOS: no error");
case PCIBIOS_FUNC_NOT_SUPPORTED:
return ("PCI BIOS: function not supported");
case PCIBIOS_BAD_VENDOR_ID:
return ("PCI BIOS: bad vendor ID");
case PCIBIOS_DEVICE_NOT_FOUND:
return ("PCI BIOS: device not found");
case PCIBIOS_BAD_REGISTER_NUMBER:
return ("PCI BIOS: bad register number");
case PCIBIOS_SET_FAILED:
return ("PCI BIOS: set failed");
case PCIBIOS_BUFFER_TOO_SMALL:
return ("PCI BIOS: buffer too small");
default:
sprintf(buf, "PCI BIOS: invalid error #%d", error);
return(buf);
}
}
/*
* Note: This routine has to access the PCI configuration space
* for the PCI bridge chip (Intel 82378).
*/
void route_PCI_interrupts(void)
{
unsigned char *ibc_pirq = (unsigned char *)0x80800860;
unsigned char *ibc_pcicon = (unsigned char *)0x80800840;
extern unsigned long isBeBox[];
int i;
/* Decide which motherboard this is & how the PCI interrupts are routed */
if (isBeBox[0])
{
Motherboard_map = BeBox_pci_IRQ_map;
Motherboard_routes = BeBox_pci_IRQ_routes;
} else
{ /* Motorola hardware */
switch (inb(0x800) & 0xF0)
{
case 0x10: /* MVME16xx */
Motherboard_map = Genesis_pci_IRQ_map;
Motherboard_routes = Genesis_pci_IRQ_routes;
break;
case 0x20: /* Series E */
Motherboard_map = Comet_pci_IRQ_map;
Motherboard_routes = Comet_pci_IRQ_routes;
break;
case 0x40: /* PowerStack */
default: /* Can't hurt, can it? */
Motherboard_map = Blackhawk_pci_IRQ_map;
Motherboard_routes = Blackhawk_pci_IRQ_routes;
break;
}
}
/* Set up mapping from slots */
for (i = 1; i <= 4; i++)
{
ibc_pirq[i-1] = Motherboard_routes[i];
}
/* Enable PCI interrupts */
*ibc_pcicon |= 0x20;
}
|