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