4xx_pci.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /*-----------------------------------------------------------------------------+
  2. *
  3. * This source code has been made available to you by IBM on an AS-IS
  4. * basis. Anyone receiving this source is licensed under IBM
  5. * copyrights to use it in any way he or she deems fit, including
  6. * copying it, modifying it, compiling it, and redistributing it either
  7. * with or without modifications. No license under IBM patents or
  8. * patent applications is to be implied by the copyright license.
  9. *
  10. * Any user of this software should understand that IBM cannot provide
  11. * technical support for this software and will not be responsible for
  12. * any consequences resulting from the use of this software.
  13. *
  14. * Any person who transfers this source code or any derivative work
  15. * must include the IBM copyright notice, this paragraph, and the
  16. * preceding two paragraphs in the transferred software.
  17. *
  18. * COPYRIGHT I B M CORPORATION 1995
  19. * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
  20. *-----------------------------------------------------------------------------*/
  21. /*----------------------------------------------------------------------------+
  22. *
  23. * File Name: 405gp_pci.c
  24. *
  25. * Function: Initialization code for the 405GP PCI Configuration regs.
  26. *
  27. * Author: Mark Game
  28. *
  29. * Change Activity-
  30. *
  31. * Date Description of Change BY
  32. * --------- --------------------- ---
  33. * 09-Sep-98 Created MCG
  34. * 02-Nov-98 Removed External arbiter selected message JWB
  35. * 27-Nov-98 Zero out PTMBAR2 and disable in PTM2MS JWB
  36. * 04-Jan-99 Zero out other unused PMM and PTM regs. Change bus scan MCG
  37. * from (0 to n) to (1 to n).
  38. * 17-May-99 Port to Walnut JWB
  39. * 17-Jun-99 Updated for VGA support JWB
  40. * 21-Jun-99 Updated to allow SRAM region to be a target from PCI bus JWB
  41. * 19-Jul-99 Updated for 405GP pass 1 errata #26 (Low PCI subsequent MCG
  42. * target latency timer values are not supported).
  43. * Should be fixed in pass 2.
  44. * 09-Sep-99 Removed use of PTM2 since the SRAM region no longer needs JWB
  45. * to be a PCI target. Zero out PTMBAR2 and disable in PTM2MS.
  46. * 10-Dec-99 Updated PCI_Write_CFG_Reg for pass2 errata #6 JWB
  47. * 11-Jan-00 Ensure PMMxMAs disabled before setting PMMxLAs. This is not
  48. * really required after a reset since PMMxMAs are already
  49. * disabled but is a good practice nonetheless. JWB
  50. * 12-Jun-01 stefan.roese@esd-electronics.com
  51. * - PCI host/adapter handling reworked
  52. * 09-Jul-01 stefan.roese@esd-electronics.com
  53. * - PCI host now configures from device 0 (not 1) to max_dev,
  54. * (host configures itself)
  55. * - On CPCI-405 pci base address and size is generated from
  56. * SDRAM and FLASH size (CFG regs not used anymore)
  57. * - Some minor changes for CPCI-405-A (adapter version)
  58. * 14-Sep-01 stefan.roese@esd-electronics.com
  59. * - CONFIG_PCI_SCAN_SHOW added to print pci devices upon startup
  60. * 28-Sep-01 stefan.roese@esd-electronics.com
  61. * - Changed pci master configuration for linux compatibility
  62. * (no need for bios_fixup() anymore)
  63. * 26-Feb-02 stefan.roese@esd-electronics.com
  64. * - Bug fixed in pci configuration (Andrew May)
  65. * - Removed pci class code init for CPCI405 board
  66. * 15-May-02 stefan.roese@esd-electronics.com
  67. * - New vga device handling
  68. * 29-May-02 stefan.roese@esd-electronics.com
  69. * - PCI class code init added (if defined)
  70. *----------------------------------------------------------------------------*/
  71. #include <common.h>
  72. #include <command.h>
  73. #if !defined(CONFIG_440)
  74. #include <asm/4xx_pci.h>
  75. #endif
  76. #include <asm/processor.h>
  77. #include <pci.h>
  78. #ifdef CONFIG_PCI
  79. DECLARE_GLOBAL_DATA_PTR;
  80. /*
  81. * Board-specific pci initialization
  82. * Platform code can reimplement pci_pre_init() if needed
  83. */
  84. int __pci_pre_init(struct pci_controller *hose)
  85. {
  86. #if defined (CONFIG_405EP)
  87. /*
  88. * Enable the internal PCI arbiter by default.
  89. *
  90. * On 405EP CPUs the internal arbiter can be controlled
  91. * by the I2C strapping EEPROM. If you want to do so
  92. * or if you want to disable the arbiter pci_pre_init()
  93. * must be reimplemented without enabling the arbiter.
  94. * The arbiter is enabled in this place because of
  95. * compatibility reasons.
  96. */
  97. mtdcr(cpc0_pci, mfdcr(cpc0_pci) | CPC0_PCI_ARBIT_EN);
  98. #endif /* CONFIG_405EP */
  99. return 1;
  100. }
  101. int pci_pre_init(struct pci_controller *hose) __attribute__((weak, alias("__pci_pre_init")));
  102. #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
  103. #if defined(CONFIG_PMC405)
  104. ushort pmc405_pci_subsys_deviceid(void);
  105. #endif
  106. /*#define DEBUG*/
  107. int __is_pci_host(struct pci_controller *hose)
  108. {
  109. #if defined(CONFIG_405GP)
  110. if (mfdcr(strap) & PSR_PCI_ARBIT_EN)
  111. return 1;
  112. #elif defined (CONFIG_405EP)
  113. if (mfdcr(cpc0_pci) & CPC0_PCI_ARBIT_EN)
  114. return 1;
  115. #endif
  116. return 0;
  117. }
  118. int is_pci_host(struct pci_controller *hose) __attribute__((weak, alias("__is_pci_host")));
  119. /*-----------------------------------------------------------------------------+
  120. * pci_init. Initializes the 405GP PCI Configuration regs.
  121. *-----------------------------------------------------------------------------*/
  122. void pci_405gp_init(struct pci_controller *hose)
  123. {
  124. int i, reg_num = 0;
  125. bd_t *bd = gd->bd;
  126. unsigned short temp_short;
  127. unsigned long ptmpcila[2] = {CONFIG_SYS_PCI_PTM1PCI, CONFIG_SYS_PCI_PTM2PCI};
  128. #if defined(CONFIG_CPCI405) || defined(CONFIG_PMC405)
  129. char *ptmla_str, *ptmms_str;
  130. #endif
  131. unsigned long ptmla[2] = {CONFIG_SYS_PCI_PTM1LA, CONFIG_SYS_PCI_PTM2LA};
  132. unsigned long ptmms[2] = {CONFIG_SYS_PCI_PTM1MS, CONFIG_SYS_PCI_PTM2MS};
  133. #if defined(CONFIG_PIP405) || defined (CONFIG_MIP405)
  134. unsigned long pmmla[3] = {0x80000000, 0xA0000000, 0};
  135. unsigned long pmmma[3] = {0xE0000001, 0xE0000001, 0};
  136. unsigned long pmmpcila[3] = {0x80000000, 0x00000000, 0};
  137. unsigned long pmmpciha[3] = {0x00000000, 0x00000000, 0};
  138. #else
  139. unsigned long pmmla[3] = {0x80000000, 0,0};
  140. unsigned long pmmma[3] = {0xC0000001, 0,0};
  141. unsigned long pmmpcila[3] = {0x80000000, 0,0};
  142. unsigned long pmmpciha[3] = {0x00000000, 0,0};
  143. #endif
  144. #ifdef CONFIG_PCI_PNP
  145. #if (CONFIG_PCI_HOST == PCI_HOST_AUTO)
  146. char *s;
  147. #endif
  148. #endif
  149. #if defined(CONFIG_CPCI405) || defined(CONFIG_PMC405)
  150. ptmla_str = getenv("ptm1la");
  151. ptmms_str = getenv("ptm1ms");
  152. if(NULL != ptmla_str && NULL != ptmms_str ) {
  153. ptmla[0] = simple_strtoul (ptmla_str, NULL, 16);
  154. ptmms[0] = simple_strtoul (ptmms_str, NULL, 16);
  155. }
  156. ptmla_str = getenv("ptm2la");
  157. ptmms_str = getenv("ptm2ms");
  158. if(NULL != ptmla_str && NULL != ptmms_str ) {
  159. ptmla[1] = simple_strtoul (ptmla_str, NULL, 16);
  160. ptmms[1] = simple_strtoul (ptmms_str, NULL, 16);
  161. }
  162. #endif
  163. /*
  164. * Register the hose
  165. */
  166. hose->first_busno = 0;
  167. hose->last_busno = 0xff;
  168. /* ISA/PCI I/O space */
  169. pci_set_region(hose->regions + reg_num++,
  170. MIN_PCI_PCI_IOADDR,
  171. MIN_PLB_PCI_IOADDR,
  172. 0x10000,
  173. PCI_REGION_IO);
  174. /* PCI I/O space */
  175. pci_set_region(hose->regions + reg_num++,
  176. 0x00800000,
  177. 0xe8800000,
  178. 0x03800000,
  179. PCI_REGION_IO);
  180. reg_num = 2;
  181. /* Memory spaces */
  182. for (i=0; i<2; i++)
  183. if (ptmms[i] & 1)
  184. {
  185. if (!i) hose->pci_fb = hose->regions + reg_num;
  186. pci_set_region(hose->regions + reg_num++,
  187. ptmpcila[i], ptmla[i],
  188. ~(ptmms[i] & 0xfffff000) + 1,
  189. PCI_REGION_MEM |
  190. PCI_REGION_SYS_MEMORY);
  191. }
  192. /* PCI memory spaces */
  193. for (i=0; i<3; i++)
  194. if (pmmma[i] & 1)
  195. {
  196. pci_set_region(hose->regions + reg_num++,
  197. pmmpcila[i], pmmla[i],
  198. ~(pmmma[i] & 0xfffff000) + 1,
  199. PCI_REGION_MEM);
  200. }
  201. hose->region_count = reg_num;
  202. pci_setup_indirect(hose,
  203. PCICFGADR,
  204. PCICFGDATA);
  205. if (hose->pci_fb)
  206. pciauto_region_init(hose->pci_fb);
  207. /* Let board change/modify hose & do initial checks */
  208. if (pci_pre_init (hose) == 0) {
  209. printf("PCI: Board-specific initialization failed.\n");
  210. printf("PCI: Configuration aborted.\n");
  211. return;
  212. }
  213. pci_register_hose(hose);
  214. /*--------------------------------------------------------------------------+
  215. * 405GP PCI Master configuration.
  216. * Map one 512 MB range of PLB/processor addresses to PCI memory space.
  217. * PLB address 0x80000000-0xBFFFFFFF ==> PCI address 0x80000000-0xBFFFFFFF
  218. * Use byte reversed out routines to handle endianess.
  219. *--------------------------------------------------------------------------*/
  220. out32r(PMM0MA, (pmmma[0]&~0x1)); /* disable, configure PMMxLA, PMMxPCILA first */
  221. out32r(PMM0LA, pmmla[0]);
  222. out32r(PMM0PCILA, pmmpcila[0]);
  223. out32r(PMM0PCIHA, pmmpciha[0]);
  224. out32r(PMM0MA, pmmma[0]);
  225. /*--------------------------------------------------------------------------+
  226. * PMM1 is not used. Initialize them to zero.
  227. *--------------------------------------------------------------------------*/
  228. out32r(PMM1MA, (pmmma[1]&~0x1));
  229. out32r(PMM1LA, pmmla[1]);
  230. out32r(PMM1PCILA, pmmpcila[1]);
  231. out32r(PMM1PCIHA, pmmpciha[1]);
  232. out32r(PMM1MA, pmmma[1]);
  233. /*--------------------------------------------------------------------------+
  234. * PMM2 is not used. Initialize them to zero.
  235. *--------------------------------------------------------------------------*/
  236. out32r(PMM2MA, (pmmma[2]&~0x1));
  237. out32r(PMM2LA, pmmla[2]);
  238. out32r(PMM2PCILA, pmmpcila[2]);
  239. out32r(PMM2PCIHA, pmmpciha[2]);
  240. out32r(PMM2MA, pmmma[2]);
  241. /*--------------------------------------------------------------------------+
  242. * 405GP PCI Target configuration. (PTM1)
  243. * Note: PTM1MS is hardwire enabled but we set the enable bit anyway.
  244. *--------------------------------------------------------------------------*/
  245. out32r(PTM1LA, ptmla[0]); /* insert address */
  246. out32r(PTM1MS, ptmms[0]); /* insert size, enable bit is 1 */
  247. pci_write_config_dword(PCIDEVID_405GP, PCI_BASE_ADDRESS_1, ptmpcila[0]);
  248. /*--------------------------------------------------------------------------+
  249. * 405GP PCI Target configuration. (PTM2)
  250. *--------------------------------------------------------------------------*/
  251. out32r(PTM2LA, ptmla[1]); /* insert address */
  252. pci_write_config_dword(PCIDEVID_405GP, PCI_BASE_ADDRESS_2, ptmpcila[1]);
  253. if (ptmms[1] == 0)
  254. {
  255. out32r(PTM2MS, 0x00000001); /* set enable bit */
  256. pci_write_config_dword(PCIDEVID_405GP, PCI_BASE_ADDRESS_2, 0x00000000);
  257. out32r(PTM2MS, 0x00000000); /* disable */
  258. }
  259. else
  260. {
  261. out32r(PTM2MS, ptmms[1]); /* insert size, enable bit is 1 */
  262. }
  263. /*
  264. * Insert Subsystem Vendor and Device ID
  265. */
  266. pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_VENDOR_ID, CONFIG_SYS_PCI_SUBSYS_VENDORID);
  267. #ifdef CONFIG_CPCI405
  268. if (is_pci_host(hose))
  269. pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_DEVICEID);
  270. else
  271. pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_DEVICEID2);
  272. #else
  273. pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_DEVICEID);
  274. #endif
  275. /*
  276. * Insert Class-code
  277. */
  278. #ifdef CONFIG_SYS_PCI_CLASSCODE
  279. pci_write_config_word(PCIDEVID_405GP, PCI_CLASS_SUB_CODE, CONFIG_SYS_PCI_CLASSCODE);
  280. #endif /* CONFIG_SYS_PCI_CLASSCODE */
  281. /*--------------------------------------------------------------------------+
  282. * If PCI speed = 66MHz, set 66MHz capable bit.
  283. *--------------------------------------------------------------------------*/
  284. if (bd->bi_pci_busfreq >= 66000000) {
  285. pci_read_config_word(PCIDEVID_405GP, PCI_STATUS, &temp_short);
  286. pci_write_config_word(PCIDEVID_405GP,PCI_STATUS,(temp_short|PCI_STATUS_66MHZ));
  287. }
  288. #if (CONFIG_PCI_HOST != PCI_HOST_ADAPTER)
  289. #if (CONFIG_PCI_HOST == PCI_HOST_AUTO)
  290. if (is_pci_host(hose) ||
  291. (((s = getenv("pciscan")) != NULL) && (strcmp(s, "yes") == 0)))
  292. #endif
  293. {
  294. /*--------------------------------------------------------------------------+
  295. * Write the 405GP PCI Configuration regs.
  296. * Enable 405GP to be a master on the PCI bus (PMM).
  297. * Enable 405GP to act as a PCI memory target (PTM).
  298. *--------------------------------------------------------------------------*/
  299. pci_read_config_word(PCIDEVID_405GP, PCI_COMMAND, &temp_short);
  300. pci_write_config_word(PCIDEVID_405GP, PCI_COMMAND, temp_short |
  301. PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
  302. }
  303. #endif
  304. #if defined(CONFIG_405EP)
  305. /*
  306. * on ppc405ep vendor/device id is not set
  307. * The user manual says 0x1014 (IBM) / 0x0156 (405GP!)
  308. * are the correct values.
  309. */
  310. pci_write_config_word(PCIDEVID_405GP, PCI_VENDOR_ID, PCI_VENDOR_ID_IBM);
  311. pci_write_config_word(PCIDEVID_405GP,
  312. PCI_DEVICE_ID, PCI_DEVICE_ID_IBM_405GP);
  313. #endif
  314. /*
  315. * Set HCE bit (Host Configuration Enabled)
  316. */
  317. pci_read_config_word(PCIDEVID_405GP, PCIBRDGOPT2, &temp_short);
  318. pci_write_config_word(PCIDEVID_405GP, PCIBRDGOPT2, (temp_short | 0x0001));
  319. #ifdef CONFIG_PCI_PNP
  320. /*--------------------------------------------------------------------------+
  321. * Scan the PCI bus and configure devices found.
  322. *--------------------------------------------------------------------------*/
  323. #if (CONFIG_PCI_HOST == PCI_HOST_AUTO)
  324. if (is_pci_host(hose) ||
  325. (((s = getenv("pciscan")) != NULL) && (strcmp(s, "yes") == 0)))
  326. #endif
  327. {
  328. #ifdef CONFIG_PCI_SCAN_SHOW
  329. printf("PCI: Bus Dev VenId DevId Class Int\n");
  330. #endif
  331. hose->last_busno = pci_hose_scan(hose);
  332. }
  333. #endif /* CONFIG_PCI_PNP */
  334. }
  335. /*
  336. * drivers/pci/pci.c skips every host bridge but the 405GP since it could
  337. * be set as an Adapter.
  338. *
  339. * I (Andrew May) don't know what we should do here, but I don't want
  340. * the auto setup of a PCI device disabling what is done pci_405gp_init
  341. * as has happened before.
  342. */
  343. void pci_405gp_setup_bridge(struct pci_controller *hose, pci_dev_t dev,
  344. struct pci_config_table *entry)
  345. {
  346. #ifdef DEBUG
  347. printf("405gp_setup_bridge\n");
  348. #endif
  349. }
  350. /*
  351. *
  352. */
  353. void pci_405gp_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  354. {
  355. unsigned char int_line = 0xff;
  356. /*
  357. * Write pci interrupt line register (cpci405 specific)
  358. */
  359. switch (PCI_DEV(dev) & 0x03)
  360. {
  361. case 0:
  362. int_line = 27 + 2;
  363. break;
  364. case 1:
  365. int_line = 27 + 3;
  366. break;
  367. case 2:
  368. int_line = 27 + 0;
  369. break;
  370. case 3:
  371. int_line = 27 + 1;
  372. break;
  373. }
  374. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line);
  375. }
  376. void pci_405gp_setup_vga(struct pci_controller *hose, pci_dev_t dev,
  377. struct pci_config_table *entry)
  378. {
  379. unsigned int cmdstat = 0;
  380. pciauto_setup_device(hose, dev, 6, hose->pci_mem, hose->pci_prefetch, hose->pci_io);
  381. /* always enable io space on vga boards */
  382. pci_hose_read_config_dword(hose, dev, PCI_COMMAND, &cmdstat);
  383. cmdstat |= PCI_COMMAND_IO;
  384. pci_hose_write_config_dword(hose, dev, PCI_COMMAND, cmdstat);
  385. }
  386. #if !(defined(CONFIG_PIP405) || defined (CONFIG_MIP405)) && !(defined (CONFIG_SC3))
  387. /*
  388. *As is these functs get called out of flash Not a horrible
  389. *thing, but something to keep in mind. (no statics?)
  390. */
  391. static struct pci_config_table pci_405gp_config_table[] = {
  392. /*if VendID is 0 it terminates the table search (ie Walnut)*/
  393. #ifdef CONFIG_SYS_PCI_SUBSYS_VENDORID
  394. {CONFIG_SYS_PCI_SUBSYS_VENDORID, PCI_ANY_ID, PCI_CLASS_BRIDGE_HOST,
  395. PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, pci_405gp_setup_bridge},
  396. #endif
  397. {PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA,
  398. PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, pci_405gp_setup_vga},
  399. {PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NOT_DEFINED_VGA,
  400. PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, pci_405gp_setup_vga},
  401. { }
  402. };
  403. static struct pci_controller hose = {
  404. fixup_irq: pci_405gp_fixup_irq,
  405. config_table: pci_405gp_config_table,
  406. };
  407. void pci_init_board(void)
  408. {
  409. /*we want the ptrs to RAM not flash (ie don't use init list)*/
  410. hose.fixup_irq = pci_405gp_fixup_irq;
  411. hose.config_table = pci_405gp_config_table;
  412. pci_405gp_init(&hose);
  413. }
  414. #endif
  415. #endif /* CONFIG_405GP */
  416. /*-----------------------------------------------------------------------------+
  417. * CONFIG_440
  418. *-----------------------------------------------------------------------------*/
  419. #if defined(CONFIG_440)
  420. static struct pci_controller ppc440_hose = {0};
  421. int pci_440_init (struct pci_controller *hose)
  422. {
  423. int reg_num = 0;
  424. #ifndef CONFIG_DISABLE_PISE_TEST
  425. /*--------------------------------------------------------------------------+
  426. * The PCI initialization sequence enable bit must be set ... if not abort
  427. * pci setup since updating the bit requires chip reset.
  428. *--------------------------------------------------------------------------*/
  429. #if defined(CONFIG_440GX) || defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  430. unsigned long strap;
  431. mfsdr(sdr_sdstp1,strap);
  432. if ((strap & SDR0_SDSTP1_PISE_MASK) == 0) {
  433. printf("PCI: SDR0_STRP1[PISE] not set.\n");
  434. printf("PCI: Configuration aborted.\n");
  435. return -1;
  436. }
  437. #elif defined(CONFIG_440GP)
  438. unsigned long strap;
  439. strap = mfdcr(cpc0_strp1);
  440. if ((strap & CPC0_STRP1_PISE_MASK) == 0) {
  441. printf("PCI: CPC0_STRP1[PISE] not set.\n");
  442. printf("PCI: Configuration aborted.\n");
  443. return -1;
  444. }
  445. #endif
  446. #endif /* CONFIG_DISABLE_PISE_TEST */
  447. /*--------------------------------------------------------------------------+
  448. * PCI controller init
  449. *--------------------------------------------------------------------------*/
  450. hose->first_busno = 0;
  451. hose->last_busno = 0;
  452. /* PCI I/O space */
  453. pci_set_region(hose->regions + reg_num++,
  454. 0x00000000,
  455. PCIX0_IOBASE,
  456. 0x10000,
  457. PCI_REGION_IO);
  458. /* PCI memory space */
  459. pci_set_region(hose->regions + reg_num++,
  460. CONFIG_SYS_PCI_TARGBASE,
  461. CONFIG_SYS_PCI_MEMBASE,
  462. #ifdef CONFIG_SYS_PCI_MEMSIZE
  463. CONFIG_SYS_PCI_MEMSIZE,
  464. #else
  465. 0x10000000,
  466. #endif
  467. PCI_REGION_MEM );
  468. #if defined(CONFIG_PCI_SYS_MEM_BUS) && defined(CONFIG_PCI_SYS_MEM_PHYS) && \
  469. defined(CONFIG_PCI_SYS_MEM_SIZE)
  470. /* System memory space */
  471. pci_set_region(hose->regions + reg_num++,
  472. CONFIG_PCI_SYS_MEM_BUS,
  473. CONFIG_PCI_SYS_MEM_PHYS,
  474. CONFIG_PCI_SYS_MEM_SIZE,
  475. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY );
  476. #endif
  477. hose->region_count = reg_num;
  478. pci_setup_indirect(hose, PCIX0_CFGADR, PCIX0_CFGDATA);
  479. /* Let board change/modify hose & do initial checks */
  480. if (pci_pre_init (hose) == 0) {
  481. printf("PCI: Board-specific initialization failed.\n");
  482. printf("PCI: Configuration aborted.\n");
  483. return -1;
  484. }
  485. pci_register_hose( hose );
  486. /*--------------------------------------------------------------------------+
  487. * PCI target init
  488. *--------------------------------------------------------------------------*/
  489. #if defined(CONFIG_SYS_PCI_TARGET_INIT)
  490. pci_target_init(hose); /* Let board setup pci target */
  491. #else
  492. out16r( PCIX0_SBSYSVID, CONFIG_SYS_PCI_SUBSYS_VENDORID );
  493. out16r( PCIX0_SBSYSID, CONFIG_SYS_PCI_SUBSYS_ID );
  494. out16r( PCIX0_CLS, 0x00060000 ); /* Bridge, host bridge */
  495. #endif
  496. #if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
  497. defined(CONFIG_460EX) || defined(CONFIG_460GT)
  498. out32r( PCIX0_BRDGOPT1, 0x04000060 ); /* PLB Rq pri highest */
  499. out32r( PCIX0_BRDGOPT2, in32(PCIX0_BRDGOPT2) | 0x83 ); /* Enable host config, clear Timeout, ensure int src1 */
  500. #elif defined(PCIX0_BRDGOPT1)
  501. out32r( PCIX0_BRDGOPT1, 0x10000060 ); /* PLB Rq pri highest */
  502. out32r( PCIX0_BRDGOPT2, in32(PCIX0_BRDGOPT2) | 1 ); /* Enable host config */
  503. #endif
  504. /*--------------------------------------------------------------------------+
  505. * PCI master init: default is one 256MB region for PCI memory:
  506. * 0x3_00000000 - 0x3_0FFFFFFF ==> CONFIG_SYS_PCI_MEMBASE
  507. *--------------------------------------------------------------------------*/
  508. #if defined(CONFIG_SYS_PCI_MASTER_INIT)
  509. pci_master_init(hose); /* Let board setup pci master */
  510. #else
  511. out32r( PCIX0_POM0SA, 0 ); /* disable */
  512. out32r( PCIX0_POM1SA, 0 ); /* disable */
  513. out32r( PCIX0_POM2SA, 0 ); /* disable */
  514. #if defined(CONFIG_440SPE)
  515. out32r( PCIX0_POM0LAL, 0x10000000 );
  516. out32r( PCIX0_POM0LAH, 0x0000000c );
  517. #elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
  518. out32r( PCIX0_POM0LAL, 0x20000000 );
  519. out32r( PCIX0_POM0LAH, 0x0000000c );
  520. #else
  521. out32r( PCIX0_POM0LAL, 0x00000000 );
  522. out32r( PCIX0_POM0LAH, 0x00000003 );
  523. #endif
  524. out32r( PCIX0_POM0PCIAL, CONFIG_SYS_PCI_MEMBASE );
  525. out32r( PCIX0_POM0PCIAH, 0x00000000 );
  526. out32r( PCIX0_POM0SA, 0xf0000001 ); /* 256MB, enabled */
  527. out32r( PCIX0_STS, in32r( PCIX0_STS ) & ~0x0000fff8 );
  528. #endif
  529. /*--------------------------------------------------------------------------+
  530. * PCI host configuration -- we don't make any assumptions here ... the
  531. * _board_must_indicate_ what to do -- there's just too many runtime
  532. * scenarios in environments like cPCI, PPMC, etc. to make a determination
  533. * based on hard-coded values or state of arbiter enable.
  534. *--------------------------------------------------------------------------*/
  535. if (is_pci_host(hose)) {
  536. #ifdef CONFIG_PCI_SCAN_SHOW
  537. printf("PCI: Bus Dev VenId DevId Class Int\n");
  538. #endif
  539. #if !defined(CONFIG_440EP) && !defined(CONFIG_440GR) && \
  540. !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX)
  541. out16r( PCIX0_CMD, in16r( PCIX0_CMD ) | PCI_COMMAND_MASTER);
  542. #endif
  543. hose->last_busno = pci_hose_scan(hose);
  544. }
  545. return hose->last_busno;
  546. }
  547. void pci_init_board(void)
  548. {
  549. int busno;
  550. busno = pci_440_init (&ppc440_hose);
  551. #if (defined(CONFIG_440SPE) || \
  552. defined(CONFIG_460EX) || defined(CONFIG_460GT)) && \
  553. !defined(CONFIG_PCI_DISABLE_PCIE)
  554. pcie_setup_hoses(busno + 1);
  555. #endif
  556. }
  557. #endif /* CONFIG_440 */
  558. #if defined(CONFIG_405EX)
  559. void pci_init_board(void)
  560. {
  561. #ifdef CONFIG_PCI_SCAN_SHOW
  562. printf("PCI: Bus Dev VenId DevId Class Int\n");
  563. #endif
  564. pcie_setup_hoses(0);
  565. }
  566. #endif /* CONFIG_405EX */
  567. #endif /* CONFIG_PCI */