pci.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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. u32 bar_response;
  111. /* read BAR address */
  112. pci_read_config_dword(pdev, bar, &bar_response);
  113. pci_bus_addr = (pci_addr_t)(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. printf("pci_bus_to_hose() failed\n");
  141. return NULL;
  142. }
  143. struct pci_controller *find_hose_by_cfg_addr(void *cfg_addr)
  144. {
  145. struct pci_controller *hose;
  146. for (hose = hose_head; hose; hose = hose->next) {
  147. if (hose->cfg_addr == cfg_addr)
  148. return hose;
  149. }
  150. return NULL;
  151. }
  152. int pci_last_busno(void)
  153. {
  154. struct pci_controller *hose = hose_head;
  155. if (!hose)
  156. return -1;
  157. while (hose->next)
  158. hose = hose->next;
  159. return hose->last_busno;
  160. }
  161. pci_dev_t pci_find_devices(struct pci_device_id *ids, int index)
  162. {
  163. struct pci_controller * hose;
  164. u16 vendor, device;
  165. u8 header_type;
  166. pci_dev_t bdf;
  167. int i, bus, found_multi = 0;
  168. for (hose = hose_head; hose; hose = hose->next)
  169. {
  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,PCI_MAX_PCI_FUNCTIONS-1);
  178. #else
  179. bdf < PCI_BDF(bus+1,0,0);
  180. #endif
  181. bdf += PCI_BDF(0,0,1))
  182. {
  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. {
  202. if (index <= 0)
  203. return bdf;
  204. index--;
  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. /* if PCI_REGION_MEM is set we do a two pass search with preference
  255. * on matches that don't have PCI_REGION_SYS_MEMORY set */
  256. if ((flags & PCI_REGION_MEM) == PCI_REGION_MEM) {
  257. ret = __pci_hose_phys_to_bus(hose, phys_addr,
  258. flags, PCI_REGION_SYS_MEMORY, &bus_addr);
  259. if (!ret)
  260. return bus_addr;
  261. }
  262. ret = __pci_hose_phys_to_bus(hose, phys_addr, flags, 0, &bus_addr);
  263. if (ret)
  264. puts ("pci_hose_phys_to_bus: invalid physical address\n");
  265. return bus_addr;
  266. }
  267. int __pci_hose_bus_to_phys (struct pci_controller *hose,
  268. pci_addr_t bus_addr,
  269. unsigned long flags,
  270. unsigned long skip_mask,
  271. phys_addr_t *pa)
  272. {
  273. struct pci_region *res;
  274. int i;
  275. for (i = 0; i < hose->region_count; i++) {
  276. res = &hose->regions[i];
  277. if (((res->flags ^ flags) & PCI_REGION_TYPE) != 0)
  278. continue;
  279. if (res->flags & skip_mask)
  280. continue;
  281. if (bus_addr >= res->bus_start &&
  282. bus_addr < res->bus_start + res->size) {
  283. *pa = (bus_addr - res->bus_start + res->phys_start);
  284. return 0;
  285. }
  286. }
  287. return 1;
  288. }
  289. phys_addr_t pci_hose_bus_to_phys(struct pci_controller* hose,
  290. pci_addr_t bus_addr,
  291. unsigned long flags)
  292. {
  293. phys_addr_t phys_addr = 0;
  294. int ret;
  295. if (!hose) {
  296. puts ("pci_hose_bus_to_phys: invalid hose\n");
  297. return phys_addr;
  298. }
  299. /* if PCI_REGION_MEM is set we do a two pass search with preference
  300. * on matches that don't have PCI_REGION_SYS_MEMORY set */
  301. if ((flags & PCI_REGION_MEM) == PCI_REGION_MEM) {
  302. ret = __pci_hose_bus_to_phys(hose, bus_addr,
  303. flags, PCI_REGION_SYS_MEMORY, &phys_addr);
  304. if (!ret)
  305. return phys_addr;
  306. }
  307. ret = __pci_hose_bus_to_phys(hose, bus_addr, flags, 0, &phys_addr);
  308. if (ret)
  309. puts ("pci_hose_bus_to_phys: invalid physical address\n");
  310. return phys_addr;
  311. }
  312. /*
  313. *
  314. */
  315. int pci_hose_config_device(struct pci_controller *hose,
  316. pci_dev_t dev,
  317. unsigned long io,
  318. pci_addr_t mem,
  319. unsigned long command)
  320. {
  321. unsigned int bar_response, old_command;
  322. pci_addr_t bar_value;
  323. pci_size_t bar_size;
  324. unsigned char pin;
  325. int bar, found_mem64;
  326. debug ("PCI Config: I/O=0x%lx, Memory=0x%llx, Command=0x%lx\n",
  327. io, (u64)mem, command);
  328. pci_hose_write_config_dword (hose, dev, PCI_COMMAND, 0);
  329. for (bar = PCI_BASE_ADDRESS_0; bar <= PCI_BASE_ADDRESS_5; bar += 4) {
  330. pci_hose_write_config_dword (hose, dev, bar, 0xffffffff);
  331. pci_hose_read_config_dword (hose, dev, bar, &bar_response);
  332. if (!bar_response)
  333. continue;
  334. found_mem64 = 0;
  335. /* Check the BAR type and set our address mask */
  336. if (bar_response & PCI_BASE_ADDRESS_SPACE) {
  337. bar_size = ~(bar_response & PCI_BASE_ADDRESS_IO_MASK) + 1;
  338. /* round up region base address to a multiple of size */
  339. io = ((io - 1) | (bar_size - 1)) + 1;
  340. bar_value = io;
  341. /* compute new region base address */
  342. io = io + bar_size;
  343. } else {
  344. if ((bar_response & PCI_BASE_ADDRESS_MEM_TYPE_MASK) ==
  345. PCI_BASE_ADDRESS_MEM_TYPE_64) {
  346. u32 bar_response_upper;
  347. u64 bar64;
  348. pci_hose_write_config_dword(hose, dev, bar+4, 0xffffffff);
  349. pci_hose_read_config_dword(hose, dev, bar+4, &bar_response_upper);
  350. bar64 = ((u64)bar_response_upper << 32) | bar_response;
  351. bar_size = ~(bar64 & PCI_BASE_ADDRESS_MEM_MASK) + 1;
  352. found_mem64 = 1;
  353. } else {
  354. bar_size = (u32)(~(bar_response & PCI_BASE_ADDRESS_MEM_MASK) + 1);
  355. }
  356. /* round up region base address to multiple of size */
  357. mem = ((mem - 1) | (bar_size - 1)) + 1;
  358. bar_value = mem;
  359. /* compute new region base address */
  360. mem = mem + bar_size;
  361. }
  362. /* Write it out and update our limit */
  363. pci_hose_write_config_dword (hose, dev, bar, (u32)bar_value);
  364. if (found_mem64) {
  365. bar += 4;
  366. #ifdef CONFIG_SYS_PCI_64BIT
  367. pci_hose_write_config_dword(hose, dev, bar, (u32)(bar_value>>32));
  368. #else
  369. pci_hose_write_config_dword (hose, dev, bar, 0x00000000);
  370. #endif
  371. }
  372. }
  373. /* Configure Cache Line Size Register */
  374. pci_hose_write_config_byte (hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
  375. /* Configure Latency Timer */
  376. pci_hose_write_config_byte (hose, dev, PCI_LATENCY_TIMER, 0x80);
  377. /* Disable interrupt line, if device says it wants to use interrupts */
  378. pci_hose_read_config_byte (hose, dev, PCI_INTERRUPT_PIN, &pin);
  379. if (pin != 0) {
  380. pci_hose_write_config_byte (hose, dev, PCI_INTERRUPT_LINE, 0xff);
  381. }
  382. pci_hose_read_config_dword (hose, dev, PCI_COMMAND, &old_command);
  383. pci_hose_write_config_dword (hose, dev, PCI_COMMAND,
  384. (old_command & 0xffff0000) | command);
  385. return 0;
  386. }
  387. /*
  388. *
  389. */
  390. struct pci_config_table *pci_find_config(struct pci_controller *hose,
  391. unsigned short class,
  392. unsigned int vendor,
  393. unsigned int device,
  394. unsigned int bus,
  395. unsigned int dev,
  396. unsigned int func)
  397. {
  398. struct pci_config_table *table;
  399. for (table = hose->config_table; table && table->vendor; table++) {
  400. if ((table->vendor == PCI_ANY_ID || table->vendor == vendor) &&
  401. (table->device == PCI_ANY_ID || table->device == device) &&
  402. (table->class == PCI_ANY_ID || table->class == class) &&
  403. (table->bus == PCI_ANY_ID || table->bus == bus) &&
  404. (table->dev == PCI_ANY_ID || table->dev == dev) &&
  405. (table->func == PCI_ANY_ID || table->func == func)) {
  406. return table;
  407. }
  408. }
  409. return NULL;
  410. }
  411. void pci_cfgfunc_config_device(struct pci_controller *hose,
  412. pci_dev_t dev,
  413. struct pci_config_table *entry)
  414. {
  415. pci_hose_config_device(hose, dev, entry->priv[0], entry->priv[1], entry->priv[2]);
  416. }
  417. void pci_cfgfunc_do_nothing(struct pci_controller *hose,
  418. pci_dev_t dev, struct pci_config_table *entry)
  419. {
  420. }
  421. /*
  422. *
  423. */
  424. /* HJF: Changed this to return int. I think this is required
  425. * to get the correct result when scanning bridges
  426. */
  427. extern int pciauto_config_device(struct pci_controller *hose, pci_dev_t dev);
  428. extern void pciauto_config_init(struct pci_controller *hose);
  429. #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI_SCAN_SHOW)
  430. const char * pci_class_str(u8 class)
  431. {
  432. switch (class) {
  433. case PCI_CLASS_NOT_DEFINED:
  434. return "Build before PCI Rev2.0";
  435. break;
  436. case PCI_BASE_CLASS_STORAGE:
  437. return "Mass storage controller";
  438. break;
  439. case PCI_BASE_CLASS_NETWORK:
  440. return "Network controller";
  441. break;
  442. case PCI_BASE_CLASS_DISPLAY:
  443. return "Display controller";
  444. break;
  445. case PCI_BASE_CLASS_MULTIMEDIA:
  446. return "Multimedia device";
  447. break;
  448. case PCI_BASE_CLASS_MEMORY:
  449. return "Memory controller";
  450. break;
  451. case PCI_BASE_CLASS_BRIDGE:
  452. return "Bridge device";
  453. break;
  454. case PCI_BASE_CLASS_COMMUNICATION:
  455. return "Simple comm. controller";
  456. break;
  457. case PCI_BASE_CLASS_SYSTEM:
  458. return "Base system peripheral";
  459. break;
  460. case PCI_BASE_CLASS_INPUT:
  461. return "Input device";
  462. break;
  463. case PCI_BASE_CLASS_DOCKING:
  464. return "Docking station";
  465. break;
  466. case PCI_BASE_CLASS_PROCESSOR:
  467. return "Processor";
  468. break;
  469. case PCI_BASE_CLASS_SERIAL:
  470. return "Serial bus controller";
  471. break;
  472. case PCI_BASE_CLASS_INTELLIGENT:
  473. return "Intelligent controller";
  474. break;
  475. case PCI_BASE_CLASS_SATELLITE:
  476. return "Satellite controller";
  477. break;
  478. case PCI_BASE_CLASS_CRYPT:
  479. return "Cryptographic device";
  480. break;
  481. case PCI_BASE_CLASS_SIGNAL_PROCESSING:
  482. return "DSP";
  483. break;
  484. case PCI_CLASS_OTHERS:
  485. return "Does not fit any class";
  486. break;
  487. default:
  488. return "???";
  489. break;
  490. };
  491. }
  492. #endif /* CONFIG_CMD_PCI || CONFIG_PCI_SCAN_SHOW */
  493. int __pci_skip_dev(struct pci_controller *hose, pci_dev_t dev)
  494. {
  495. /*
  496. * Check if pci device should be skipped in configuration
  497. */
  498. if (dev == PCI_BDF(hose->first_busno, 0, 0)) {
  499. #if defined(CONFIG_PCI_CONFIG_HOST_BRIDGE) /* don't skip host bridge */
  500. /*
  501. * Only skip configuration if "pciconfighost" is not set
  502. */
  503. if (getenv("pciconfighost") == NULL)
  504. return 1;
  505. #else
  506. return 1;
  507. #endif
  508. }
  509. return 0;
  510. }
  511. int pci_skip_dev(struct pci_controller *hose, pci_dev_t dev)
  512. __attribute__((weak, alias("__pci_skip_dev")));
  513. #ifdef CONFIG_PCI_SCAN_SHOW
  514. int __pci_print_dev(struct pci_controller *hose, pci_dev_t dev)
  515. {
  516. if (dev == PCI_BDF(hose->first_busno, 0, 0))
  517. return 0;
  518. return 1;
  519. }
  520. int pci_print_dev(struct pci_controller *hose, pci_dev_t dev)
  521. __attribute__((weak, alias("__pci_print_dev")));
  522. #endif /* CONFIG_PCI_SCAN_SHOW */
  523. int pci_hose_scan_bus(struct pci_controller *hose, int bus)
  524. {
  525. unsigned int sub_bus, found_multi=0;
  526. unsigned short vendor, device, class;
  527. unsigned char header_type;
  528. struct pci_config_table *cfg;
  529. pci_dev_t dev;
  530. #ifdef CONFIG_PCI_SCAN_SHOW
  531. static int indent = 0;
  532. #endif
  533. sub_bus = bus;
  534. for (dev = PCI_BDF(bus,0,0);
  535. dev < PCI_BDF(bus,PCI_MAX_PCI_DEVICES-1,PCI_MAX_PCI_FUNCTIONS-1);
  536. dev += PCI_BDF(0,0,1)) {
  537. if (pci_skip_dev(hose, dev))
  538. continue;
  539. if (PCI_FUNC(dev) && !found_multi)
  540. continue;
  541. pci_hose_read_config_byte(hose, dev, PCI_HEADER_TYPE, &header_type);
  542. pci_hose_read_config_word(hose, dev, PCI_VENDOR_ID, &vendor);
  543. if (vendor == 0xffff || vendor == 0x0000)
  544. continue;
  545. if (!PCI_FUNC(dev))
  546. found_multi = header_type & 0x80;
  547. debug ("PCI Scan: Found Bus %d, Device %d, Function %d\n",
  548. PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev) );
  549. pci_hose_read_config_word(hose, dev, PCI_DEVICE_ID, &device);
  550. pci_hose_read_config_word(hose, dev, PCI_CLASS_DEVICE, &class);
  551. #ifdef CONFIG_PCI_SCAN_SHOW
  552. indent++;
  553. /* Print leading space, including bus indentation */
  554. printf("%*c", indent + 1, ' ');
  555. if (pci_print_dev(hose, dev)) {
  556. printf("%02x:%02x.%-*x - %04x:%04x - %s\n",
  557. PCI_BUS(dev), PCI_DEV(dev), 6 - indent, PCI_FUNC(dev),
  558. vendor, device, pci_class_str(class >> 8));
  559. }
  560. #endif
  561. cfg = pci_find_config(hose, class, vendor, device,
  562. PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev));
  563. if (cfg) {
  564. cfg->config_device(hose, dev, cfg);
  565. sub_bus = max(sub_bus, hose->current_busno);
  566. #ifdef CONFIG_PCI_PNP
  567. } else {
  568. int n = pciauto_config_device(hose, dev);
  569. sub_bus = max(sub_bus, n);
  570. #endif
  571. }
  572. #ifdef CONFIG_PCI_SCAN_SHOW
  573. indent--;
  574. #endif
  575. if (hose->fixup_irq)
  576. hose->fixup_irq(hose, dev);
  577. }
  578. return sub_bus;
  579. }
  580. int pci_hose_scan(struct pci_controller *hose)
  581. {
  582. #if defined(CONFIG_PCI_BOOTDELAY)
  583. static int pcidelay_done;
  584. char *s;
  585. int i;
  586. if (!pcidelay_done) {
  587. /* wait "pcidelay" ms (if defined)... */
  588. s = getenv("pcidelay");
  589. if (s) {
  590. int val = simple_strtoul(s, NULL, 10);
  591. for (i = 0; i < val; i++)
  592. udelay(1000);
  593. }
  594. pcidelay_done = 1;
  595. }
  596. #endif /* CONFIG_PCI_BOOTDELAY */
  597. /* Start scan at current_busno.
  598. * PCIe will start scan at first_busno+1.
  599. */
  600. /* For legacy support, ensure current>=first */
  601. if (hose->first_busno > hose->current_busno)
  602. hose->current_busno = hose->first_busno;
  603. #ifdef CONFIG_PCI_PNP
  604. pciauto_config_init(hose);
  605. #endif
  606. return pci_hose_scan_bus(hose, hose->current_busno);
  607. }
  608. void pci_init(void)
  609. {
  610. hose_head = NULL;
  611. /* now call board specific pci_init()... */
  612. pci_init_board();
  613. }