prep_pci.c 38.4 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
/*
2
 * BK Id: %F% %I% %G% %U% %#%
Linus Torvalds's avatar
Linus Torvalds committed
3 4
 */
/*
Linus Torvalds's avatar
Linus Torvalds committed
5 6 7 8 9 10 11
 * PReP pci functions.
 * Originally by Gary Thomas
 * rewritten and updated by Cort Dougan (cort@cs.nmt.edu)
 *
 * The motherboard routes/maps will disappear shortly. -- Cort
 */

Linus Torvalds's avatar
Linus Torvalds committed
12
#include <linux/config.h>
Linus Torvalds's avatar
Linus Torvalds committed
13 14 15 16 17
#include <linux/types.h>
#include <linux/pci.h>
#include <linux/kernel.h>
#include <linux/init.h>

Linus Torvalds's avatar
Linus Torvalds committed
18
#include <asm/sections.h>
Linus Torvalds's avatar
Linus Torvalds committed
19 20 21 22 23 24 25 26 27
#include <asm/byteorder.h>
#include <asm/io.h>
#include <asm/ptrace.h>
#include <asm/prom.h>
#include <asm/pci-bridge.h>
#include <asm/residual.h>
#include <asm/processor.h>
#include <asm/irq.h>
#include <asm/machdep.h>
28
#include <asm/open_pic.h>
Linus Torvalds's avatar
Linus Torvalds committed
29 30 31 32 33

#define MAX_DEVNR 22

/* Which PCI interrupt line does a given device [slot] use? */
/* Note: This really should be two dimensional based in slot/pin used */
Linus Torvalds's avatar
Linus Torvalds committed
34
static unsigned char *Motherboard_map;
Linus Torvalds's avatar
Linus Torvalds committed
35 36 37
unsigned char *Motherboard_map_name;

/* How is the 82378 PIRQ mapping setup? */
Linus Torvalds's avatar
Linus Torvalds committed
38
static unsigned char *Motherboard_routes;
Linus Torvalds's avatar
Linus Torvalds committed
39

Linus Torvalds's avatar
Linus Torvalds committed
40
static void (*Motherboard_non0)(struct pci_dev *);
Linus Torvalds's avatar
Linus Torvalds committed
41

Linus Torvalds's avatar
Linus Torvalds committed
42
static void Powerplus_Map_Non0(struct pci_dev *);
Linus Torvalds's avatar
Linus Torvalds committed
43

Linus Torvalds's avatar
Linus Torvalds committed
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
/* Used for Motorola to store system config register */
static unsigned long	*ProcInfo;

/* Tables for known hardware */   

/* Motorola PowerStackII - Utah */
static char Utah_pci_IRQ_map[23] __prepdata =
{
        0,   /* Slot 0  - unused */
        0,   /* Slot 1  - unused */
        5,   /* Slot 2  - SCSI - NCR825A  */
        0,   /* Slot 3  - unused */
        1,   /* Slot 4  - Ethernet - DEC2114x */
        0,   /* Slot 5  - unused */
        3,   /* Slot 6  - PCI Card slot #1 */
        4,   /* Slot 7  - PCI Card slot #2 */
        5,   /* Slot 8  - PCI Card slot #3 */
        5,   /* Slot 9  - PCI Bridge */
             /* added here in case we ever support PCI bridges */
             /* Secondary PCI bus cards are at slot-9,6 & slot-9,7 */
        0,   /* Slot 10 - unused */
        0,   /* Slot 11 - unused */
        5,   /* Slot 12 - SCSI - NCR825A */
        0,   /* Slot 13 - unused */
        3,   /* Slot 14 - enet */
        0,   /* Slot 15 - unused */
        2,   /* Slot 16 - unused */
        3,   /* Slot 17 - unused */
        5,   /* Slot 18 - unused */
        0,   /* Slot 19 - unused */
        0,   /* Slot 20 - unused */
        0,   /* Slot 21 - unused */
        0,   /* Slot 22 - unused */
};

static char Utah_pci_IRQ_routes[] __prepdata =
{
        0,   /* Line 0 - Unused */
        9,   /* Line 1 */
	10,  /* Line 2 */
        11,  /* Line 3 */
        14,  /* Line 4 */
        15,  /* Line 5 */
};

/* Motorola PowerStackII - Omaha */
/* no integrated SCSI or ethernet */
static char Omaha_pci_IRQ_map[23] __prepdata =
{
        0,   /* Slot 0  - unused */
        0,   /* Slot 1  - unused */
        3,   /* Slot 2  - Winbond EIDE */
        0,   /* Slot 3  - unused */
        0,   /* Slot 4  - unused */
        0,   /* Slot 5  - unused */
        1,   /* Slot 6  - PCI slot 1 */
        2,   /* Slot 7  - PCI slot 2  */
        3,   /* Slot 8  - PCI slot 3 */
        4,   /* Slot 9  - PCI slot 4 */ /* needs indirect access */
        0,   /* Slot 10 - unused */
        0,   /* Slot 11 - unused */
        0,   /* Slot 12 - unused */
        0,   /* Slot 13 - unused */
        0,   /* Slot 14 - unused */
        0,   /* Slot 15 - unused */
        1,   /* Slot 16  - PCI slot 1 */
        2,   /* Slot 17  - PCI slot 2  */
        3,   /* Slot 18  - PCI slot 3 */
        4,   /* Slot 19  - PCI slot 4 */ /* needs indirect access */
        0,
        0,
        0,
};

static char Omaha_pci_IRQ_routes[] __prepdata =
{
        0,   /* Line 0 - Unused */
        9,   /* Line 1 */
        11,  /* Line 2 */
        14,  /* Line 3 */
        15   /* Line 4 */
};

/* Motorola PowerStack */
static char Blackhawk_pci_IRQ_map[19] __prepdata =
{
  	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 */
 	1,	/* Slot P7 */
 	2,	/* Slot P6 */
 	3,	/* Slot P5 */
};

static char Blackhawk_pci_IRQ_routes[] __prepdata =
{
   	0,	/* Line 0 - Unused */
   	9,	/* Line 1 */
   	11,	/* Line 2 */
   	15,	/* Line 3 */
   	15	/* Line 4 */
};
   
/* Motorola Mesquite */
static char Mesquite_pci_IRQ_map[23] __prepdata =
{
	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 */
Linus Torvalds's avatar
Linus Torvalds committed
173
	0,	/* Slot 10 - unused */
Linus Torvalds's avatar
Linus Torvalds committed
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
	0,	/* Slot 11 - unused */
	0,	/* Slot 12 - unused */
	0,	/* Slot 13 - unused */
	2,	/* Slot 14 - Ethernet */
	0,	/* Slot 15 - unused */
	3,	/* Slot 16 - PMC */
	0,	/* Slot 17 - unused */
	0,	/* Slot 18 - unused */
	0,	/* Slot 19 - unused */
	0,	/* Slot 20 - unused */
	0,	/* Slot 21 - unused */
	0,	/* Slot 22 - unused */
};

