4xx_pci.c 21.6 KB
Newer Older
wdenk's avatar
wdenk committed
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
/*-----------------------------------------------------------------------------+
 *
 *       This source code has been made available to you by IBM on an AS-IS
 *       basis.  Anyone receiving this source is licensed under IBM
 *       copyrights to use it in any way he or she deems fit, including
 *       copying it, modifying it, compiling it, and redistributing it either
 *       with or without modifications.  No license under IBM patents or
 *       patent applications is to be implied by the copyright license.
 *
 *       Any user of this software should understand that IBM cannot provide
 *       technical support for this software and will not be responsible for
 *       any consequences resulting from the use of this software.
 *
 *       Any person who transfers this source code or any derivative work
 *       must include the IBM copyright notice, this paragraph, and the
 *       preceding two paragraphs in the transferred software.
 *
 *       COPYRIGHT   I B M   CORPORATION 1995
 *       LICENSED MATERIAL  -  PROGRAM PROPERTY OF I B M
 *-----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------+
 *
 *  File Name:   405gp_pci.c
 *
 *  Function:    Initialization code for the 405GP PCI Configuration regs.
 *
 *  Author:      Mark Game
 *
 *  Change Activity-
 *
 *  Date        Description of Change                                       BY
 *  ---------   ---------------------                                       ---
 *  09-Sep-98   Created                                                     MCG
 *  02-Nov-98   Removed External arbiter selected message                   JWB
 *  27-Nov-98   Zero out PTMBAR2 and disable in PTM2MS                      JWB
 *  04-Jan-99   Zero out other unused PMM and PTM regs. Change bus scan     MCG
 *              from (0 to n) to (1 to n).
 *  17-May-99   Port to Walnut                                              JWB
 *  17-Jun-99   Updated for VGA support                                     JWB
 *  21-Jun-99   Updated to allow SRAM region to be a target from PCI bus    JWB
 *  19-Jul-99   Updated for 405GP pass 1 errata #26 (Low PCI subsequent     MCG
 *              target latency timer values are not supported).
 *              Should be fixed in pass 2.
 *  09-Sep-99   Removed use of PTM2 since the SRAM region no longer needs   JWB
 *              to be a PCI target. Zero out PTMBAR2 and disable in PTM2MS.
 *  10-Dec-99   Updated PCI_Write_CFG_Reg for pass2 errata #6               JWB
 *  11-Jan-00   Ensure PMMxMAs disabled before setting PMMxLAs. This is not
 *              really required after a reset since PMMxMAs are already
Wolfgang Denk's avatar
Wolfgang Denk committed
49
 *	        disabled but is a good practice nonetheless.                JWB
wdenk's avatar
wdenk committed
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
 *  12-Jun-01   stefan.roese@esd-electronics.com
 *              - PCI host/adapter handling reworked
 *  09-Jul-01   stefan.roese@esd-electronics.com
 *              - PCI host now configures from device 0 (not 1) to max_dev,
 *                (host configures itself)
 *              - On CPCI-405 pci base address and size is generated from
 *                SDRAM and FLASH size (CFG regs not used anymore)
 *              - Some minor changes for CPCI-405-A (adapter version)
 *  14-Sep-01   stefan.roese@esd-electronics.com
 *              - CONFIG_PCI_SCAN_SHOW added to print pci devices upon startup
 *  28-Sep-01   stefan.roese@esd-electronics.com
 *              - Changed pci master configuration for linux compatibility
 *                (no need for bios_fixup() anymore)
 *  26-Feb-02   stefan.roese@esd-electronics.com
 *              - Bug fixed in pci configuration (Andrew May)
 *              - Removed pci class code init for CPCI405 board
 *  15-May-02   stefan.roese@esd-electronics.com
 *              - New vga device handling
 *  29-May-02   stefan.roese@esd-electronics.com
 *              - PCI class code init added (if defined)
 *----------------------------------------------------------------------------*/

#include <common.h>
#include <command.h>
#if !defined(CONFIG_440)
75
#include <asm/4xx_pci.h>
wdenk's avatar
wdenk committed
76 77 78 79
#endif
#include <asm/processor.h>
#include <pci.h>

