pci.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /*
  2. * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  3. * Andreas Heppel <aheppel@sysgo.de>
  4. *
  5. * (C) Copyright 2002, 2003
  6. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. /*
  27. * PCI routines
  28. */
  29. #include <common.h>
  30. #include <command.h>
  31. #include <asm/processor.h>
  32. #include <asm/io.h>
  33. #include <pci.h>
  34. #define PCI_HOSE_OP(rw, size, type) \
  35. int pci_hose_##rw##_config_##size(struct pci_controller *hose, \
  36. pci_dev_t dev, \
  37. int offset, type value) \
  38. { \
  39. return hose->rw##_##size(hose, dev, offset, value); \
  40. }
  41. PCI_HOSE_OP(read, byte, u8 *)
  42. PCI_HOSE_OP(read, word, u16 *)
  43. PCI_HOSE_OP(read, dword, u32 *)
  44. PCI_HOSE_OP(write, byte, u8)
  45. PCI_HOSE_OP(write, word, u16)
  46. PCI_HOSE_OP(write, dword, u32)
  47. #define PCI_OP(rw, size, type, error_code) \
  48. int pci_##rw##_config_##size(pci_dev_t dev, int offset, type value) \
  49. { \
  50. struct pci_controller *hose = pci_bus_to_hose(PCI_BUS(dev)); \
  51. \
  52. if (!hose) \
  53. { \
  54. error_code; \
  55. return -1; \
  56. } \
  57. \
  58. return pci_hose_##rw##_config_##size(hose, dev, offset, value); \
  59. }
  60. PCI_OP(read, byte, u8 *, *value = 0xff)
  61. PCI_OP(read, word, u16 *, *value = 0xffff)
  62. PCI_OP(read, dword, u32 *, *value = 0xffffffff)
  63. PCI_OP(write, byte, u8, )
  64. PCI_OP(write, word, u16, )
  65. PCI_OP(write, dword, u32, )
  66. #define PCI_READ_VIA_DWORD_OP(size, type, off_mask) \
  67. int pci_hose_read_config_##size##_via_dword(struct pci_controller *hose,\
  68. pci_dev_t dev, \
  69. int offset, type val) \
  70. { \
  71. u32 val32; \
  72. \
  73. if (pci_hose_read_config_dword(hose, dev, offset & 0xfc, &val32) < 0) { \
  74. *val = -1; \
  75. return -1; \
  76. } \
  77. \
  78. *val = (val32 >> ((offset & (int)off_mask) * 8)); \
  79. \
  80. return 0; \
  81. }
  82. #define PCI_WRITE_VIA_DWORD_OP(size, type, off_mask, val_mask) \
  83. int pci_hose_write_config_##size##_via_dword(struct pci_controller *hose,\
  84. pci_dev_t dev, \
  85. int offset, type val) \
  86. { \
  87. u32 val32, mask, ldata, shift; \
  88. \
  89. if (pci_hose_read_config_dword(hose, dev, offset & 0xfc, &val32) < 0)\
  90. return -1; \
  91. \
  92. shift = ((offset & (int)off_mask) * 8); \
  93. ldata = (((unsigned long)val) & val_mask) << shift; \
  94. mask = val_mask << shift; \
  95. val32 = (val32 & ~mask) | ldata; \
  96. \
  97. if (pci_hose_write_config_dword(hose, dev, offset & 0xfc, val32) < 0)\
  98. return -1; \
  99. \
  100. return 0; \
  101. }
  102. PCI_READ_VIA_DWORD_OP(byte, u8 *, 0x03)
  103. PCI_READ_VIA_DWORD_OP(word, u16 *, 0x02)
  104. PCI_WRITE_VIA_DWORD_OP(byte, u8, 0x03, 0x000000ff)
  105. PCI_WRITE_VIA_DWORD_OP(word, u16, 0x02, 0x0000ffff)
  106. /* Get a virtual address associated with a BAR region */
  107. void *pci_map_bar(pci_dev_t pdev, int bar, int flags)
  108. {
  109. pci_addr_t pci_bus_addr;
  110. pci_addr_t bar_response;
  111. /* read BAR address */
  112. pci_read_config_dword(pdev, bar, &bar_response);
  113. pci_bus_addr = bar_response & ~0xf;
  114. /*
  115. * Pass "0" as the length argument to pci_bus_to_virt. The arg
  116. * isn't actualy used on any platform because u-boot assumes a static
  117. * linear mapping. In the future, this could read the BAR size
  118. * and pass that as the size if needed.
  119. */
  120. return pci_bus_to_virt(pdev, pci_bus_addr, flags, 0, MAP_NOCACHE);
  121. }
  122. /*
  123. *
  124. */
  125. static struct pci_controller* hose_head;
  126. void pci_register_hose(struct pci_controller* hose)
  127. {
  128. struct pci_controller **phose = &hose_head;
  129. while(*phose)
  130. phose = &(*phose)->next;
  131. hose->next = NULL;
  132. *phose = hose;
  133. }
  134. struct pci_controller *pci_bus_to_hose(int bus)
  135. {
  136. struct pci_controller *hose;
  137. for (hose = hose_head; hose; hose = hose->next) {
  138. if (bus >= hose->first_busno && bus <= hose->last_busno)
  139. return hose;
  140. }
  141. printf("pci_bus_to_hose() failed\n");
  142. return NULL;
  143. }
  144. struct pci_controller *find_hose_by_cfg_addr(void *cfg_addr)
  145. {
  146. struct pci_controller *hose;
  147. for (hose = hose_head; hose; hose = hose->next) {
  148. if (hose->cfg_addr == cfg_addr)
  149. return hose;
  150. }
  151. return NULL;
  152. }
  153. int pci_last_busno(void)
  154. {
  155. struct pci_controller *hose = hose_head;
  156. if (!hose)
  157. return -1;
  158. while (hose->next)
  159. hose = hose->next;
  160. return hose->last_busno;
  161. }
  162. pci_dev_t pci_find_devices(struct pci_device_id *ids, int index)
  163. {
  164. struct pci_controller * hose;
  165. u16 vendor, device;
  166. u8 header_type;
  167. pci_dev_t bdf;
  168. int i, bus, found_multi = 0;
  169. for (hose = hose_head; hose; hose = hose->next) {
  170. #ifdef CONFIG_SYS_SCSI_SCAN_BUS_REVERSE
  171. for (bus = hose->last_busno; bus >= hose->first_busno; bus--)
  172. #else
  173. for (bus = hose->first_busno; bus <= hose->last_busno; bus++)
  174. #endif
  175. for (bdf = PCI_BDF(bus, 0, 0);
  176. #if defined(CONFIG_ELPPC) || defined(CONFIG_PPMC7XX)
  177. bdf < PCI_BDF(bus, PCI_MAX_PCI_DEVICES - 1,
  178. PCI_MAX_PCI_FUNCTIONS - 1);
  179. #else
  180. bdf < PCI_BDF(bus + 1, 0, 0);
  181. #endif
  182. bdf += PCI_BDF(0, 0, 1)) {
  183. if (!PCI_FUNC(bdf)) {
  184. pci_read_config_byte(bdf,
  185. PCI_HEADER_TYPE,
  186. &header_type);
  187. found_multi = header_type & 0x80;
  188. } else {
  189. if (!found_multi)
  190. continue;
  191. }
  192. pci_read_config_word(bdf,
  193. PCI_VENDOR_ID,
  194. &vendor);
  195. pci_read_config_word(bdf,
  196. PCI_DEVICE_ID,
  197. &device);
  198. for (i = 0; ids[i].vendor != 0; i++) {
  199. if (vendor == ids[i].vendor &&
  200. device == ids[i].device) {
  201. if (index <= 0)
  202. return bdf;
  203. index--;
  204. }
  205. }
  206. }
  207. }
  208. return -1;
  209. }
  210. pci_dev_t pci_find_device(unsigned int vendor, unsigned int device, int index)
  211. {
  212. static struct pci_device_id ids[2] = {{}, {0, 0}};
  213. ids[0].vendor = vendor;
  214. ids[0].device = device;
  215. return pci_find_devices(ids, index);
  216. }
  217. /*
  218. *
  219. */
  220. int __pci_hose_phys_to_bus(struct pci_controller *hose,
  221. phys_addr_t phys_addr,
  222. unsigned long flags,
  223. unsigned long skip_mask,
  224. pci_addr_t *ba)
  225. {
  226. struct pci_region *res;
  227. pci_addr_t bus_addr;
  228. int i;
  229. for (i = 0; i < hose->region_count; i++) {
  230. res = &hose->regions[i];
  231. if (((res->flags ^ flags) & PCI_REGION_TYPE) != 0)
  232. continue;
  233. if (res->flags & skip_mask)
  234. continue;
  235. bus_addr = phys_addr - res->phys_start + res->bus_start;
  236. if (bus_addr >= res->bus_start &&
  237. bus_addr < res->bus_start + res->size) {
  238. *ba = bus_addr;
  239. return 0;
  240. }
  241. }
  242. return 1;
  243. }
  244. pci_addr_t pci_hose_phys_to_bus (struct pci_controller *hose,
  245. phys_addr_t phys_addr,
  246. unsigned long flags)
  247. {
  248. pci_addr_t bus_addr = 0;
  249. int ret;
  250. if (!hose) {
  251. puts("pci_hose_phys_to_bus: invalid hose\n");
  252. return bus_addr;
  253. }
  254. /*
  255. * if PCI_REGION_MEM is set we do a two pass search with preference
  256. * on matches that don't have PCI_REGION_SYS_MEMORY set
  257. */
  258. if ((flags & PCI_REGION_MEM) == PCI_REGION_MEM) {
  259. ret = __pci_hose_phys_to_bus(hose, phys_addr,
  260. flags, PCI_REGION_SYS_MEMORY, &bus_addr);
  261. if (!ret)
  262. return bus_addr;
  263. }
  264. ret = __pci_hose_phys_to_bus(hose, phys_addr, flags, 0, &bus_addr);
  265. if (ret)
  266. puts("pci_hose_phys_to_bus: invalid physical address\n");
  267. return bus_addr;
  268. }
  269. int __pci_hose_bus_to_phys(struct pci_controller *hose,
  270. pci_addr_t bus_addr,
  271. unsigned long flags,
  272. unsigned long skip_mask,
  273. phys_addr_t *pa)
  274. {
  275. struct pci_region *res;
  276. int i;
  277. for (i = 0; i < hose->region_count; i++) {
  278. res = &hose->regions[i];
  279. if (((res->flags ^ flags) & PCI_REGION_TYPE) != 0)
  280. continue;
  281. if (res->flags & skip_mask)
  282. continue;
  283. if (bus_addr >= res->bus_start &&
  284. bus_addr < res->bus_start + res->size) {
  285. *pa = (bus_addr - res->bus_start + res->phys_start);
  286. return 0;
  287. }
  288. }
  289. return 1;
  290. }
  291. phys_addr_t pci_hose_bus_to_phys(struct pci_controller* hose,
  292. pci_addr_t bus_addr,
  293. unsigned long flags)
  294. {
  295. phys_addr_t phys_addr = 0;
  296. int ret;
  297. if (!hose) {
  298. puts("pci_hose_bus_to_phys: invalid hose\n");
  299. return phys_addr;
  300. }
  301. /*
  302. * if PCI_REGION_MEM is set we do a two pass search with preference
  303. * on matches that don't have PCI_REGION_SYS_MEMORY set
  304. */
  305. if ((flags & PCI_REGION_MEM) == PCI_REGION_MEM) {
  306. ret = __pci_hose_bus_to_phys(hose, bus_addr,
  307. flags, PCI_REGION_SYS_MEMORY, &phys_addr);
  308. if (!ret)
  309. return phys_addr;
  310. }
  311. ret = __pci_hose_bus_to_phys(hose, bus_addr, flags, 0, &phys_addr);
  312. if (ret)
  313. puts("pci_hose_bus_to_phys: invalid physical address\n");
  314. return phys_addr;
  315. }
  316. /*
  317. *
  318. */
  319. int pci_hose_config_device(struct pci_controller *hose,
  320. pci_dev_t dev,
  321. unsigned long io,
  322. pci_addr_t mem,
  323. unsigned long command)
  324. {
  325. pci_addr_t bar_response;
  326. unsigned int old_command;
  327. pci_addr_t bar_value;
  328. pci_size_t bar_size;
  329. unsigned char pin;
  330. int bar, found_mem64;
  331. debug("PCI Config: I/O=0x%lx, Memory=0x%llx, Command=0x%lx\n", io,
  332. (u64)mem, command);
  333. pci_hose_write_config_dword(hose, dev, PCI_COMMAND, 0);
  334. for (bar = PCI_BASE_ADDRESS_0; bar <= PCI_BASE_ADDRESS_5; bar += 4) {
  335. pci_hose_write_config_dword(hose, dev, bar, 0xffffffff);
  336. pci_hose_read_config_dword(hose, dev, bar, &bar_response);
  337. if (!bar_response)
  338. continue;
  339. found_mem64 = 0;
  340. /* Check the BAR type and set our address mask */
  341. if (bar_response & PCI_BASE_ADDRESS_SPACE) {
  342. bar_size = ~(bar_response & PCI_BASE_ADDRESS_IO_MASK) + 1;
  343. /* round up region base address to a multiple of size */
  344. io = ((io - 1) | (bar_size - 1)) + 1;
  345. bar_value = io;
  346. /* compute new region base address */
  347. io = io + bar_size;
  348. } else {
  349. if ((bar_response & PCI_BASE_ADDRESS_MEM_TYPE_MASK) ==
  350. PCI_BASE_ADDRESS_MEM_TYPE_64) {
  351. u32 bar_response_upper;
  352. u64 bar64;
  353. pci_hose_write_config_dword(hose, dev, bar + 4,
  354. 0xffffffff);
  355. pci_hose_read_config_dword(hose, dev, bar + 4,
  356. &bar_response_upper);
  357. bar64 = ((u64)bar_response_upper << 32) | bar_response;
  358. bar_size = ~(bar64 & PCI_BASE_ADDRESS_MEM_MASK) + 1;
  359. found_mem64 = 1;
  360. } else {
  361. bar_size = (u32)(~(bar_response & PCI_BASE_ADDRESS_MEM_MASK) + 1);
  362. }
  363. /* round up region base address to multiple of size */
  364. mem = ((mem - 1) | (bar_size - 1)) + 1;
  365. bar_value = mem;
  366. /* compute new region base address */
  367. mem = mem + bar_size;
  368. }
  369. /* Write it out and update our limit */
  370. pci_hose_write_config_dword (hose, dev, bar, (u32)bar_value);
  371. if (found_mem64) {
  372. bar += 4;
  373. #ifdef CONFIG_SYS_PCI_64BIT
  374. pci_hose_write_config_dword(hose, dev, bar,
  375. (u32)(bar_value >> 32));
  376. #else
  377. pci_hose_write_config_dword(hose, dev, bar, 0x00000000);
  378. #endif
  379. }
  380. }
  381. /* Configure Cache Line Size Register */
  382. pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
  383. /* Configure Latency Timer */
  384. pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
  385. /* Disable interrupt line, if device says it wants to use interrupts */
  386. pci_hose_read_config_byte(hose, dev, PCI_INTERRUPT_PIN, &pin);
  387. if (pin != 0) {
  388. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, 0xff);
  389. }
  390. pci_hose_read_config_dword(hose, dev, PCI_COMMAND, &old_command);
  391. pci_hose_write_config_dword(hose, dev, PCI_COMMAND,
  392. (old_command & 0xffff0000) | command);
  393. return 0;
  394. }
  395. /*
  396. *
  397. */
  398. struct pci_config_table *pci_find_config(struct pci_controller *hose,
  399. unsigned short class,
  400. unsigned int vendor,
  401. unsigned int device,
  402. unsigned int bus,
  403. unsigned int dev,
  404. unsigned int func)
  405. {
  406. struct pci_config_table *table;
  407. for (table = hose->config_table; table && table->vendor; table++) {
  408. if ((table->vendor == PCI_ANY_ID || table->vendor == vendor) &&
  409. (table->device == PCI_ANY_ID || table->device == device) &&
  410. (table->class == PCI_ANY_ID || table->class == class) &&
  411. (table->bus == PCI_ANY_ID || table->bus == bus) &&
  412. (table->dev == PCI_ANY_ID || table->dev == dev) &&
  413. (table->func == PCI_ANY_ID || table->func == func)) {
  414. return table;
  415. }
  416. }
  417. return NULL;
  418. }
  419. void pci_cfgfunc_config_device(struct pci_controller *hose,
  420. pci_dev_t dev,
  421. struct pci_config_table *entry)
  422. {
  423. pci_hose_config_device(hose, dev, entry->priv[0], entry->priv[1],
  424. entry->priv[2]);
  425. }
  426. void pci_cfgfunc_do_nothing(struct pci_controller *hose,
  427. pci_dev_t dev, struct pci_config_table *entry)
  428. {
  429. }
  430. /*
  431. * HJF: Changed this to return int. I think this is required
  432. * to get the correct result when scanning bridges
  433. */
  434. extern int pciauto_config_device(struct pci_controller *hose, pci_dev_t dev);
  435. #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI_SCAN_SHOW)
  436. const char * pci_class_str(u8 class)
  437. {
  438. switch (class) {
  439. case PCI_CLASS_NOT_DEFINED:
  440. return "Build before PCI Rev2.0";
  441. break;
  442. case PCI_BASE_CLASS_STORAGE:
  443. return "Mass storage controller";
  444. break;
  445. case PCI_BASE_CLASS_NETWORK:
  446. return "Network controller";
  447. break;
  448. case PCI_BASE_CLASS_DISPLAY:
  449. return "Display controller";
  450. break;
  451. case PCI_BASE_CLASS_MULTIMEDIA:
  452. return "Multimedia device";
  453. break;
  454. case PCI_BASE_CLASS_MEMORY:
  455. return "Memory controller";
  456. break;
  457. case PCI_BASE_CLASS_BRIDGE:
  458. return "Bridge device";
  459. break;
  460. case PCI_BASE_CLASS_COMMUNICATION:
  461. return "Simple comm. controller";
  462. break;
  463. case PCI_BASE_CLASS_SYSTEM:
  464. return "Base system peripheral";
  465. break;
  466. case PCI_BASE_CLASS_INPUT:
  467. return "Input device";
  468. break;
  469. case PCI_BASE_CLASS_DOCKING:
  470. return "Docking station";
  471. break;
  472. case PCI_BASE_CLASS_PROCESSOR:
  473. return "Processor";
  474. break;
  475. case PCI_BASE_CLASS_SERIAL:
  476. return "Serial bus controller";
  477. break;
  478. case PCI_BASE_CLASS_INTELLIGENT:
  479. return "Intelligent controller";
  480. break;
  481. case PCI_BASE_CLASS_SATELLITE:
  482. return "Satellite controller";
  483. break;
  484. case PCI_BASE_CLASS_CRYPT:
  485. return "Cryptographic device";
  486. break;
  487. case PCI_BASE_CLASS_SIGNAL_PROCESSING:
  488. return "DSP";
  489. break;
  490. case PCI_CLASS_OTHERS:
  491. return "Does not fit any class";
  492. break;
  493. default:
  494. return "???";
  495. break;
  496. };
  497. }
  498. #endif /* CONFIG_CMD_PCI || CONFIG_PCI_SCAN_SHOW */
  499. int __pci_skip_dev(struct pci_controller *hose, pci_dev_t dev)
  500. {
  501. /*
  502. * Check if pci device should be skipped in configuration
  503. */
  504. if (dev == PCI_BDF(hose->first_busno, 0, 0)) {
  505. #if defined(CONFIG_PCI_CONFIG_HOST_BRIDGE) /* don't skip host bridge */
  506. /*
  507. * Only skip configuration if "pciconfighost" is not set
  508. */
  509. if (getenv("pciconfighost") == NULL)
  510. return 1;
  511. #else
  512. return 1;
  513. #endif
  514. }
  515. return 0;
  516. }
  517. int pci_skip_dev(struct pci_controller *hose, pci_dev_t dev)
  518. __attribute__((weak, alias("__pci_skip_dev")));
  519. #ifdef CONFIG_PCI_SCAN_SHOW
  520. int __pci_print_dev(struct pci_controller *hose, pci_dev_t dev)
  521. {
  522. if (dev == PCI_BDF(hose->first_busno, 0, 0))
  523. return 0;
  524. return 1;
  525. }
  526. int pci_print_dev(struct pci_controller *hose, pci_dev_t dev)
  527. __attribute__((weak, alias("__pci_print_dev")));
  528. #endif /* CONFIG_PCI_SCAN_SHOW */
  529. int pci_hose_scan_bus(struct pci_controller *hose, int bus)
  530. {
  531. unsigned int sub_bus, found_multi = 0;
  532. unsigned short vendor, device, class;
  533. unsigned char header_type;
  534. struct pci_config_table *cfg;
  535. pci_dev_t dev;
  536. #ifdef CONFIG_PCI_SCAN_SHOW
  537. static int indent = 0;
  538. #endif
  539. sub_bus = bus;
  540. for (dev = PCI_BDF(bus,0,0);
  541. dev < PCI_BDF(bus, PCI_MAX_PCI_DEVICES - 1,
  542. PCI_MAX_PCI_FUNCTIONS - 1);
  543. dev += PCI_BDF(0, 0, 1)) {
  544. if (pci_skip_dev(hose, dev))
  545. continue;
  546. if (PCI_FUNC(dev) && !found_multi)
  547. continue;
  548. pci_hose_read_config_byte(hose, dev, PCI_HEADER_TYPE, &header_type);
  549. pci_hose_read_config_word(hose, dev, PCI_VENDOR_ID, &vendor);
  550. if (vendor == 0xffff || vendor == 0x0000)
  551. continue;
  552. if (!PCI_FUNC(dev))
  553. found_multi = header_type & 0x80;
  554. debug("PCI Scan: Found Bus %d, Device %d, Function %d\n",
  555. PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev));
  556. pci_hose_read_config_word(hose, dev, PCI_DEVICE_ID, &device);
  557. pci_hose_read_config_word(hose, dev, PCI_CLASS_DEVICE, &class);
  558. #ifdef CONFIG_PCI_SCAN_SHOW
  559. indent++;
  560. /* Print leading space, including bus indentation */
  561. printf("%*c", indent + 1, ' ');
  562. if (pci_print_dev(hose, dev)) {
  563. printf("%02x:%02x.%-*x - %04x:%04x - %s\n",
  564. PCI_BUS(dev), PCI_DEV(dev), 6 - indent, PCI_FUNC(dev),
  565. vendor, device, pci_class_str(class >> 8));
  566. }
  567. #endif
  568. cfg = pci_find_config(hose, class, vendor, device,
  569. PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev));
  570. if (cfg) {
  571. cfg->config_device(hose, dev, cfg);
  572. sub_bus = max(sub_bus, hose->current_busno);
  573. #ifdef CONFIG_PCI_PNP
  574. } else {
  575. int n = pciauto_config_device(hose, dev);
  576. sub_bus = max(sub_bus, n);
  577. #endif
  578. }
  579. #ifdef CONFIG_PCI_SCAN_SHOW
  580. indent--;
  581. #endif
  582. if (hose->fixup_irq)
  583. hose->fixup_irq(hose, dev);
  584. }
  585. return sub_bus;
  586. }
  587. int pci_hose_scan(struct pci_controller *hose)
  588. {
  589. #if defined(CONFIG_PCI_BOOTDELAY)
  590. static int pcidelay_done;
  591. char *s;
  592. int i;
  593. if (!pcidelay_done) {
  594. /* wait "pcidelay" ms (if defined)... */
  595. s = getenv("pcidelay");
  596. if (s) {
  597. int val = simple_strtoul(s, NULL, 10);
  598. for (i = 0; i < val; i++)
  599. udelay(1000);
  600. }
  601. pcidelay_done = 1;
  602. }
  603. #endif /* CONFIG_PCI_BOOTDELAY */
  604. /*
  605. * Start scan at current_busno.
  606. * PCIe will start scan at first_busno+1.
  607. */
  608. /* For legacy support, ensure current >= first */
  609. if (hose->first_busno > hose->current_busno)
  610. hose->current_busno = hose->first_busno;
  611. #ifdef CONFIG_PCI_PNP
  612. pciauto_config_init(hose);
  613. #endif
  614. return pci_hose_scan_bus(hose, hose->current_busno);
  615. }
  616. void pci_init(void)
  617. {
  618. hose_head = NULL;
  619. /* now call board specific pci_init()... */
  620. pci_init_board();
  621. }