/* Motorola Sitka */
static char Sitka_pci_IRQ_map[21] __prepdata =
{
	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 */
Linus Torvalds's avatar
Linus Torvalds committed
201
	0,      /* Slot 10 - unused */
Linus Torvalds's avatar
Linus Torvalds committed
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
	0,      /* Slot 11 - unused */
	0,      /* Slot 12 - unused */
	0,      /* Slot 13 - unused */
	2,      /* Slot 14 - Ethernet */
	0,      /* Slot 15 - unused */
	9,      /* Slot 16 - PMC 1  */
	12,     /* Slot 17 - PMC 2  */
	0,      /* Slot 18 - unused */
	0,      /* Slot 19 - unused */
	4,      /* Slot 20 - NT P2P bridge */
};

/* Motorola MTX */
static char MTX_pci_IRQ_map[23] __prepdata =
{
	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 */
	2,	/* Slot 14 - Ethernet */
	0,	/* Slot 15 - unused */
	9,      /* Slot 16 - PCI/PMC slot 1 */
	10,     /* Slot 17 - PCI/PMC slot 2 */
	11,     /* Slot 18 - PCI slot 3 */
	0,	/* Slot 19 - unused */
	0,	/* Slot 20 - unused */
	0,	/* Slot 21 - unused */
	0,	/* Slot 22 - unused */
};

/* Motorola MTX Plus */
/* Secondary bus interrupt routing is not supported yet */
static char MTXplus_pci_IRQ_map[23] __prepdata =
{
        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 */
        2,      /* Slot 14 - Ethernet 1 */
        0,      /* Slot 15 - unused */
        9,      /* Slot 16 - PCI slot 1P */
        10,     /* Slot 17 - PCI slot 2P */
        11,     /* Slot 18 - PCI slot 3P */
        10,     /* Slot 19 - Ethernet 2 */
        0,      /* Slot 20 - P2P Bridge */
        0,      /* Slot 21 - unused */
        0,      /* Slot 22 - unused */
};

static char Raven_pci_IRQ_routes[] __prepdata =
{
   	0,	/* This is a dummy structure */
};
   