80 81
#ifdef CONFIG_PCI

82 83
DECLARE_GLOBAL_DATA_PTR;

84 85 86 87 88 89
/*
 * Board-specific pci initialization
 * Platform code can reimplement pci_pre_init() if needed
 */
int __pci_pre_init(struct pci_controller *hose)
{
90 91 92 93 94 95 96 97 98 99 100 101 102 103
#if defined (CONFIG_405EP)
	/*
	 * Enable the internal PCI arbiter by default.
	 *
	 * On 405EP CPUs the internal arbiter can be controlled
	 * by the I2C strapping EEPROM. If you want to do so
	 * or if you want to disable the arbiter pci_pre_init()
	 * must be reimplemented without enabling the arbiter.
	 * The arbiter is enabled in this place because of
	 * compatibility reasons.
	 */
	mtdcr(cpc0_pci, mfdcr(cpc0_pci) | CPC0_PCI_ARBIT_EN);
#endif /* CONFIG_405EP */

104 105 106
	return 1;
}
int pci_pre_init(struct pci_controller *hose) __attribute__((weak, alias("__pci_pre_init")));
wdenk's avatar
wdenk committed
107

108
#if defined(CONFIG_405GP) || defined(CONFIG_405EP)
wdenk's avatar
wdenk committed
109

110 111 112 113
#if defined(CONFIG_PMC405)
ushort pmc405_pci_subsys_deviceid(void);
#endif

wdenk's avatar
wdenk committed
114 115
/*#define DEBUG*/

116 117 118 119 120 121 122 123 124 125 126 127 128
int __is_pci_host(struct pci_controller *hose)
{
#if defined(CONFIG_405GP)
	if (mfdcr(strap) & PSR_PCI_ARBIT_EN)
		return 1;
#elif defined (CONFIG_405EP)
	if (mfdcr(cpc0_pci) & CPC0_PCI_ARBIT_EN)
		return 1;
#endif
	return 0;
}
int is_pci_host(struct pci_controller *hose) __attribute__((weak, alias("__is_pci_host")));

wdenk's avatar
wdenk committed
129 130 131 132 133 134 135 136 137
/*-----------------------------------------------------------------------------+
 * pci_init.  Initializes the 405GP PCI Configuration regs.
 *-----------------------------------------------------------------------------*/
