pci.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. /*
  2. * IXP PCI Init
  3. * (C) Copyright 2004 eslab.whut.edu.cn
  4. * Yue Hu(huyue_whut@yahoo.com.cn), Ligong Xue(lgxue@hotmail.com)
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #ifdef CONFIG_PCI
  26. #include <asm/processor.h>
  27. #include <asm/io.h>
  28. #include <pci.h>
  29. #include <asm/arch/ixp425.h>
  30. #include <asm/arch/ixp425pci.h>
  31. static void non_prefetch_read (unsigned int addr, unsigned int cmd,
  32. unsigned int *data);
  33. static void non_prefetch_write (unsigned int addr, unsigned int cmd,
  34. unsigned int data);
  35. static void configure_pins (void);
  36. static void sys_pci_gpio_clock_config (void);
  37. static void pci_bus_scan (void);
  38. static int pci_device_exists (unsigned int deviceNo);
  39. static void sys_pci_bar_info_get (unsigned int devnum, unsigned int bus,
  40. unsigned int dev, unsigned int func);
  41. static void sys_pci_device_bars_write (void);
  42. static void calc_bars (PciBar * Bars[], unsigned int nBars,
  43. unsigned int startAddr);
  44. #define PCI_MEMORY_BUS 0x00000000
  45. #define PCI_MEMORY_PHY 0x48000000
  46. #define PCI_MEMORY_SIZE 0x04000000
  47. #define PCI_MEM_BUS 0x40000000
  48. #define PCI_MEM_PHY 0x00000000
  49. #define PCI_MEM_SIZE 0x04000000
  50. #define PCI_IO_BUS 0x40000000
  51. #define PCI_IO_PHY 0x50000000
  52. #define PCI_IO_SIZE 0x10000000
  53. struct pci_controller hose;
  54. unsigned int nDevices;
  55. unsigned int nMBars;
  56. unsigned int nIOBars;
  57. PciBar *memBars[IXP425_PCI_MAX_BAR];
  58. PciBar *ioBars[IXP425_PCI_MAX_BAR];
  59. PciDevice devices[IXP425_PCI_MAX_FUNC_ON_BUS];
  60. int pci_read_config_dword (pci_dev_t dev, int where, unsigned int *val)
  61. {
  62. unsigned int retval;
  63. unsigned int addr;
  64. /*address bits 31:28 specify the device 10:8 specify the function */
  65. /*Set the address to be read */
  66. addr = BIT ((31 - dev)) | (where & ~3);
  67. non_prefetch_read (addr, NP_CMD_CONFIGREAD, &retval);
  68. *val = retval;
  69. return (OK);
  70. }
  71. int pci_read_config_word (pci_dev_t dev, int where, unsigned short *val)
  72. {
  73. unsigned int n;
  74. unsigned int retval;
  75. unsigned int addr;
  76. unsigned int byteEnables;
  77. n = where % 4;
  78. /*byte enables are 4 bits active low, the position of each
  79. bit maps to the byte that it enables */
  80. byteEnables =
  81. (~(BIT (n) | BIT ((n + 1)))) &
  82. IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
  83. byteEnables = byteEnables << PCI_NP_CBE_BESL;
  84. /*address bits 31:28 specify the device 10:8 specify the function */
  85. /*Set the address to be read */
  86. addr = BIT ((31 - dev)) | (where & ~3);
  87. non_prefetch_read (addr, byteEnables | NP_CMD_CONFIGREAD, &retval);
  88. /*Pick out the word we are interested in */
  89. *val = (retval >> (8 * n));
  90. return (OK);
  91. }
  92. int pci_read_config_byte (pci_dev_t dev, int where, unsigned char *val)
  93. {
  94. unsigned int retval;
  95. unsigned int n;
  96. unsigned int byteEnables;
  97. unsigned int addr;
  98. n = where % 4;
  99. /*byte enables are 4 bits, active low, the position of each
  100. bit maps to the byte that it enables */
  101. byteEnables = (~BIT (n)) & IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
  102. byteEnables = byteEnables << PCI_NP_CBE_BESL;
  103. /*address bits 31:28 specify the device, 10:8 specify the function */
  104. /*Set the address to be read */
  105. addr = BIT ((31 - dev)) | (where & ~3);
  106. non_prefetch_read (addr, byteEnables | NP_CMD_CONFIGREAD, &retval);
  107. /*Pick out the byte we are interested in */
  108. *val = (retval >> (8 * n));
  109. return (OK);
  110. }
  111. int pci_write_config_byte (pci_dev_t dev, int where, unsigned char val)
  112. {
  113. unsigned int addr;
  114. unsigned int byteEnables;
  115. unsigned int n;
  116. unsigned int ldata;
  117. n = where % 4;
  118. /*byte enables are 4 bits active low, the position of each
  119. bit maps to the byte that it enables */
  120. byteEnables = (~BIT (n)) & IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
  121. byteEnables = byteEnables << PCI_NP_CBE_BESL;
  122. ldata = val << (8 * n);
  123. /*address bits 31:28 specify the device 10:8 specify the function */
  124. /*Set the address to be written */
  125. addr = BIT ((31 - dev)) | (where & ~3);
  126. non_prefetch_write (addr, byteEnables | NP_CMD_CONFIGWRITE, ldata);
  127. return (OK);
  128. }
  129. int pci_write_config_word (pci_dev_t dev, int where, unsigned short val)
  130. {
  131. unsigned int addr;
  132. unsigned int byteEnables;
  133. unsigned int n;
  134. unsigned int ldata;
  135. n = where % 4;
  136. /*byte enables are 4 bits active low, the position of each
  137. bit maps to the byte that it enables */
  138. byteEnables =
  139. (~(BIT (n) | BIT ((n + 1)))) &
  140. IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
  141. byteEnables = byteEnables << PCI_NP_CBE_BESL;
  142. ldata = val << (8 * n);
  143. /*address bits 31:28 specify the device 10:8 specify the function */
  144. /*Set the address to be written */
  145. addr = BIT (31 - dev) | (where & ~3);
  146. non_prefetch_write (addr, byteEnables | NP_CMD_CONFIGWRITE, ldata);
  147. return (OK);
  148. }
  149. int pci_write_config_dword (pci_dev_t dev, int where, unsigned int val)
  150. {
  151. unsigned int addr;
  152. /*address bits 31:28 specify the device 10:8 specify the function */
  153. /*Set the address to be written */
  154. addr = BIT (31 - dev) | (where & ~3);
  155. non_prefetch_write (addr, NP_CMD_CONFIGWRITE, val);
  156. return (OK);
  157. }
  158. void non_prefetch_read (unsigned int addr,
  159. unsigned int cmd, unsigned int *data)
  160. {
  161. REG_WRITE (PCI_CSR_BASE, PCI_NP_AD_OFFSET, addr);
  162. /*set up and execute the read */
  163. REG_WRITE (PCI_CSR_BASE, PCI_NP_CBE_OFFSET, cmd);
  164. /*The result of the read is now in np_rdata */
  165. REG_READ (PCI_CSR_BASE, PCI_NP_RDATA_OFFSET, *data);
  166. return;
  167. }
  168. void non_prefetch_write (unsigned int addr,
  169. unsigned int cmd, unsigned int data)
  170. {
  171. REG_WRITE (PCI_CSR_BASE, PCI_NP_AD_OFFSET, addr);
  172. /*set up the write */
  173. REG_WRITE (PCI_CSR_BASE, PCI_NP_CBE_OFFSET, cmd);
  174. /*Execute the write by writing to NP_WDATA */
  175. REG_WRITE (PCI_CSR_BASE, PCI_NP_WDATA_OFFSET, data);
  176. return;
  177. }
  178. /*
  179. * PCI controller config registers are accessed through these functions
  180. * i.e. these allow us to set up our own BARs etc.
  181. */
  182. void crp_read (unsigned int offset, unsigned int *data)
  183. {
  184. REG_WRITE (PCI_CSR_BASE, PCI_CRP_AD_CBE_OFFSET, offset);
  185. REG_READ (PCI_CSR_BASE, PCI_CRP_RDATA_OFFSET, *data);
  186. }
  187. void crp_write (unsigned int offset, unsigned int data)
  188. {
  189. /*The CRP address register bit 16 indicates that we want to do a write */
  190. REG_WRITE (PCI_CSR_BASE, PCI_CRP_AD_CBE_OFFSET,
  191. PCI_CRP_WRITE | offset);
  192. REG_WRITE (PCI_CSR_BASE, PCI_CRP_WDATA_OFFSET, data);
  193. }
  194. /*struct pci_controller *hose*/
  195. void pci_ixp_init (struct pci_controller *hose)
  196. {
  197. unsigned int regval;
  198. hose->first_busno = 0;
  199. hose->last_busno = 0x00;
  200. /* System memory space */
  201. pci_set_region (hose->regions + 0,
  202. PCI_MEMORY_BUS,
  203. PCI_MEMORY_PHY, PCI_MEMORY_SIZE, PCI_REGION_MEMORY);
  204. /* PCI memory space */
  205. pci_set_region (hose->regions + 1,
  206. PCI_MEM_BUS,
  207. PCI_MEM_PHY, PCI_MEM_SIZE, PCI_REGION_MEM);
  208. /* PCI I/O space */
  209. pci_set_region (hose->regions + 2,
  210. PCI_IO_BUS, PCI_IO_PHY, PCI_IO_SIZE, PCI_REGION_IO);
  211. hose->region_count = 3;
  212. pci_register_hose (hose);
  213. /*
  214. ==========================================================
  215. Init IXP PCI
  216. ==========================================================
  217. */
  218. REG_READ (PCI_CSR_BASE, PCI_CSR_OFFSET, regval);
  219. regval |= 1 << 2;
  220. REG_WRITE (PCI_CSR_BASE, PCI_CSR_OFFSET, regval);
  221. configure_pins ();
  222. READ_GPIO_REG (IXP425_GPIO_GPOUTR, regval);
  223. WRITE_GPIO_REG (IXP425_GPIO_GPOUTR, regval & (~(1 << 13)));
  224. udelay (533);
  225. sys_pci_gpio_clock_config ();
  226. REG_WRITE (PCI_CSR_BASE, PCI_INTEN_OFFSET, 0);
  227. udelay (100);
  228. READ_GPIO_REG (IXP425_GPIO_GPOUTR, regval);
  229. WRITE_GPIO_REG (IXP425_GPIO_GPOUTR, regval | (1 << 13));
  230. udelay (533);
  231. crp_write (PCI_CFG_BASE_ADDRESS_0, IXP425_PCI_BAR_0_DEFAULT);
  232. crp_write (PCI_CFG_BASE_ADDRESS_1, IXP425_PCI_BAR_1_DEFAULT);
  233. crp_write (PCI_CFG_BASE_ADDRESS_2, IXP425_PCI_BAR_2_DEFAULT);
  234. crp_write (PCI_CFG_BASE_ADDRESS_3, IXP425_PCI_BAR_3_DEFAULT);
  235. crp_write (PCI_CFG_BASE_ADDRESS_4, IXP425_PCI_BAR_4_DEFAULT);
  236. crp_write (PCI_CFG_BASE_ADDRESS_5, IXP425_PCI_BAR_5_DEFAULT);
  237. /*Setup PCI-AHB and AHB-PCI address mappings */
  238. REG_WRITE (PCI_CSR_BASE, PCI_AHBMEMBASE_OFFSET,
  239. IXP425_PCI_AHBMEMBASE_DEFAULT);
  240. REG_WRITE (PCI_CSR_BASE, PCI_AHBIOBASE_OFFSET,
  241. IXP425_PCI_AHBIOBASE_DEFAULT);
  242. REG_WRITE (PCI_CSR_BASE, PCI_PCIMEMBASE_OFFSET,
  243. IXP425_PCI_PCIMEMBASE_DEFAULT);
  244. crp_write (PCI_CFG_SUB_VENDOR_ID, IXP425_PCI_SUB_VENDOR_SYSTEM);
  245. REG_READ (PCI_CSR_BASE, PCI_CSR_OFFSET, regval);
  246. regval |= PCI_CSR_IC | PCI_CSR_ABE | PCI_CSR_PDS;
  247. REG_WRITE (PCI_CSR_BASE, PCI_CSR_OFFSET, regval);
  248. crp_write (PCI_CFG_COMMAND, PCI_CFG_CMD_MAE | PCI_CFG_CMD_BME);
  249. udelay (1000);
  250. pci_write_config_word (0, PCI_CFG_COMMAND, INITIAL_PCI_CMD);
  251. REG_WRITE (PCI_CSR_BASE, PCI_ISR_OFFSET, PCI_ISR_PSE
  252. | PCI_ISR_PFE | PCI_ISR_PPE | PCI_ISR_AHBE);
  253. #ifdef CONFIG_PCI_SCAN_SHOW
  254. printf ("Device bus dev func deviceID vendorID \n");
  255. #endif
  256. pci_bus_scan ();
  257. }
  258. void configure_pins (void)
  259. {
  260. unsigned int regval;
  261. /* Disable clock on GPIO PIN 14 */
  262. READ_GPIO_REG (IXP425_GPIO_GPCLKR, regval);
  263. WRITE_GPIO_REG (IXP425_GPIO_GPCLKR, regval & (~(1 << 8)));
  264. READ_GPIO_REG (IXP425_GPIO_GPCLKR, regval);
  265. READ_GPIO_REG (IXP425_GPIO_GPOER, regval);
  266. WRITE_GPIO_REG (IXP425_GPIO_GPOER,
  267. (((~(3 << 13)) & regval) | (0xf << 8)));
  268. READ_GPIO_REG (IXP425_GPIO_GPOER, regval);
  269. READ_GPIO_REG (IXP425_GPIO_GPIT2R, regval);
  270. WRITE_GPIO_REG (IXP425_GPIO_GPIT2R,
  271. (regval &
  272. ((0x1 << 9) | (0x1 << 6) | (0x1 << 3) | 0x1)));
  273. READ_GPIO_REG (IXP425_GPIO_GPIT2R, regval);
  274. READ_GPIO_REG (IXP425_GPIO_GPISR, regval);
  275. WRITE_GPIO_REG (IXP425_GPIO_GPISR, (regval | (0xf << 8)));
  276. READ_GPIO_REG (IXP425_GPIO_GPISR, regval);
  277. }
  278. void sys_pci_gpio_clock_config (void)
  279. {
  280. unsigned int regval;
  281. READ_GPIO_REG (IXP425_GPIO_GPCLKR, regval);
  282. regval |= 0x1 << 4;
  283. WRITE_GPIO_REG (IXP425_GPIO_GPCLKR, regval);
  284. READ_GPIO_REG (IXP425_GPIO_GPCLKR, regval);
  285. regval |= 0x1 << 8;
  286. WRITE_GPIO_REG (IXP425_GPIO_GPCLKR, regval);
  287. }
  288. void pci_bus_scan (void)
  289. {
  290. unsigned int bus = 0, dev, func = 0;
  291. unsigned short data16;
  292. unsigned int data32;
  293. unsigned char intPin;
  294. /* Assign first device to ourselves */
  295. devices[0].bus = 0;
  296. devices[0].device = 0;
  297. devices[0].func = 0;
  298. crp_read (PCI_CFG_VENDOR_ID, &data32);
  299. devices[0].vendor_id = data32 & IXP425_PCI_BOTTOM_WORD_OF_LONG_MASK;
  300. devices[0].device_id = data32 >> 16;
  301. devices[0].error = FALSE;
  302. devices[0].bar[NO_BAR].size = 0; /*dummy - required */
  303. nDevices = 1;
  304. nMBars = 0;
  305. nIOBars = 0;
  306. for (dev = 0; dev < IXP425_PCI_MAX_DEV; dev++) {
  307. /*Check whether a device is present */
  308. if (pci_device_exists (dev) != TRUE) {
  309. /*Clear error bits in ISR, write 1 to clear */
  310. REG_WRITE (PCI_CSR_BASE, PCI_ISR_OFFSET, PCI_ISR_PSE
  311. | PCI_ISR_PFE | PCI_ISR_PPE |
  312. PCI_ISR_AHBE);
  313. continue;
  314. }
  315. /*A device is present, add an entry to the array */
  316. devices[nDevices].bus = bus;
  317. devices[nDevices].device = dev;
  318. devices[nDevices].func = func;
  319. pci_read_config_word (dev, PCI_CFG_VENDOR_ID, &data16);
  320. devices[nDevices].vendor_id = data16;
  321. pci_read_config_word (dev, PCI_CFG_DEVICE_ID, &data16);
  322. devices[nDevices].device_id = data16;
  323. /*The device is functioning correctly, set error to FALSE */
  324. devices[nDevices].error = FALSE;
  325. /*Figure out what BARs are on this device */
  326. sys_pci_bar_info_get (nDevices, bus, dev, func);
  327. /*Figure out what INTX# line the card uses */
  328. pci_read_config_byte (dev, PCI_CFG_DEV_INT_PIN, &intPin);
  329. /*assign the appropriate irq line */
  330. if (intPin > PCI_IRQ_LINES) {
  331. devices[nDevices].error = TRUE;
  332. } else if (intPin != 0) {
  333. /*This device uses an interrupt line */
  334. /*devices[nDevices].irq = ixp425PciIntTranslate[dev][intPin-1]; */
  335. devices[nDevices].irq = intPin;
  336. }
  337. #ifdef CONFIG_PCI_SCAN_SHOW
  338. printf ("%06d %03d %03d %04d %08d %08x\n", nDevices,
  339. devices[nDevices].vendor_id);
  340. #endif
  341. nDevices++;
  342. }
  343. calc_bars (memBars, nMBars, IXP425_PCI_BAR_MEM_BASE);
  344. sys_pci_device_bars_write ();
  345. REG_WRITE (PCI_CSR_BASE, PCI_ISR_OFFSET, PCI_ISR_PSE
  346. | PCI_ISR_PFE | PCI_ISR_PPE | PCI_ISR_AHBE);
  347. }
  348. void sys_pci_bar_info_get (unsigned int devnum,
  349. unsigned int bus,
  350. unsigned int dev, unsigned int func)
  351. {
  352. unsigned int data32;
  353. unsigned int tmp;
  354. unsigned int size;
  355. pci_write_config_dword (devnum,
  356. PCI_CFG_BASE_ADDRESS_0, IXP425_PCI_BAR_QUERY);
  357. pci_read_config_dword (devnum, PCI_CFG_BASE_ADDRESS_0, &data32);
  358. devices[devnum].bar[0].address = (data32 & 1);
  359. if (data32 & 1) {
  360. /* IO space */
  361. tmp = data32 & ~0x3;
  362. size = ~(tmp - 1);
  363. devices[devnum].bar[0].size = size;
  364. if (nIOBars < IXP425_PCI_MAX_BAR) {
  365. ioBars[nIOBars++] = &devices[devnum].bar[0];
  366. }
  367. } else {
  368. /* Mem space */
  369. tmp = data32 & ~IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
  370. size = ~(tmp - 1);
  371. devices[devnum].bar[0].size = size;
  372. if (nMBars < IXP425_PCI_MAX_BAR) {
  373. memBars[nMBars++] = &devices[devnum].bar[0];
  374. } else {
  375. devices[devnum].error = TRUE;
  376. }
  377. }
  378. devices[devnum].bar[1].size = 0;
  379. }
  380. void sortBars (PciBar * Bars[], unsigned int nBars)
  381. {
  382. unsigned int i, j;
  383. PciBar *tmp;
  384. if (nBars == 0) {
  385. return;
  386. }
  387. /* Sort biggest to smallest */
  388. for (i = 0; i < nBars - 1; i++) {
  389. for (j = i + 1; j < nBars; j++) {
  390. if (Bars[j]->size > Bars[i]->size) {
  391. /* swap them */
  392. tmp = Bars[i];
  393. Bars[i] = Bars[j];
  394. Bars[j] = tmp;
  395. }
  396. }
  397. }
  398. }
  399. void calc_bars (PciBar * Bars[], unsigned int nBars, unsigned int startAddr)
  400. {
  401. unsigned int i;
  402. if (nBars == 0) {
  403. return;
  404. }
  405. for (i = 0; i < nBars; i++) {
  406. Bars[i]->address |= startAddr;
  407. startAddr += Bars[i]->size;
  408. }
  409. }
  410. void sys_pci_device_bars_write (void)
  411. {
  412. unsigned int i;
  413. int addr;
  414. for (i = 1; i < nDevices; i++) {
  415. if (devices[i].error) {
  416. continue;
  417. }
  418. pci_write_config_dword (devices[i].device,
  419. PCI_CFG_BASE_ADDRESS_0,
  420. devices[i].bar[0].address);
  421. addr = BIT (31 - devices[i].device) |
  422. (0 << PCI_NP_AD_FUNCSL) |
  423. (PCI_CFG_BASE_ADDRESS_0 & ~3);
  424. pci_write_config_dword (devices[i].device,
  425. PCI_CFG_DEV_INT_LINE, devices[i].irq);
  426. pci_write_config_word (devices[i].device,
  427. PCI_CFG_COMMAND, INITIAL_PCI_CMD);
  428. }
  429. }
  430. int pci_device_exists (unsigned int deviceNo)
  431. {
  432. unsigned int vendorId;
  433. unsigned int regval;
  434. pci_read_config_dword (deviceNo, PCI_CFG_VENDOR_ID, &vendorId);
  435. /* There are two ways to find out an empty device.
  436. * 1. check Master Abort bit after the access.
  437. * 2. check whether the vendor id read back is 0x0.
  438. */
  439. REG_READ (PCI_CSR_BASE, PCI_ISR_OFFSET, regval);
  440. if ((vendorId != 0x0) && ((regval & PCI_ISR_PFE) == 0)) {
  441. return TRUE;
  442. }
  443. /*no device present, make sure that the master abort bit is reset */
  444. REG_WRITE (PCI_CSR_BASE, PCI_ISR_OFFSET, PCI_ISR_PFE);
  445. return FALSE;
  446. }
  447. pci_dev_t pci_find_devices (struct pci_device_id * ids, int devNo)
  448. {
  449. unsigned int i;
  450. unsigned int devdidvid;
  451. unsigned int didvid;
  452. unsigned int vendorId, deviceId;
  453. vendorId = ids->vendor;
  454. deviceId = ids->device;
  455. didvid = ((deviceId << 16) & IXP425_PCI_TOP_WORD_OF_LONG_MASK) |
  456. (vendorId & IXP425_PCI_BOTTOM_WORD_OF_LONG_MASK);
  457. for (i = devNo + 1; i < nDevices; i++) {
  458. pci_read_config_dword (devices[i].device, PCI_CFG_VENDOR_ID,
  459. &devdidvid);
  460. if (devdidvid == didvid) {
  461. return devices[i].device;
  462. }
  463. }
  464. return -1;
  465. }
  466. #endif /* CONFIG_PCI */