/* Motorola MVME16xx */
static char Genesis_pci_IRQ_map[16] __prepdata =
{
  	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[] __prepdata =
{
   	0,	/* Line 0 - Unused */
   	10,	/* Line 1 */
   	11,	/* Line 2 */
   	14,	/* Line 3 */
   	15	/* Line 4 */
};
   
static char Genesis2_pci_IRQ_map[23] __prepdata =
{
	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 - Ethernet */
	0,	/* Slot 11 - Universe PCI - VME Bridge */
	3,	/* Slot 12 - unused */
	0,	/* Slot 13 - unused */
	2,	/* Slot 14 - SCSI */
Linus Torvalds's avatar
Linus Torvalds committed
323 324
	0,	/* Slot 15 - unused */
	9,	/* Slot 16 - PMC 1 */
Linus Torvalds's avatar
Linus Torvalds committed
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
	12,	/* Slot 17 - pci */
	11,	/* Slot 18 - pci */
	10,	/* Slot 19 - pci */
	0,	/* Slot 20 - pci */
	0,	/* Slot 21 - unused */
	0,	/* Slot 22 - unused */
};

/* Motorola Series-E */
static char Comet_pci_IRQ_map[23] __prepdata =
{
  	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 */
	1,	/* Slot 16 - PCI slot 1 */
	2,	/* Slot 17 - PCI slot 2 */
	3,	/* Slot 18 - PCI slot 3 */
	4,	/* Slot 19 - PCI bridge */
	0,
	0,
	0,
};

static char Comet_pci_IRQ_routes[] __prepdata =
{
   	0,	/* Line 0 - Unused */
   	10,	/* Line 1 */
   	11,	/* Line 2 */
   	14,	/* Line 3 */
   	15	/* Line 4 */
};

/* Motorola Series-EX */
static char Comet2_pci_IRQ_map[23] __prepdata =
{
	0,	/* Slot 0  - unused */
	0,	/* Slot 1  - unused */
	3,	/* Slot 2  - SCSI - NCR825A */
	0,	/* Slot 3  - unused */
	1,	/* Slot 4  - Ethernet - DEC2104X */
	0,	/* Slot 5  - unused */
	1,	/* Slot 6  - PCI slot 1 */
	2,	/* Slot 7  - PCI slot 2 */
	3,	/* Slot 8  - PCI slot 3 */
	4,	/* Slot 9  - PCI bridge  */
	0,	/* Slot 10 - unused */
	0,	/* Slot 11 - unused */
	3,	/* Slot 12 - SCSI - NCR825A */
	0,	/* Slot 13 - unused */
	1,	/* Slot 14 - Ethernet - DEC2104X */
	0,	/* Slot 15 - unused */
	1,	/* Slot 16 - PCI slot 1 */
	2,	/* Slot 17 - PCI slot 2 */
	3,	/* Slot 18 - PCI slot 3 */
	4,	/* Slot 19 - PCI bridge */
	0,
	0,
	0,
};

static char Comet2_pci_IRQ_routes[] __prepdata =
{
	0,	/* Line 0 - Unused */
	10,	/* Line 1 */
	11,	/* Line 2 */
	14,	/* Line 3 */
	15,	/* Line 4 */
};

/*
 * ibm 830 (and 850?).
 * This is actually based on the Carolina motherboard
 * -- Cort
 */
static char ibm8xx_pci_IRQ_map[23] __prepdata = {
        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 - FireCoral */
        4, /* Slot 12 - Ethernet  PCIINTD# */
        2, /* Slot 13 - PCI Slot #2 */
        2, /* Slot 14 - S3 Video PCIINTD# */
        0, /* Slot 15 - onboard SCSI (INDI) [1] */
        3, /* Slot 16 - NCR58C810 RS6000 Only PCIINTC# */
        0, /* Slot 17 - unused */
        2, /* Slot 18 - PCI Slot 2 PCIINTx# (See below) */
        0, /* Slot 19 - unused */
        0, /* Slot 20 - unused */
        0, /* Slot 21 - unused */
        2, /* Slot 22 - PCI slot 1 PCIINTx# (See below) */
};

static char ibm8xx_pci_IRQ_routes[] __prepdata = {
        0,      /* Line 0 - unused */
Linus Torvalds's avatar
Linus Torvalds committed
440 441
        15,     /* Line 1 */
        15,     /* Line 2 */
Linus Torvalds's avatar
Linus Torvalds committed
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
        15,     /* Line 3 */
        15,     /* Line 4 */
};

/*
 * a 6015 ibm board
 * -- Cort
 */
static char ibm6015_pci_IRQ_map[23] __prepdata = {
        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 -  */
        1, /* Slot 12 - SCSI */
        2, /* Slot 13 -  */
        2, /* Slot 14 -  */
        1, /* Slot 15 -  */
        1, /* Slot 16 -  */
        0, /* Slot 17 -  */
        2, /* Slot 18 -  */
        0, /* Slot 19 -  */
        0, /* Slot 20 -  */
        0, /* Slot 21 -  */
        2, /* Slot 22 -  */
};
Linus Torvalds's avatar
Linus Torvalds committed
475

Linus Torvalds's avatar
Linus Torvalds committed
476 477 478
static char ibm6015_pci_IRQ_routes[] __prepdata = {
        0,      /* Line 0 - unused */
        13,     /* Line 1 */
Linus Torvalds's avatar
Linus Torvalds committed
479
        15,     /* Line 2 */
Linus Torvalds's avatar
Linus Torvalds committed
480 481 482 483 484
        15,     /* Line 3 */
        15,     /* Line 4 */
};


Linus Torvalds's avatar
Linus Torvalds committed
485
/* IBM Nobis and Thinkpad 850 */
Linus Torvalds's avatar
Linus Torvalds committed
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
static char Nobis_pci_IRQ_map[23] __prepdata ={
        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 */
        0, /* Slot 14 - unused */
        0, /* Slot 15 - unused */
};

static char Nobis_pci_IRQ_routes[] __prepdata = {
        0, /* Line 0 - Unused */
        13, /* Line 1 */
        13, /* Line 2 */
        13, /* Line 3 */
        13      /* Line 4 */
};

Linus Torvalds's avatar
Linus Torvalds committed
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
/*
 * IBM RS/6000 43p/140  -- paulus
 * XXX we should get all this from the residual data
 */
static char ibm43p_pci_IRQ_map[23] __prepdata = {
        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 - FireCoral ISA bridge */
        6, /* Slot 12 - Ethernet  */
        0, /* Slot 13 - openpic */
        0, /* Slot 14 - unused */
        0, /* Slot 15 - unused */
        7, /* Slot 16 - NCR58C825a onboard scsi */
        0, /* Slot 17 - unused */
        2, /* Slot 18 - PCI Slot 2 PCIINTx# (See below) */
        0, /* Slot 19 - unused */
        0, /* Slot 20 - unused */
        0, /* Slot 21 - unused */
        1, /* Slot 22 - PCI slot 1 PCIINTx# (See below) */
};

static char ibm43p_pci_IRQ_routes[] __prepdata = {
        0,      /* Line 0 - unused */
        15,     /* Line 1 */
        15,     /* Line 2 */
        15,     /* Line 3 */
        15,     /* Line 4 */
};

Linus Torvalds's avatar
Linus Torvalds committed
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
/* Motorola PowerPlus architecture PCI IRQ tables */
/* Interrupt line values for INTA-D on primary/secondary MPIC inputs */

struct powerplus_irq_list
{
	unsigned char primary[4];       /* INT A-D */
	unsigned char secondary[4];     /* INT A-D */
};

/*
 * For standard PowerPlus boards, bus 0 PCI INTs A-D are routed to
 * OpenPIC inputs 9-12.  PCI INTs A-D from the on board P2P bridge
 * are routed to OpenPIC inputs 5-8.  These values are offset by
 * 16 in the table to reflect the Linux kernel interrupt value.
 */
Linus Torvalds's avatar
Linus Torvalds committed
566
struct powerplus_irq_list Powerplus_pci_IRQ_list __prepdata =
Linus Torvalds's avatar
Linus Torvalds committed
567 568 569 570 571 572 573 574 575 576 577 578
{
	{25, 26, 27, 28},
	{21, 22, 23, 24}
};

/*
 * For the MCP750 (system slot board), cPCI INTs A-D are routed to
 * OpenPIC inputs 8-11 and the PMC INTs A-D are routed to OpenPIC
 * input 3.  On a hot swap MCP750, the companion card PCI INTs A-D
 * are routed to OpenPIC inputs 12-15. These values are offset by
 * 16 in the table to reflect the Linux kernel interrupt value.
 */
Linus Torvalds's avatar
Linus Torvalds committed
579
struct powerplus_irq_list Mesquite_pci_IRQ_list __prepdata =
Linus Torvalds's avatar
Linus Torvalds committed
580 581 582 583 584 585 586 587 588
{
	{24, 25, 26, 27},
	{28, 29, 30, 31}
};

/*
 * This table represents the standard PCI swizzle defined in the
 * PCI bus specification.
 */
Linus Torvalds's avatar
Linus Torvalds committed
589
static unsigned char prep_pci_intpins[4][4] __prepdata =
Linus Torvalds's avatar
Linus Torvalds committed
590 591 592 593 594 595 596
{
	{ 1, 2, 3, 4},  /* Buses 0, 4, 8, ... */
	{ 2, 3, 4, 1},  /* Buses 1, 5, 9, ... */
	{ 3, 4, 1, 2},  /* Buses 2, 6, 10 ... */
	{ 4, 1, 2, 3},  /* Buses 3, 7, 11 ... */
};

Linus Torvalds's avatar
Linus Torvalds committed
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
/* We have to turn on LEVEL mode for changed IRQ's */
/* All PCI IRQ's need to be level mode, so this should be something
 * other than hard-coded as well... IRQ's are individually mappable
 * to either edge or level.
 */

/*
 * 8259 edge/level control definitions
 */
#define ISA8259_M_ELCR 0x4d0
#define ISA8259_S_ELCR 0x4d1

#define ELCRS_INT15_LVL         0x80
#define ELCRS_INT14_LVL         0x40
#define ELCRS_INT12_LVL         0x10
#define ELCRS_INT11_LVL         0x08
#define ELCRS_INT10_LVL         0x04
#define ELCRS_INT9_LVL          0x02
#define ELCRS_INT8_LVL          0x01
#define ELCRM_INT7_LVL          0x80
#define ELCRM_INT5_LVL          0x20

#define CFGPTR(dev) (0x80800000 | (1<<(dev>>3)) | ((dev&7)<<8) | offset)
#define DEVNO(dev)  (dev>>3)                                  

Linus Torvalds's avatar
Linus Torvalds committed
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
#define cfg_read(val, addr, type, op)	*val = op((type)(addr))
#define cfg_write(val, addr, type, op)	op((type *)(addr), (val))

#define cfg_read_bad(val, size)		*val = bad_##size;
#define cfg_write_bad(val, size)

#define bad_byte	0xff
#define bad_word	0xffff
#define bad_dword	0xffffffffU

#define PREP_PCI_OP(rw, size, type, op)					\
static int __prep							\
prep_##rw##_config_##size(struct pci_dev *dev, int offset, type val)	\
{									\
	if ((dev->bus->number != 0) || (DEVNO(dev->devfn) > MAX_DEVNR))	\
	{                   						\
		cfg_##rw##_bad(val, size)				\
		return PCIBIOS_DEVICE_NOT_FOUND;    			\
	}								\
	cfg_##rw(val, CFGPTR(dev->devfn), type, op);			\
	return PCIBIOS_SUCCESSFUL;					\
Linus Torvalds's avatar
Linus Torvalds committed
643 644
}

Linus Torvalds's avatar
Linus Torvalds committed
645 646 647 648 649 650
PREP_PCI_OP(read, byte, u8 *, in_8)
PREP_PCI_OP(read, word, u16 *, in_le16)
PREP_PCI_OP(read, dword, u32 *, in_le32)
PREP_PCI_OP(write, byte, u8, out_8)
PREP_PCI_OP(write, word, u16, out_le16)
PREP_PCI_OP(write, dword, u32, out_le32)
Linus Torvalds's avatar
Linus Torvalds committed
651

Linus Torvalds's avatar
Linus Torvalds committed
652
static struct pci_ops prep_pci_ops =
Linus Torvalds's avatar
Linus Torvalds committed
653
{
Linus Torvalds's avatar
Linus Torvalds committed
654 655 656 657 658 659 660
	prep_read_config_byte,
	prep_read_config_word,
	prep_read_config_dword,
	prep_write_config_byte,
	prep_write_config_word,
	prep_write_config_dword
};
Linus Torvalds's avatar
Linus Torvalds committed
661 662 663 664 665 666 667

#define MOTOROLA_CPUTYPE_REG	0x800
#define MOTOROLA_BASETYPE_REG	0x803
#define MPIC_RAVEN_ID		0x48010000
#define	MPIC_HAWK_ID		0x48030000
#define	MOT_PROC2_BIT		0x800

668 669 670
static u_char prep_openpic_initsenses[] __initdata = {
    (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* MVME2600_INT_SIO */
    (IRQ_SENSE_EDGE | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_FALCON_ECC_ERR */
671 672 673 674 675 676 677 678 679 680 681 682 683
    (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_ETHERNET */
    (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_SCSI */
    (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_GRAPHICS */
    (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_VME0 */
    (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_VME1 */
    (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_VME2 */
    (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_VME3 */
    (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_INTA */
    (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_INTB */
    (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_INTC */
    (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_INTD */
    (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_LM_SIG0 */
    (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_LM_SIG1 */
Linus Torvalds's avatar
Linus Torvalds committed
684 685 686 687 688
};

#define MOT_RAVEN_PRESENT	0x1
#define MOT_HAWK_PRESENT	0x2

Linus Torvalds's avatar
Linus Torvalds committed
689
int mot_entry = -1;
Linus Torvalds's avatar
Linus Torvalds committed
690
int prep_keybd_present = 1;
Linus Torvalds's avatar
Linus Torvalds committed
691 692
int MotMPIC;
int mot_multi;
Linus Torvalds's avatar
Linus Torvalds committed
693

Linus Torvalds's avatar
Linus Torvalds committed
694 695
int __init
raven_init(void)
Linus Torvalds's avatar
Linus Torvalds committed
696 697 698 699 700 701 702
{
	unsigned int	devid;
	unsigned int	pci_membase;
	unsigned char	base_mod;

	/* Check to see if the Raven chip exists. */
	if ( _prep_type != _PREP_Motorola) {
Linus Torvalds's avatar
Linus Torvalds committed
703
		OpenPIC_Addr = NULL;
Linus Torvalds's avatar
Linus Torvalds committed
704 705 706 707 708
		return 0;
	}

	/* Check to see if this board is a type that might have a Raven. */
	if ((inb(MOTOROLA_CPUTYPE_REG) & 0xF0) != 0xE0) {
Linus Torvalds's avatar
Linus Torvalds committed
709
		OpenPIC_Addr = NULL;
Linus Torvalds's avatar
Linus Torvalds committed
710 711 712 713
		return 0;
	}

	/* Check the first PCI device to see if it is a Raven. */
Linus Torvalds's avatar
Linus Torvalds committed
714
	early_read_config_dword(0, 0, 0, PCI_VENDOR_ID, &devid);
Linus Torvalds's avatar
Linus Torvalds committed
715 716 717 718 719 720 721 722 723

	switch (devid & 0xffff0000) {
	case MPIC_RAVEN_ID:
		MotMPIC = MOT_RAVEN_PRESENT;
		break;
	case MPIC_HAWK_ID:
		MotMPIC = MOT_HAWK_PRESENT;
		break;
	default:
Linus Torvalds's avatar
Linus Torvalds committed
724
		OpenPIC_Addr = NULL;
Linus Torvalds's avatar
Linus Torvalds committed
725 726 727 728 729
		return 0;
	}


	/* Read the memory base register. */
Linus Torvalds's avatar
Linus Torvalds committed
730
	early_read_config_dword(0, 0, 0, PCI_BASE_ADDRESS_1, &pci_membase);
Linus Torvalds's avatar
Linus Torvalds committed
731 732

	if (pci_membase == 0) {
Linus Torvalds's avatar
Linus Torvalds committed
733
		OpenPIC_Addr = NULL;
Linus Torvalds's avatar
Linus Torvalds committed
734 735 736 737
		return 0;
	}

	/* Map the Raven MPIC registers to virtual memory. */
Linus Torvalds's avatar
Linus Torvalds committed
738
	OpenPIC_Addr = ioremap(pci_membase+0xC0000000, 0x22000);
Linus Torvalds's avatar
Linus Torvalds committed
739

740 741
	OpenPIC_InitSenses = prep_openpic_initsenses;
	OpenPIC_NumInitSenses = sizeof(prep_openpic_initsenses);
Linus Torvalds's avatar
Linus Torvalds committed
742

Linus Torvalds's avatar
Linus Torvalds committed
743
	ppc_md.get_irq = openpic_get_irq;
Linus Torvalds's avatar
Linus Torvalds committed
744 745 746 747 748 749
	
	/* If raven is present on Motorola store the system config register
	 * for later use.
	 */
	ProcInfo = (unsigned long *)ioremap(0xfef80400, 4);

Linus Torvalds's avatar
Linus Torvalds committed
750 751 752 753 754
	/* Indicate to system if this is a multiprocessor board */
	if (!(*ProcInfo & MOT_PROC2_BIT)) {
		mot_multi = 1;
	}

Linus Torvalds's avatar
Linus Torvalds committed
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
	/* This is a hack.  If this is a 2300 or 2400 mot board then there is
	 * no keyboard controller and we have to indicate that.
	 */
	base_mod = inb(MOTOROLA_BASETYPE_REG);
	if ((MotMPIC == MOT_HAWK_PRESENT) || (base_mod == 0xF9) ||
	    (base_mod == 0xFA) || (base_mod == 0xE1))
		prep_keybd_present = 0;

	return 1;
}

struct mot_info {
	int		cpu_type;	/* 0x100 mask assumes for Raven and Hawk boards that the level/edge are set */
					/* 0x200 if this board has a Hawk chip. */
	int		base_type;
	int		max_cpu;	/* ored with 0x80 if this board should be checked for multi CPU */
	const char	*name;
	unsigned char	*map;
	unsigned char	*routes;
Linus Torvalds's avatar
Linus Torvalds committed
774 775 776
	void            (*map_non0_bus)(struct pci_dev *);      /* For boards with more than bus 0 devices. */
	struct powerplus_irq_list *pci_irq_list; /* List of PCI MPIC inputs */
	unsigned char   secondary_bridge_devfn; /* devfn of secondary bus transparent bridge */
Linus Torvalds's avatar
Linus Torvalds committed
777
} mot_info[] __prepdata = {
Linus Torvalds's avatar
Linus Torvalds committed
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
	{0x300, 0x00, 0x00, "MVME 2400",			Genesis2_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0xFF},
	{0x010, 0x00, 0x00, "Genesis",				Genesis_pci_IRQ_map,	Genesis_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0x00},
	{0x020, 0x00, 0x00, "Powerstack (Series E)",		Comet_pci_IRQ_map,	Comet_pci_IRQ_routes, NULL, NULL, 0x00},
	{0x040, 0x00, 0x00, "Blackhawk (Powerstack)",		Blackhawk_pci_IRQ_map,	Blackhawk_pci_IRQ_routes, NULL, NULL, 0x00},
	{0x050, 0x00, 0x00, "Omaha (PowerStack II Pro3000)",	Omaha_pci_IRQ_map,	Omaha_pci_IRQ_routes, NULL, NULL, 0x00},
	{0x060, 0x00, 0x00, "Utah (Powerstack II Pro4000)",	Utah_pci_IRQ_map,	Utah_pci_IRQ_routes, NULL, NULL, 0x00},
	{0x0A0, 0x00, 0x00, "Powerstack (Series EX)",		Comet2_pci_IRQ_map,	Comet2_pci_IRQ_routes, NULL, NULL, 0x00},
	{0x1E0, 0xE0, 0x00, "Mesquite cPCI (MCP750)",		Mesquite_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Mesquite_pci_IRQ_list, 0xFF},
	{0x1E0, 0xE1, 0x00, "Sitka cPCI (MCPN750)",		Sitka_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0xFF},
	{0x1E0, 0xE2, 0x00, "Mesquite cPCI (MCP750) w/ HAC",	Mesquite_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Mesquite_pci_IRQ_list, 0xC0},
	{0x1E0, 0xF6, 0x80, "MTX Plus",				MTXplus_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0xA0},
	{0x1E0, 0xF6, 0x81, "Dual MTX Plus",			MTXplus_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0xA0},
	{0x1E0, 0xF7, 0x80, "MTX wo/ Parallel Port",		MTX_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0x00},
	{0x1E0, 0xF7, 0x81, "Dual MTX wo/ Parallel Port",	MTX_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0x00},
	{0x1E0, 0xF8, 0x80, "MTX w/ Parallel Port",		MTX_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0x00},
	{0x1E0, 0xF8, 0x81, "Dual MTX w/ Parallel Port",	MTX_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0x00},
	{0x1E0, 0xF9, 0x00, "MVME 2300",			Genesis2_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0xFF},
	{0x1E0, 0xFA, 0x00, "MVME 2300SC/2600",			Genesis2_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0xFF},
	{0x1E0, 0xFB, 0x00, "MVME 2600 with MVME712M",		Genesis2_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0xFF},
	{0x1E0, 0xFC, 0x00, "MVME 2600/2700 with MVME761",	Genesis2_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0xFF},
	{0x1E0, 0xFD, 0x80, "MVME 3600 with MVME712M",		Genesis2_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0x00},
	{0x1E0, 0xFD, 0x81, "MVME 4600 with MVME712M",		Genesis2_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0xFF},
	{0x1E0, 0xFE, 0x80, "MVME 3600 with MVME761",		Genesis2_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0xFF},
	{0x1E0, 0xFE, 0x81, "MVME 4600 with MVME761",		Genesis2_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0xFF},
	{0x1E0, 0xFF, 0x00, "MVME 1600-001 or 1600-011",	Genesis2_pci_IRQ_map,	Raven_pci_IRQ_routes, Powerplus_Map_Non0, &Powerplus_pci_IRQ_list, 0xFF},
	{0x000, 0x00, 0x00, "",					NULL,			NULL, NULL, NULL, 0x00}
Linus Torvalds's avatar
Linus Torvalds committed
804 805
};

Linus Torvalds's avatar
Linus Torvalds committed
806 807
void __init
ibm_prep_init(void)
Linus Torvalds's avatar
Linus Torvalds committed
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823
{
	u32 addr;
#ifdef CONFIG_PREP_RESIDUAL
	PPC_DEVICE *mpic;
#endif

	if (inb(0x0852) == 0xd5) {
		/* This is for the 43p-140 */
		early_read_config_dword(0, 0, PCI_DEVFN(13, 0),
					PCI_BASE_ADDRESS_0, &addr);
		if (addr != 0xffffffff
		    && !(addr & PCI_BASE_ADDRESS_SPACE_IO)
		    && (addr &= PCI_BASE_ADDRESS_MEM_MASK) != 0) {
			addr += PREP_ISA_MEM_BASE;
			OpenPIC_Addr = ioremap(addr, 0x40000);
			ppc_md.get_irq = openpic_get_irq;
824 825 826

			OpenPIC_InitSenses = prep_openpic_initsenses;
			OpenPIC_NumInitSenses = sizeof(prep_openpic_initsenses);
Linus Torvalds's avatar
Linus Torvalds committed
827 828 829 830 831 832
		}
	}

#ifdef CONFIG_PREP_RESIDUAL
	mpic = residual_find_device(-1, NULL, SystemPeripheral,
				    ProgrammableInterruptController, MPIC, 0);
Linus Torvalds's avatar
Linus Torvalds committed
833
	if (mpic != NULL)
Linus Torvalds's avatar
Linus Torvalds committed
834 835 836 837
		printk("mpic = %p\n", mpic);
#endif
}

Linus Torvalds's avatar
Linus Torvalds committed
838
static void __init
Linus Torvalds's avatar
Linus Torvalds committed
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853
ibm43p_pci_map_non0(struct pci_dev *dev)
{
	unsigned char intpin;
	static unsigned char bridge_intrs[4] = { 3, 4, 5, 8 };

	if (dev == NULL)
		return;
	pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &intpin);
	if (intpin < 1 || intpin > 4)
		return;
	intpin = (PCI_SLOT(dev->devfn) + intpin - 1) & 3;
	dev->irq = openpic_to_irq(bridge_intrs[intpin]);
	pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
}

Linus Torvalds's avatar
Linus Torvalds committed
854 855
void __init
prep_route_pci_interrupts(void)
Linus Torvalds's avatar
Linus Torvalds committed
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911
{
	unsigned char *ibc_pirq = (unsigned char *)0x80800860;
	unsigned char *ibc_pcicon = (unsigned char *)0x80800840;
	int i;
	
	if ( _prep_type == _PREP_Motorola)
	{
		unsigned short irq_mode;
		unsigned char  cpu_type;
		unsigned char  base_mod;
		int	       entry;

		cpu_type = inb(MOTOROLA_CPUTYPE_REG) & 0xF0;
		base_mod = inb(MOTOROLA_BASETYPE_REG);

		for (entry = 0; mot_info[entry].cpu_type != 0; entry++) {
			if (mot_info[entry].cpu_type & 0x200) {		 	/* Check for Hawk chip */
				if (!(MotMPIC & MOT_HAWK_PRESENT))
					continue;
			} else {						/* Check non hawk boards */
				if ((mot_info[entry].cpu_type & 0xff) != cpu_type)
					continue;

				if (mot_info[entry].base_type == 0) {
					mot_entry = entry;
					break;
				}

				if (mot_info[entry].base_type != base_mod)
					continue;
			}

			if (!(mot_info[entry].max_cpu & 0x80)) {
				mot_entry = entry;
				break;
			}

			/* processor 1 not present and max processor zero indicated */
			if ((*ProcInfo & MOT_PROC2_BIT) && !(mot_info[entry].max_cpu & 0x7f)) {
				mot_entry = entry;
				break;
			}

			/* processor 1 present and max processor zero indicated */
			if (!(*ProcInfo & MOT_PROC2_BIT) && (mot_info[entry].max_cpu & 0x7f)) {
				mot_entry = entry;
				break;
			}
		}

		if (mot_entry == -1) 	/* No particular cpu type found - assume Blackhawk */
			mot_entry = 3;

		Motherboard_map_name = (unsigned char *)mot_info[mot_entry].name;
		Motherboard_map = mot_info[mot_entry].map;
		Motherboard_routes = mot_info[mot_entry].routes;
Linus Torvalds's avatar
Linus Torvalds committed
912
		Motherboard_non0 = mot_info[mot_entry].map_non0_bus;
Linus Torvalds's avatar
Linus Torvalds committed
913 914 915 916 917 918 919 920 921

		if (!(mot_info[entry].cpu_type & 0x100)) {
			/* AJF adjust level/edge control according to routes */
			irq_mode = 0;
			for (i = 1;  i <= 4;  i++)
				irq_mode |= ( 1 << Motherboard_routes[i] );
			outb( irq_mode & 0xff, 0x4d0 );
			outb( (irq_mode >> 8) & 0xff, 0x4d1 );
		}
Linus Torvalds's avatar
Linus Torvalds committed
922 923 924 925 926 927
	} else if ( _prep_type == _PREP_IBM ) {
		unsigned char planar_id = inb(0x0852);
		unsigned char irq_edge_mask_lo, irq_edge_mask_hi;

		printk("IBM ID: %08x\n", planar_id);
		switch(planar_id) {
Linus Torvalds's avatar
Linus Torvalds committed
928
		case 0xff:
Linus Torvalds's avatar
Linus Torvalds committed
929
			Motherboard_map_name = "IBM Thinkpad 850/860";
Linus Torvalds's avatar
Linus Torvalds committed
930 931
			Motherboard_map = Nobis_pci_IRQ_map;
			Motherboard_routes = Nobis_pci_IRQ_routes;
Linus Torvalds's avatar
Linus Torvalds committed
932 933
			irq_edge_mask_lo = 0x00; /* irq's 0-7 all edge-triggered */
			irq_edge_mask_hi = 0xA0; /* irq's 13, 15 level-triggered */
Linus Torvalds's avatar
Linus Torvalds committed
934 935
			break;
		case 0xfc:
Linus Torvalds's avatar
Linus Torvalds committed
936
			Motherboard_map_name = "IBM 6015/7020 (Sandalfoot/Sandalbow)";
Linus Torvalds's avatar
Linus Torvalds committed
937 938
			Motherboard_map = ibm6015_pci_IRQ_map;
			Motherboard_routes = ibm6015_pci_IRQ_routes;
Linus Torvalds's avatar
Linus Torvalds committed
939 940
			irq_edge_mask_lo = 0x00; /* irq's 0-7 all edge-triggered */
			irq_edge_mask_hi = 0xA0; /* irq's 13, 15 level-triggered */
Linus Torvalds's avatar
Linus Torvalds committed
941 942
			break;
		case 0xd5:
Linus Torvalds's avatar
Linus Torvalds committed
943
			Motherboard_map_name = "IBM 43P-140 (Tiger1)";
Linus Torvalds's avatar
Linus Torvalds committed
944 945 946
			Motherboard_map = ibm43p_pci_IRQ_map;
			Motherboard_routes = ibm43p_pci_IRQ_routes;
			Motherboard_non0 = ibm43p_pci_map_non0;
Linus Torvalds's avatar
Linus Torvalds committed
947 948
			irq_edge_mask_lo = 0x00; /* irq's 0-7 all edge-triggered */
			irq_edge_mask_hi = 0xA0; /* irq's 13, 15 level-triggered */
Linus Torvalds's avatar
Linus Torvalds committed
949
			break;
Linus Torvalds's avatar
Linus Torvalds committed
950
		default:
Linus Torvalds's avatar
Linus Torvalds committed
951 952 953 954 955 956 957 958 959
			printk(KERN_ERR "Unknown IBM motherboard! Defaulting to Carolina.\n");
		case 0xf0: /* PowerSeries 830/850 */
		case 0xf1: /* PowerSeries 830/850 */
		case 0xf2: /* PowerSeries 830/850 */
		case 0xf4: /* 7248-43P */
		case 0xf5: /* 7248-43P */
		case 0xf6: /* 7248-43P */
		case 0xf7: /* 7248-43P (missing from Carolina Tech Spec) */
			Motherboard_map_name = "IBM PS830/PS850/7248 (Carolina)";
Linus Torvalds's avatar
Linus Torvalds committed
960 961
			Motherboard_map = ibm8xx_pci_IRQ_map;
			Motherboard_routes = ibm8xx_pci_IRQ_routes;
Linus Torvalds's avatar
Linus Torvalds committed
962 963
			irq_edge_mask_lo = 0x00; /* irq's 0-7 all edge-triggered */
			irq_edge_mask_hi = 0xA4; /* irq's 10, 13, 15 level-triggered */
Linus Torvalds's avatar
Linus Torvalds committed
964 965 966
			break;
		}

Linus Torvalds's avatar
Linus Torvalds committed
967 968 969
		outb(inb(0x04d0)|irq_edge_mask_lo, 0x04d0); /* primary 8259 */
		outb(inb(0x04d1)|irq_edge_mask_hi, 0x04d1); /* cascaded 8259 */
	} else {
Linus Torvalds's avatar
Linus Torvalds committed
970
		printk("No known machine pci routing!\n");
Linus Torvalds's avatar
Linus Torvalds committed
971
		return;
Linus Torvalds's avatar
Linus Torvalds committed
972 973 974 975 976 977 978 979 980
	}
	
	/* Set up mapping from slots */
	for (i = 1;  i <= 4;  i++)
		ibc_pirq[i-1] = Motherboard_routes[i];
	/* Enable PCI interrupts */
	*ibc_pcicon |= 0x20;
}

Linus Torvalds's avatar
Linus Torvalds committed
981 982 983
void __init
prep_pib_init(void)
{
Linus Torvalds's avatar
Linus Torvalds committed
984 985
	unsigned char   reg;
	unsigned short  short_reg;
Linus Torvalds's avatar
Linus Torvalds committed
986

Linus Torvalds's avatar
Linus Torvalds committed
987
	struct pci_dev *dev = NULL;
Linus Torvalds's avatar
Linus Torvalds committed
988 989 990 991 992 993 994 995 996 997 998 999

	if (( _prep_type == _PREP_Motorola) && (OpenPIC_Addr)) {
		/*
		 * Perform specific configuration for the Via Tech or
		 * or Winbond PCI-ISA-Bridge part.
		 */
		if ((dev = pci_find_device(PCI_VENDOR_ID_VIA, 
					PCI_DEVICE_ID_VIA_82C586_1, dev))) {
			/*
			 * PPCBUG does not set the enable bits
			 * for the IDE device. Force them on here.
			 */
Linus Torvalds's avatar
Linus Torvalds committed
1000
			pci_read_config_byte(dev, 0x40, &reg);
Linus Torvalds's avatar
Linus Torvalds committed
1001 1002

			reg |= 0x03; /* IDE: Chip Enable Bits */
Linus Torvalds's avatar
Linus Torvalds committed
1003 1004 1005 1006 1007 1008 1009 1010
			pci_write_config_byte(dev, 0x40, reg);
		}
		if ((dev = pci_find_device(PCI_VENDOR_ID_VIA,
						PCI_DEVICE_ID_VIA_82C586_2,
						dev)) && (dev->devfn = 0x5a)) {
			/* Force correct USB interrupt */
			dev->irq = 11;
			pci_write_config_byte(dev,
Linus Torvalds's avatar
Linus Torvalds committed
1011 1012
					PCI_INTERRUPT_LINE,
					dev->irq);
Linus Torvalds's avatar
Linus Torvalds committed
1013 1014
		}
		if ((dev = pci_find_device(PCI_VENDOR_ID_WINBOND,
Linus Torvalds's avatar
Linus Torvalds committed
1015
					PCI_DEVICE_ID_WINBOND_83C553, dev))) {
Linus Torvalds's avatar
Linus Torvalds committed
1016
			 /* Clear PCI Interrupt Routing Control Register. */
Linus Torvalds's avatar
Linus Torvalds committed
1017 1018 1019
			short_reg = 0x0000;
			pci_write_config_word(dev, 0x44, short_reg);
			if (OpenPIC_Addr){
Linus Torvalds's avatar
Linus Torvalds committed
1020
				/* Route IDE interrupts to IRQ 14 */
Linus Torvalds's avatar
Linus Torvalds committed
1021
				reg = 0xEE;
Linus Torvalds's avatar
Linus Torvalds committed
1022
				pci_write_config_byte(dev, 0x43, reg);
Linus Torvalds's avatar
Linus Torvalds committed
1023 1024 1025
			}
		}
	}
Linus Torvalds's avatar
Linus Torvalds committed
1026

Linus Torvalds's avatar
Linus Torvalds committed
1027 1028 1029
	if ((dev = pci_find_device(PCI_VENDOR_ID_WINBOND,
				   PCI_DEVICE_ID_WINBOND_82C105, dev))){
		if (OpenPIC_Addr){
Linus Torvalds's avatar
Linus Torvalds committed
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
			/*
			 * Disable LEGIRQ mode so PCI INTS are routed
			 * directly to the 8259 and enable both channels
			 */
			pci_write_config_dword(dev, 0x40, 0x10ff0033);

			/* Force correct IDE interrupt */
			dev->irq = 14;
			pci_write_config_byte(dev,
					PCI_INTERRUPT_LINE,
					dev->irq);
Linus Torvalds's avatar
Linus Torvalds committed
1041
		} else {
Linus Torvalds's avatar
Linus Torvalds committed
1042 1043 1044 1045 1046 1047
			/* Enable LEGIRQ for PCI INT -> 8259 IRQ routing */
			pci_write_config_dword(dev, 0x40, 0x10ff08a1);
		}
	}
}

Linus Torvalds's avatar
Linus Torvalds committed
1048
static void __init
Linus Torvalds's avatar
Linus Torvalds committed
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
Powerplus_Map_Non0(struct pci_dev *dev)
{
	struct pci_bus  *pbus;          /* Parent bus structure pointer */
	struct pci_dev  *tdev = dev;    /* Temporary device structure */
	unsigned int    devnum;         /* Accumulated device number */
	unsigned char   intline;        /* Linux interrupt value */
	unsigned char   intpin;         /* PCI interrupt pin */

	/* Check for valid PCI dev pointer */
	if (dev == NULL) return;

	/* Initialize bridge IDSEL variable */
	devnum = PCI_SLOT(tdev->devfn);

	/* Read the interrupt pin of the device and adjust for indexing */
	pcibios_read_config_byte(dev->bus->number, dev->devfn,
			PCI_INTERRUPT_PIN, &intpin);

	/* If device doesn't request an interrupt, return */
	if ( (intpin < 1) || (intpin > 4) )
		return;

	intpin--;

	/*
	 * Walk up to bus 0, adjusting the interrupt pin for the standard
	 * PCI bus swizzle.
	 */
	do {
		intpin = (prep_pci_intpins[devnum % 4][intpin]) - 1;
		pbus = tdev->bus;        /* up one level */
		tdev = pbus->self;
		devnum = PCI_SLOT(tdev->devfn);
	} while(tdev->bus->number);

	/* Use the primary interrupt inputs by default */
	intline = mot_info[mot_entry].pci_irq_list->primary[intpin];

	/*
	 * If the board has secondary interrupt inputs, walk the bus and
	 * note the devfn of the bridge from bus 0.  If it is the same as
	 * the devfn of the bus bridge with secondary inputs, use those.
	 * Otherwise, assume it's a PMC site and get the interrupt line
	 * value from the interrupt routing table.
	 */ 
Linus Torvalds's avatar
Linus Torvalds committed
1094
	if (mot_info[mot_entry].secondary_bridge_devfn) {
Linus Torvalds's avatar
Linus Torvalds committed
1095 1096 1097 1098 1099
		pbus = dev->bus;

		while (pbus->primary != 0)
			pbus = pbus->parent;

Linus Torvalds's avatar
Linus Torvalds committed
1100
		if ((pbus->self)->devfn != 0xA0) {
Linus Torvalds's avatar
Linus Torvalds committed
1101 1102
			if ((pbus->self)->devfn == mot_info[mot_entry].secondary_bridge_devfn)
				intline = mot_info[mot_entry].pci_irq_list->secondary[intpin];
Linus Torvalds's avatar
Linus Torvalds committed
1103
			else {
Linus Torvalds's avatar
Linus Torvalds committed
1104 1105
				if ((char *)(mot_info[mot_entry].map) == (char *)Mesquite_pci_IRQ_map)
					intline = mot_info[mot_entry].map[((pbus->self)->devfn)/8] + 16;
Linus Torvalds's avatar
Linus Torvalds committed
1106
				else {
Linus Torvalds's avatar
Linus Torvalds committed
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
					int i;
					for (i=0;i<3;i++)
						intpin = (prep_pci_intpins[devnum % 4][intpin]) - 1;
					intline = mot_info[mot_entry].pci_irq_list->primary[intpin];
				}
			}
		}
	}

	/* Write calculated interrupt value to header and device list */
	dev->irq = intline;
	pci_write_config_byte(dev, PCI_INTERRUPT_LINE, (u8)dev->irq);
}

Linus Torvalds's avatar
Linus Torvalds committed
1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
void __init
prep_pcibios_fixup(void)
{
        struct pci_dev *dev;
        extern unsigned char *Motherboard_map;
        extern unsigned char *Motherboard_routes;
        unsigned char i;

	prep_route_pci_interrupts();

	printk("Setting PCI interrupts for a \"%s\"\n", Motherboard_map_name);
Linus Torvalds's avatar
Linus Torvalds committed
1132
	if (OpenPIC_Addr) {
Linus Torvalds's avatar
Linus Torvalds committed
1133 1134
		/* PCI interrupts are controlled by the OpenPIC */
		pci_for_each_dev(dev) {
Linus Torvalds's avatar
Linus Torvalds committed
1135
			if (dev->bus->number == 0) {
Linus Torvalds's avatar
Linus Torvalds committed
1136
                       		dev->irq = openpic_to_irq(Motherboard_map[PCI_SLOT(dev->devfn)]);
Linus Torvalds's avatar
Linus Torvalds committed
1137
				pcibios_write_config_byte(dev->bus->number, dev->devfn, PCI_INTERRUPT_LINE, dev->irq);
Linus Torvalds's avatar
Linus Torvalds committed
1138
			} else {
Linus Torvalds's avatar
Linus Torvalds committed
1139 1140
				if (Motherboard_non0 != NULL)
					Motherboard_non0(dev);
Linus Torvalds's avatar
Linus Torvalds committed
1141 1142
			}
		}
Linus Torvalds's avatar
Linus Torvalds committed
1143 1144 1145 1146

		/* Setup the Winbond or Via PIB */
		prep_pib_init();

Linus Torvalds's avatar
Linus Torvalds committed
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158
		return;
	}

	pci_for_each_dev(dev) {
		/*
		 * Use our old hard-coded kludge to figure out what
		 * irq this device uses.  This is necessary on things
		 * without residual data. -- Cort
		 */
		unsigned char d = PCI_SLOT(dev->devfn);
		dev->irq = Motherboard_routes[Motherboard_map[d]];

Linus Torvalds's avatar
Linus Torvalds committed
1159
		for ( i = 0 ; i <= 5 ; i++ ) {
Linus Torvalds's avatar
Linus Torvalds committed
1160 1161 1162 1163 1164
			/*
			 * Relocate PCI I/O resources if necessary so the
			 * standard 256MB BAT covers them.
			 */
			if ( (pci_resource_flags(dev, i) & IORESOURCE_IO) &&
Linus Torvalds's avatar
Linus Torvalds committed
1165 1166 1167 1168 1169 1170 1171 1172
				      (dev->resource[i].start > 0x10000000))  {
				printk("Relocating PCI address %lx -> %lx\n",
						dev->resource[i].start,
						(dev->resource[i].start & 
						 0x00FFFFFF)| 0x01000000);
				dev->resource[i].start =
					(dev->resource[i].start & 0x00FFFFFF)
					| 0x01000000;
Linus Torvalds's avatar
Linus Torvalds committed
1173
		                pci_write_config_dword(dev,
Linus Torvalds's avatar
Linus Torvalds committed
1174 1175 1176 1177 1178
						PCI_BASE_ADDRESS_0 + (i*0x4),
						dev->resource[i].start);
				dev->resource[i].end = 
					(dev->resource[i].end & 0x00FFFFFF)
					| 0x01000000;
Linus Torvalds's avatar
Linus Torvalds committed
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
		        }
		}
#if 0
		/*
		 * If we have residual data and if it knows about this
		 * device ask it what the irq is.
		 *  -- Cort
		 */
		ppcd = residual_find_device_id( ~0L, dev->device,
		                                -1,-1,-1, 0);
#endif
	}
}

1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
static void __init
prep_pcibios_after_init(void)
{
#if 0
	struct pci_dev *dev;
	
	/* If there is a WD 90C, reset the IO BAR to 0x0 (it started that 
	 * way, but the PCI layer relocated it because it thought 0x0 was
	 * invalid for a BAR).
	 * If you don't do this, the card's VGA base will be <IO BAR>+0xc0000
	 * instead of 0xc0000. vgacon.c (for example) is completely unaware of
	 * this little quirk.
	 */
	dev = pci_find_device(PCI_VENDOR_ID_WD, PCI_DEVICE_ID_WD_90C, NULL);
	if (dev) {
		dev->resource[1].end -= dev->resource[1].start;
		dev->resource[1].start = 0;
		/* tell the hardware */
		pci_write_config_dword(dev, PCI_BASE_ADDRESS_1, 0x0);
	}
#endif
}

Linus Torvalds's avatar
Linus Torvalds committed
1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228
static void __init
prep_init_resource(struct resource *res, unsigned long start,
		   unsigned long end, int flags)
{
	res->flags = flags;
	res->start = start;
	res->end = end;
	res->name = "PCI host bridge";
	res->parent = NULL;
	res->sibling = NULL;
	res->child = NULL;
}

Linus Torvalds's avatar
Linus Torvalds committed
1229
void __init
Linus Torvalds's avatar
Linus Torvalds committed
1230
prep_find_bridges(void)
Linus Torvalds's avatar
Linus Torvalds committed
1231
{
Linus Torvalds's avatar
Linus Torvalds committed
1232 1233 1234 1235 1236 1237 1238 1239 1240
	struct pci_controller* hose;

	hose = pcibios_alloc_controller();
	if (!hose)
		return;

	hose->first_busno = 0;
	hose->last_busno = 0xff;
	hose->pci_mem_offset = PREP_ISA_MEM_BASE;
Linus Torvalds's avatar
Linus Torvalds committed
1241 1242
	hose->io_base_phys = PREP_ISA_IO_BASE;
	hose->io_base_virt = (void *)0x80000000; /* see prep_map_io() */
1243
	prep_init_resource(&hose->io_resource, 0, 0x00ffffff, IORESOURCE_IO);
Linus Torvalds's avatar
Linus Torvalds committed
1244 1245
	prep_init_resource(&hose->mem_resources[0], 0xc0000000, 0xfeffffff,
			   IORESOURCE_MEM);
1246 1247
	hose->ops = &prep_pci_ops;

Linus Torvalds's avatar
Linus Torvalds committed
1248 1249
	printk("PReP architecture\n");
#ifdef CONFIG_PREP_RESIDUAL	  
1250
	{
Linus Torvalds's avatar
Linus Torvalds committed
1251 1252 1253 1254 1255 1256 1257 1258
		PPC_DEVICE *hostbridge;

		hostbridge = residual_find_device(PROCESSORDEVICE, NULL,
			BridgeController, PCIBridge, -1, 0);
		if (hostbridge &&
			hostbridge->DeviceId.Interface == PCIBridgeIndirect) {
			PnP_TAG_PACKET * pkt;
			pkt = PnP_find_large_vendor_packet(
Linus Torvalds's avatar
Linus Torvalds committed
1259 1260
				res->DevicePnPHeap+hostbridge->AllocatedOffset,
				3, 0);
Linus Torvalds's avatar
Linus Torvalds committed
1261
			if(pkt) {
Linus Torvalds's avatar
Linus Torvalds committed
1262
#define p pkt->L4_Pack.L4_Data.L4_PPCPack
Linus Torvalds's avatar
Linus Torvalds committed
1263 1264 1265
				setup_indirect_pci(hose, 
					ld_le32((unsigned *) (p.PPCData)),
					ld_le32((unsigned *) (p.PPCData+8)));
1266
#undef p
Linus Torvalds's avatar
Linus Torvalds committed
1267
			} else
Linus Torvalds's avatar
Linus Torvalds committed
1268
				setup_indirect_pci(hose, 0x80000cf8, 0x80000cfc);
1269
		}
Linus Torvalds's avatar
Linus Torvalds committed
1270
	}
1271
#endif /* CONFIG_PREP_RESIDUAL */
Linus Torvalds's avatar
Linus Torvalds committed
1272 1273

	ppc_md.pcibios_fixup = prep_pcibios_fixup;
1274
	ppc_md.pcibios_after_init = prep_pcibios_after_init;
Linus Torvalds's avatar
Linus Torvalds committed
1275
}