void pci_405gp_init(struct pci_controller *hose)
{
	int i, reg_num = 0;
	bd_t *bd = gd->bd;

	unsigned short temp_short;
138
	unsigned long ptmpcila[2] = {CONFIG_SYS_PCI_PTM1PCI, CONFIG_SYS_PCI_PTM2PCI};
stroese's avatar
stroese committed
139
#if defined(CONFIG_CPCI405) || defined(CONFIG_PMC405)
140
	char *ptmla_str, *ptmms_str;
141
#endif
142 143
	unsigned long ptmla[2]    = {CONFIG_SYS_PCI_PTM1LA, CONFIG_SYS_PCI_PTM2LA};
	unsigned long ptmms[2]    = {CONFIG_SYS_PCI_PTM1MS, CONFIG_SYS_PCI_PTM2MS};
wdenk's avatar
wdenk committed
144 145 146 147 148 149 150 151 152 153
#if defined(CONFIG_PIP405) || defined (CONFIG_MIP405)
	unsigned long pmmla[3]    = {0x80000000, 0xA0000000, 0};
	unsigned long pmmma[3]    = {0xE0000001, 0xE0000001, 0};
	unsigned long pmmpcila[3] = {0x80000000, 0x00000000, 0};
	unsigned long pmmpciha[3] = {0x00000000, 0x00000000, 0};
#else
	unsigned long pmmla[3]    = {0x80000000, 0,0};
	unsigned long pmmma[3]    = {0xC0000001, 0,0};
	unsigned long pmmpcila[3] = {0x80000000, 0,0};
	unsigned long pmmpciha[3] = {0x00000000, 0,0};
stroese's avatar
stroese committed
154 155 156 157 158
#endif
#ifdef CONFIG_PCI_PNP
#if (CONFIG_PCI_HOST == PCI_HOST_AUTO)
	char *s;
#endif
wdenk's avatar
wdenk committed
159 160
#endif

161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
#if defined(CONFIG_CPCI405) || defined(CONFIG_PMC405)
	ptmla_str = getenv("ptm1la");
	ptmms_str = getenv("ptm1ms");
	if(NULL != ptmla_str && NULL != ptmms_str ) {
	        ptmla[0] = simple_strtoul (ptmla_str, NULL, 16);
		ptmms[0] = simple_strtoul (ptmms_str, NULL, 16);
	}

	ptmla_str = getenv("ptm2la");
	ptmms_str = getenv("ptm2ms");
	if(NULL != ptmla_str && NULL != ptmms_str ) {
	        ptmla[1] = simple_strtoul (ptmla_str, NULL, 16);
		ptmms[1] = simple_strtoul (ptmms_str, NULL, 16);
	}
#endif

wdenk's avatar
wdenk committed
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
	/*
	 * Register the hose
	 */
	hose->first_busno = 0;
	hose->last_busno = 0xff;

	/* ISA/PCI I/O space */
	pci_set_region(hose->regions + reg_num++,
		       MIN_PCI_PCI_IOADDR,
		       MIN_PLB_PCI_IOADDR,
		       0x10000,
		       PCI_REGION_IO);

	/* PCI I/O space */
	pci_set_region(hose->regions + reg_num++,
		       0x00800000,
		       0xe8800000,
		       0x03800000,
		       PCI_REGION_IO);

	reg_num = 2;

	/* Memory spaces */
	for (i=0; i<2; i++)
		if (ptmms[i] & 1)
		{
			if (!i) hose->pci_fb = hose->regions + reg_num;

			pci_set_region(hose->regions + reg_num++,
				       ptmpcila[i], ptmla[i],
				       ~(ptmms[i] & 0xfffff000) + 1,
				       PCI_REGION_MEM |
209
				       PCI_REGION_SYS_MEMORY);
wdenk's avatar
wdenk committed
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
		}

	/* PCI memory spaces */
	for (i=0; i<3; i++)
		if (pmmma[i] & 1)
		{
			pci_set_region(hose->regions + reg_num++,
				       pmmpcila[i], pmmla[i],
				       ~(pmmma[i] & 0xfffff000) + 1,
				       PCI_REGION_MEM);
		}

	hose->region_count = reg_num;

	pci_setup_indirect(hose,
			   PCICFGADR,
			   PCICFGDATA);

	if (hose->pci_fb)
		pciauto_region_init(hose->pci_fb);

231 232 233 234 235 236 237
	/* Let board change/modify hose & do initial checks */
	if (pci_pre_init (hose) == 0) {
		printf("PCI: Board-specific initialization failed.\n");
		printf("PCI: Configuration aborted.\n");
		return;
	}

wdenk's avatar
wdenk committed
238 239 240 241 242 243 244 245
	pci_register_hose(hose);

	/*--------------------------------------------------------------------------+
	 * 405GP PCI Master configuration.
	 * Map one 512 MB range of PLB/processor addresses to PCI memory space.
	 * PLB address 0x80000000-0xBFFFFFFF ==> PCI address 0x80000000-0xBFFFFFFF
	 * Use byte reversed out routines to handle endianess.
	 *--------------------------------------------------------------------------*/
wdenk's avatar
wdenk committed
246
	out32r(PMM0MA,    (pmmma[0]&~0x1)); /* disable, configure PMMxLA, PMMxPCILA first */
wdenk's avatar
wdenk committed
247 248 249 250 251 252 253 254
	out32r(PMM0LA,    pmmla[0]);
	out32r(PMM0PCILA, pmmpcila[0]);
	out32r(PMM0PCIHA, pmmpciha[0]);
	out32r(PMM0MA,    pmmma[0]);

	/*--------------------------------------------------------------------------+
	 * PMM1 is not used.  Initialize them to zero.
	 *--------------------------------------------------------------------------*/
wdenk's avatar
wdenk committed
255
	out32r(PMM1MA,    (pmmma[1]&~0x1));
wdenk's avatar
wdenk committed
256 257 258 259 260 261 262 263
	out32r(PMM1LA,    pmmla[1]);
	out32r(PMM1PCILA, pmmpcila[1]);
	out32r(PMM1PCIHA, pmmpciha[1]);
	out32r(PMM1MA,    pmmma[1]);

	/*--------------------------------------------------------------------------+
	 * PMM2 is not used.  Initialize them to zero.
	 *--------------------------------------------------------------------------*/
wdenk's avatar
wdenk committed
264
	out32r(PMM2MA,    (pmmma[2]&~0x1));
wdenk's avatar
wdenk committed
265 266 267 268 269 270 271 272 273 274 275
	out32r(PMM2LA,    pmmla[2]);
	out32r(PMM2PCILA, pmmpcila[2]);
	out32r(PMM2PCIHA, pmmpciha[2]);
	out32r(PMM2MA,    pmmma[2]);

	/*--------------------------------------------------------------------------+
	 * 405GP PCI Target configuration.  (PTM1)
	 * Note: PTM1MS is hardwire enabled but we set the enable bit anyway.
	 *--------------------------------------------------------------------------*/
	out32r(PTM1LA,    ptmla[0]);         /* insert address                     */
	out32r(PTM1MS,    ptmms[0]);         /* insert size, enable bit is 1       */
wdenk's avatar
wdenk committed
276
	pci_write_config_dword(PCIDEVID_405GP, PCI_BASE_ADDRESS_1, ptmpcila[0]);
wdenk's avatar
wdenk committed
277 278 279 280 281

	/*--------------------------------------------------------------------------+
	 * 405GP PCI Target configuration.  (PTM2)
	 *--------------------------------------------------------------------------*/
	out32r(PTM2LA, ptmla[1]);            /* insert address                     */
wdenk's avatar
wdenk committed
282 283
	pci_write_config_dword(PCIDEVID_405GP, PCI_BASE_ADDRESS_2, ptmpcila[1]);

wdenk's avatar
wdenk committed
284 285 286 287 288 289 290 291 292 293 294 295 296 297
	if (ptmms[1] == 0)
	{
		out32r(PTM2MS,    0x00000001);   /* set enable bit                     */
		pci_write_config_dword(PCIDEVID_405GP, PCI_BASE_ADDRESS_2, 0x00000000);
		out32r(PTM2MS,    0x00000000);   /* disable                            */
	}
	else
	{
		out32r(PTM2MS, ptmms[1]);        /* insert size, enable bit is 1       */
	}

	/*
	 * Insert Subsystem Vendor and Device ID
	 */
298
	pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_VENDOR_ID, CONFIG_SYS_PCI_SUBSYS_VENDORID);
wdenk's avatar
wdenk committed
299
#ifdef CONFIG_CPCI405
300
	if (is_pci_host(hose))
301
		pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_DEVICEID);
wdenk's avatar
wdenk committed
302
	else
303
		pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_DEVICEID2);
wdenk's avatar
wdenk committed
304
#else
305
	pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_DEVICEID);
wdenk's avatar
wdenk committed
306 307 308 309 310
#endif

	/*
	 * Insert Class-code
	 */
311 312 313
#ifdef CONFIG_SYS_PCI_CLASSCODE
	pci_write_config_word(PCIDEVID_405GP, PCI_CLASS_SUB_CODE, CONFIG_SYS_PCI_CLASSCODE);
#endif /* CONFIG_SYS_PCI_CLASSCODE */
wdenk's avatar
wdenk committed
314 315

	/*--------------------------------------------------------------------------+
Wolfgang Denk's avatar
Wolfgang Denk committed
316
	 * If PCI speed = 66MHz, set 66MHz capable bit.
wdenk's avatar
wdenk committed
317 318 319 320 321 322 323
	 *--------------------------------------------------------------------------*/
	if (bd->bi_pci_busfreq >= 66000000) {
		pci_read_config_word(PCIDEVID_405GP, PCI_STATUS, &temp_short);
		pci_write_config_word(PCIDEVID_405GP,PCI_STATUS,(temp_short|PCI_STATUS_66MHZ));
	}

#if (CONFIG_PCI_HOST != PCI_HOST_ADAPTER)
wdenk's avatar
wdenk committed
324
#if (CONFIG_PCI_HOST == PCI_HOST_AUTO)
325
	if (is_pci_host(hose) ||
stroese's avatar
stroese committed
326
	    (((s = getenv("pciscan")) != NULL) && (strcmp(s, "yes") == 0)))
wdenk's avatar
wdenk committed
327 328 329 330 331 332 333 334 335 336 337 338 339
#endif
	{
		/*--------------------------------------------------------------------------+
		 * Write the 405GP PCI Configuration regs.
		 * Enable 405GP to be a master on the PCI bus (PMM).
		 * Enable 405GP to act as a PCI memory target (PTM).
		 *--------------------------------------------------------------------------*/
		pci_read_config_word(PCIDEVID_405GP, PCI_COMMAND, &temp_short);
		pci_write_config_word(PCIDEVID_405GP, PCI_COMMAND, temp_short |
				      PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
	}
#endif

340 341 342 343 344 345 346 347 348
#if defined(CONFIG_405EP)
	/*
	 * on ppc405ep vendor/device id is not set
	 * The user manual says 0x1014 (IBM) / 0x0156 (405GP!)
	 * are the correct values.
	 */
	pci_write_config_word(PCIDEVID_405GP, PCI_VENDOR_ID, PCI_VENDOR_ID_IBM);
	pci_write_config_word(PCIDEVID_405GP,
			      PCI_DEVICE_ID, PCI_DEVICE_ID_IBM_405GP);
stroese's avatar
stroese committed
349 350
#endif

wdenk's avatar
wdenk committed
351 352 353 354 355 356 357 358 359 360 361
	/*
	 * Set HCE bit (Host Configuration Enabled)
	 */
	pci_read_config_word(PCIDEVID_405GP, PCIBRDGOPT2, &temp_short);
	pci_write_config_word(PCIDEVID_405GP, PCIBRDGOPT2, (temp_short | 0x0001));

#ifdef CONFIG_PCI_PNP
	/*--------------------------------------------------------------------------+
	 * Scan the PCI bus and configure devices found.
	 *--------------------------------------------------------------------------*/
#if (CONFIG_PCI_HOST == PCI_HOST_AUTO)
362
	if (is_pci_host(hose) ||
stroese's avatar
stroese committed
363
	    (((s = getenv("pciscan")) != NULL) && (strcmp(s, "yes") == 0)))
wdenk's avatar
wdenk committed
364 365 366 367 368 369 370 371 372 373 374 375
#endif
	{
#ifdef CONFIG_PCI_SCAN_SHOW
		printf("PCI:   Bus Dev VenId DevId Class Int\n");
#endif
		hose->last_busno = pci_hose_scan(hose);
	}
#endif  /* CONFIG_PCI_PNP */

}

/*
376
 * drivers/pci/pci.c skips every host bridge but the 405GP since it could
wdenk's avatar
wdenk committed
377 378 379 380 381 382 383 384 385 386
 * be set as an Adapter.
 *
 * I (Andrew May) don't know what we should do here, but I don't want
 * the auto setup of a PCI device disabling what is done pci_405gp_init
 * as has happened before.
 */
void pci_405gp_setup_bridge(struct pci_controller *hose, pci_dev_t dev,
			    struct pci_config_table *entry)
{
#ifdef DEBUG
wdenk's avatar
wdenk committed
387
	printf("405gp_setup_bridge\n");
wdenk's avatar
wdenk committed
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
#endif
}

/*
 *
 */

void pci_405gp_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
{
	unsigned char int_line = 0xff;

	/*
	 * Write pci interrupt line register (cpci405 specific)
	 */
	switch (PCI_DEV(dev) & 0x03)
	{
	case 0:
		int_line = 27 + 2;
		break;
	case 1:
		int_line = 27 + 3;
		break;
	case 2:
		int_line = 27 + 0;
		break;
	case 3:
		int_line = 27 + 1;
		break;
	}

	pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line);
}

void pci_405gp_setup_vga(struct pci_controller *hose, pci_dev_t dev,
			 struct pci_config_table *entry)
{
	unsigned int cmdstat = 0;

426
	pciauto_setup_device(hose, dev, 6, hose->pci_mem, hose->pci_prefetch, hose->pci_io);
wdenk's avatar
wdenk committed
427 428 429 430 431 432 433

	/* always enable io space on vga boards */
	pci_hose_read_config_dword(hose, dev, PCI_COMMAND, &cmdstat);
	cmdstat |= PCI_COMMAND_IO;
	pci_hose_write_config_dword(hose, dev, PCI_COMMAND, cmdstat);
}

434
#if !(defined(CONFIG_PIP405) || defined (CONFIG_MIP405)) && !(defined (CONFIG_SC3))
wdenk's avatar
wdenk committed
435 436 437 438 439 440 441

/*
 *As is these functs get called out of flash Not a horrible
 *thing, but something to keep in mind. (no statics?)
 */
static struct pci_config_table pci_405gp_config_table[] = {
/*if VendID is 0 it terminates the table search (ie Walnut)*/
442 443
#ifdef CONFIG_SYS_PCI_SUBSYS_VENDORID
	{CONFIG_SYS_PCI_SUBSYS_VENDORID, PCI_ANY_ID, PCI_CLASS_BRIDGE_HOST,
wdenk's avatar
wdenk committed
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
	 PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, pci_405gp_setup_bridge},
#endif
	{PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA,
	 PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, pci_405gp_setup_vga},

	{PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NOT_DEFINED_VGA,
	 PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, pci_405gp_setup_vga},

	{ }
};

static struct pci_controller hose = {
	fixup_irq: pci_405gp_fixup_irq,
	config_table: pci_405gp_config_table,
};

460
void pci_init_board(void)
wdenk's avatar
wdenk committed
461 462 463 464 465 466 467 468 469 470 471 472 473 474
{
	/*we want the ptrs to RAM not flash (ie don't use init list)*/
	hose.fixup_irq    = pci_405gp_fixup_irq;
	hose.config_table = pci_405gp_config_table;
	pci_405gp_init(&hose);
}

#endif

#endif /* CONFIG_405GP */

/*-----------------------------------------------------------------------------+
 * CONFIG_440
 *-----------------------------------------------------------------------------*/
475
#if defined(CONFIG_440)
wdenk's avatar
wdenk committed
476 477 478 479

static struct pci_controller ppc440_hose = {0};


480
int pci_440_init (struct pci_controller *hose)
wdenk's avatar
wdenk committed
481 482 483
{
	int reg_num = 0;

484
#ifndef CONFIG_DISABLE_PISE_TEST
wdenk's avatar
wdenk committed
485 486
	/*--------------------------------------------------------------------------+
	 * The PCI initialization sequence enable bit must be set ... if not abort
wdenk's avatar
wdenk committed
487
	 * pci setup since updating the bit requires chip reset.
wdenk's avatar
wdenk committed
488
	 *--------------------------------------------------------------------------*/
489
#if defined(CONFIG_440GX) || defined(CONFIG_440SP) || defined(CONFIG_440SPE)
490 491
	unsigned long strap;

wdenk's avatar
wdenk committed
492
	mfsdr(sdr_sdstp1,strap);
493
	if ((strap & SDR0_SDSTP1_PISE_MASK) == 0) {
wdenk's avatar
wdenk committed
494 495
		printf("PCI: SDR0_STRP1[PISE] not set.\n");
		printf("PCI: Configuration aborted.\n");
496
		return -1;
wdenk's avatar
wdenk committed
497
	}
498 499 500
#elif defined(CONFIG_440GP)
	unsigned long strap;

wdenk's avatar
wdenk committed
501
	strap = mfdcr(cpc0_strp1);
502
	if ((strap & CPC0_STRP1_PISE_MASK) == 0) {
wdenk's avatar
wdenk committed
503 504
		printf("PCI: CPC0_STRP1[PISE] not set.\n");
		printf("PCI: Configuration aborted.\n");
505
		return -1;
wdenk's avatar
wdenk committed
506 507
	}
#endif
508 509
#endif /* CONFIG_DISABLE_PISE_TEST */

wdenk's avatar
wdenk committed
510 511 512 513
	/*--------------------------------------------------------------------------+
	 * PCI controller init
	 *--------------------------------------------------------------------------*/
	hose->first_busno = 0;
514
	hose->last_busno = 0;
wdenk's avatar
wdenk committed
515

516
	/* PCI I/O space */
wdenk's avatar
wdenk committed
517 518
	pci_set_region(hose->regions + reg_num++,
		       0x00000000,
519 520 521
		       PCIX0_IOBASE,
		       0x10000,
		       PCI_REGION_IO);
wdenk's avatar
wdenk committed
522

523
	/* PCI memory space */
wdenk's avatar
wdenk committed
524
	pci_set_region(hose->regions + reg_num++,
525 526 527 528
		       CONFIG_SYS_PCI_TARGBASE,
		       CONFIG_SYS_PCI_MEMBASE,
#ifdef CONFIG_SYS_PCI_MEMSIZE
		       CONFIG_SYS_PCI_MEMSIZE,
529
#else
530
		       0x10000000,
531
#endif
532
		       PCI_REGION_MEM );
533 534 535 536 537 538 539 540

#if defined(CONFIG_PCI_SYS_MEM_BUS) && defined(CONFIG_PCI_SYS_MEM_PHYS) && \
	defined(CONFIG_PCI_SYS_MEM_SIZE)
	/* System memory space */
	pci_set_region(hose->regions + reg_num++,
		       CONFIG_PCI_SYS_MEM_BUS,
		       CONFIG_PCI_SYS_MEM_PHYS,
		       CONFIG_PCI_SYS_MEM_SIZE,
541
		       PCI_REGION_MEM | PCI_REGION_SYS_MEMORY );
542 543
#endif

wdenk's avatar
wdenk committed
544 545 546 547
	hose->region_count = reg_num;

	pci_setup_indirect(hose, PCIX0_CFGADR, PCIX0_CFGDATA);

548 549 550 551
	/* Let board change/modify hose & do initial checks */
	if (pci_pre_init (hose) == 0) {
		printf("PCI: Board-specific initialization failed.\n");
		printf("PCI: Configuration aborted.\n");
552
		return -1;
553
	}
wdenk's avatar
wdenk committed
554 555 556 557 558 559

	pci_register_hose( hose );

	/*--------------------------------------------------------------------------+
	 * PCI target init
	 *--------------------------------------------------------------------------*/
560
#if defined(CONFIG_SYS_PCI_TARGET_INIT)
wdenk's avatar
wdenk committed
561 562
	pci_target_init(hose);                /* Let board setup pci target */
#else
563 564
	out16r( PCIX0_SBSYSVID, CONFIG_SYS_PCI_SUBSYS_VENDORID );
	out16r( PCIX0_SBSYSID, CONFIG_SYS_PCI_SUBSYS_ID );
565
	out16r( PCIX0_CLS, 0x00060000 ); /* Bridge, host bridge */
wdenk's avatar
wdenk committed
566 567
#endif

568 569
#if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
    defined(CONFIG_460EX) || defined(CONFIG_460GT)
wdenk's avatar
wdenk committed
570 571
	out32r( PCIX0_BRDGOPT1, 0x04000060 );               /* PLB Rq pri highest   */
	out32r( PCIX0_BRDGOPT2, in32(PCIX0_BRDGOPT2) | 0x83 ); /* Enable host config, clear Timeout, ensure int src1  */
572
#elif defined(PCIX0_BRDGOPT1)
wdenk's avatar
wdenk committed
573 574 575
	out32r( PCIX0_BRDGOPT1, 0x10000060 );               /* PLB Rq pri highest   */
	out32r( PCIX0_BRDGOPT2, in32(PCIX0_BRDGOPT2) | 1 ); /* Enable host config   */
#endif
wdenk's avatar
wdenk committed
576 577 578

	/*--------------------------------------------------------------------------+
	 * PCI master init: default is one 256MB region for PCI memory:
579
	 * 0x3_00000000 - 0x3_0FFFFFFF  ==> CONFIG_SYS_PCI_MEMBASE
wdenk's avatar
wdenk committed
580
	 *--------------------------------------------------------------------------*/
581
#if defined(CONFIG_SYS_PCI_MASTER_INIT)
wdenk's avatar
wdenk committed
582 583 584 585 586
	pci_master_init(hose);          /* Let board setup pci master */
#else
	out32r( PCIX0_POM0SA, 0 ); /* disable */
	out32r( PCIX0_POM1SA, 0 ); /* disable */
	out32r( PCIX0_POM2SA, 0 ); /* disable */
587
#if defined(CONFIG_440SPE)
588 589
	out32r( PCIX0_POM0LAL, 0x10000000 );
	out32r( PCIX0_POM0LAH, 0x0000000c );
590 591 592
#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
	out32r( PCIX0_POM0LAL, 0x20000000 );
	out32r( PCIX0_POM0LAH, 0x0000000c );
593
#else
wdenk's avatar
wdenk committed
594 595
	out32r( PCIX0_POM0LAL, 0x00000000 );
	out32r( PCIX0_POM0LAH, 0x00000003 );
596
#endif
597
	out32r( PCIX0_POM0PCIAL, CONFIG_SYS_PCI_MEMBASE );
wdenk's avatar
wdenk committed
598 599
	out32r( PCIX0_POM0PCIAH, 0x00000000 );
	out32r( PCIX0_POM0SA, 0xf0000001 ); /* 256MB, enabled */
600
	out32r( PCIX0_STS, in32r( PCIX0_STS ) & ~0x0000fff8 );
wdenk's avatar
wdenk committed
601 602 603 604
#endif

	/*--------------------------------------------------------------------------+
	 * PCI host configuration -- we don't make any assumptions here ... the
605 606 607
	 * _board_must_indicate_ what to do -- there's just too many runtime
	 * scenarios in environments like cPCI, PPMC, etc. to make a determination
	 * based on hard-coded values or state of arbiter enable.
wdenk's avatar
wdenk committed
608
	 *--------------------------------------------------------------------------*/
609
	if (is_pci_host(hose)) {
wdenk's avatar
wdenk committed
610
#ifdef CONFIG_PCI_SCAN_SHOW
611
		printf("PCI:   Bus Dev VenId DevId Class Int\n");
wdenk's avatar
wdenk committed
612
#endif
613 614
#if !defined(CONFIG_440EP) && !defined(CONFIG_440GR) && \
    !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX)
615
		out16r( PCIX0_CMD, in16r( PCIX0_CMD ) | PCI_COMMAND_MASTER);
616
#endif
617 618
		hose->last_busno = pci_hose_scan(hose);
	}
619
	return hose->last_busno;
wdenk's avatar
wdenk committed
620 621
}

622
void pci_init_board(void)
wdenk's avatar
wdenk committed
623
{
624 625 626
	int busno;

	busno = pci_440_init (&ppc440_hose);
627 628 629
#if (defined(CONFIG_440SPE) || \
    defined(CONFIG_460EX) || defined(CONFIG_460GT)) && \
    !defined(CONFIG_PCI_DISABLE_PCIE)
630
	pcie_setup_hoses(busno + 1);
631
#endif
wdenk's avatar
wdenk committed
632 633
}

634
#endif /* CONFIG_440 */
635 636 637 638 639 640 641 642 643 644 645

#if defined(CONFIG_405EX)
void pci_init_board(void)
{
#ifdef CONFIG_PCI_SCAN_SHOW
	printf("PCI:   Bus Dev VenId DevId Class Int\n");
#endif
	pcie_setup_hoses(0);
}
#endif /* CONFIG_405EX */

646
#endif /* CONFIG_PCI */