pci_bus.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. /*-
  2. * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  3. *
  4. * Copyright (c) 1997, Stefan Esser <se@freebsd.org>
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice unmodified, this list of conditions, and the following
  12. * disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #include <sys/cdefs.h>
  29. __FBSDID("$FreeBSD$");
  30. #include "opt_cpu.h"
  31. #include <sys/param.h>
  32. #include <sys/systm.h>
  33. #include <sys/bus.h>
  34. #include <sys/kernel.h>
  35. #include <sys/malloc.h>
  36. #include <sys/module.h>
  37. #include <sys/rman.h>
  38. #include <sys/sysctl.h>
  39. #include <dev/pci/pcivar.h>
  40. #include <dev/pci/pcireg.h>
  41. #include <dev/pci/pcib_private.h>
  42. #include <isa/isavar.h>
  43. #ifdef CPU_ELAN
  44. #include <machine/md_var.h>
  45. #endif
  46. #include <x86/legacyvar.h>
  47. #include <machine/pci_cfgreg.h>
  48. #include <machine/resource.h>
  49. #include "pcib_if.h"
  50. int
  51. legacy_pcib_maxslots(device_t dev)
  52. {
  53. return 31;
  54. }
  55. /* read configuration space register */
  56. uint32_t
  57. legacy_pcib_read_config(device_t dev, u_int bus, u_int slot, u_int func,
  58. u_int reg, int bytes)
  59. {
  60. return(pci_cfgregread(bus, slot, func, reg, bytes));
  61. }
  62. /* write configuration space register */
  63. void
  64. legacy_pcib_write_config(device_t dev, u_int bus, u_int slot, u_int func,
  65. u_int reg, uint32_t data, int bytes)
  66. {
  67. pci_cfgregwrite(bus, slot, func, reg, data, bytes);
  68. }
  69. /* route interrupt */
  70. static int
  71. legacy_pcib_route_interrupt(device_t pcib, device_t dev, int pin)
  72. {
  73. #ifdef __HAVE_PIR
  74. return (pci_pir_route_interrupt(pci_get_bus(dev), pci_get_slot(dev),
  75. pci_get_function(dev), pin));
  76. #else
  77. /* No routing possible */
  78. return (PCI_INVALID_IRQ);
  79. #endif
  80. }
  81. /* Pass MSI requests up to the nexus. */
  82. int
  83. legacy_pcib_alloc_msi(device_t pcib, device_t dev, int count, int maxcount,
  84. int *irqs)
  85. {
  86. device_t bus;
  87. bus = device_get_parent(pcib);
  88. return (PCIB_ALLOC_MSI(device_get_parent(bus), dev, count, maxcount,
  89. irqs));
  90. }
  91. int
  92. legacy_pcib_alloc_msix(device_t pcib, device_t dev, int *irq)
  93. {
  94. device_t bus;
  95. bus = device_get_parent(pcib);
  96. return (PCIB_ALLOC_MSIX(device_get_parent(bus), dev, irq));
  97. }
  98. int
  99. legacy_pcib_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr,
  100. uint32_t *data)
  101. {
  102. device_t bus, hostb;
  103. int error, func, slot;
  104. bus = device_get_parent(pcib);
  105. error = PCIB_MAP_MSI(device_get_parent(bus), dev, irq, addr, data);
  106. if (error)
  107. return (error);
  108. slot = legacy_get_pcislot(pcib);
  109. func = legacy_get_pcifunc(pcib);
  110. if (slot == -1 || func == -1)
  111. return (0);
  112. hostb = pci_find_bsf(0, slot, func);
  113. KASSERT(hostb != NULL, ("%s: missing hostb for 0:%d:%d", __func__,
  114. slot, func));
  115. pci_ht_map_msi(hostb, *addr);
  116. return (0);
  117. }
  118. static const char *
  119. legacy_pcib_is_host_bridge(int bus, int slot, int func,
  120. uint32_t id, uint8_t class, uint8_t subclass,
  121. uint8_t *busnum)
  122. {
  123. #ifdef __i386__
  124. const char *s = NULL;
  125. static uint8_t pxb[4]; /* hack for 450nx */
  126. *busnum = 0;
  127. switch (id) {
  128. case 0x12258086:
  129. s = "Intel 824?? host to PCI bridge";
  130. /* XXX This is a guess */
  131. /* *busnum = legacy_pcib_read_config(0, bus, slot, func, 0x41, 1); */
  132. *busnum = bus;
  133. break;
  134. case 0x71208086:
  135. s = "Intel 82810 (i810 GMCH) Host To Hub bridge";
  136. break;
  137. case 0x71228086:
  138. s = "Intel 82810-DC100 (i810-DC100 GMCH) Host To Hub bridge";
  139. break;
  140. case 0x71248086:
  141. s = "Intel 82810E (i810E GMCH) Host To Hub bridge";
  142. break;
  143. case 0x11308086:
  144. s = "Intel 82815 (i815 GMCH) Host To Hub bridge";
  145. break;
  146. case 0x71808086:
  147. s = "Intel 82443LX (440 LX) host to PCI bridge";
  148. break;
  149. case 0x71908086:
  150. s = "Intel 82443BX (440 BX) host to PCI bridge";
  151. break;
  152. case 0x71928086:
  153. s = "Intel 82443BX host to PCI bridge (AGP disabled)";
  154. break;
  155. case 0x71948086:
  156. s = "Intel 82443MX host to PCI bridge";
  157. break;
  158. case 0x71a08086:
  159. s = "Intel 82443GX host to PCI bridge";
  160. break;
  161. case 0x71a18086:
  162. s = "Intel 82443GX host to AGP bridge";
  163. break;
  164. case 0x71a28086:
  165. s = "Intel 82443GX host to PCI bridge (AGP disabled)";
  166. break;
  167. case 0x84c48086:
  168. s = "Intel 82454KX/GX (Orion) host to PCI bridge";
  169. *busnum = legacy_pcib_read_config(0, bus, slot, func, 0x4a, 1);
  170. break;
  171. case 0x84ca8086:
  172. /*
  173. * For the 450nx chipset, there is a whole bundle of
  174. * things pretending to be host bridges. The MIOC will
  175. * be seen first and isn't really a pci bridge (the
  176. * actual buses are attached to the PXB's). We need to
  177. * read the registers of the MIOC to figure out the
  178. * bus numbers for the PXB channels.
  179. *
  180. * Since the MIOC doesn't have a pci bus attached, we
  181. * pretend it wasn't there.
  182. */
  183. pxb[0] = legacy_pcib_read_config(0, bus, slot, func,
  184. 0xd0, 1); /* BUSNO[0] */
  185. pxb[1] = legacy_pcib_read_config(0, bus, slot, func,
  186. 0xd1, 1) + 1; /* SUBA[0]+1 */
  187. pxb[2] = legacy_pcib_read_config(0, bus, slot, func,
  188. 0xd3, 1); /* BUSNO[1] */
  189. pxb[3] = legacy_pcib_read_config(0, bus, slot, func,
  190. 0xd4, 1) + 1; /* SUBA[1]+1 */
  191. return NULL;
  192. case 0x84cb8086:
  193. switch (slot) {
  194. case 0x12:
  195. s = "Intel 82454NX PXB#0, Bus#A";
  196. *busnum = pxb[0];
  197. break;
  198. case 0x13:
  199. s = "Intel 82454NX PXB#0, Bus#B";
  200. *busnum = pxb[1];
  201. break;
  202. case 0x14:
  203. s = "Intel 82454NX PXB#1, Bus#A";
  204. *busnum = pxb[2];
  205. break;
  206. case 0x15:
  207. s = "Intel 82454NX PXB#1, Bus#B";
  208. *busnum = pxb[3];
  209. break;
  210. }
  211. break;
  212. case 0x1A308086:
  213. s = "Intel 82845 Host to PCI bridge";
  214. break;
  215. /* AMD -- vendor 0x1022 */
  216. case 0x30001022:
  217. s = "AMD Elan SC520 host to PCI bridge";
  218. #ifdef CPU_ELAN
  219. init_AMD_Elan_sc520();
  220. #else
  221. printf(
  222. "*** WARNING: missing CPU_ELAN -- timekeeping may be wrong\n");
  223. #endif
  224. break;
  225. case 0x70061022:
  226. s = "AMD-751 host to PCI bridge";
  227. break;
  228. case 0x700e1022:
  229. s = "AMD-761 host to PCI bridge";
  230. break;
  231. /* SiS -- vendor 0x1039 */
  232. case 0x04961039:
  233. s = "SiS 85c496";
  234. break;
  235. case 0x04061039:
  236. s = "SiS 85c501";
  237. break;
  238. case 0x06011039:
  239. s = "SiS 85c601";
  240. break;
  241. case 0x55911039:
  242. s = "SiS 5591 host to PCI bridge";
  243. break;
  244. case 0x00011039:
  245. s = "SiS 5591 host to AGP bridge";
  246. break;
  247. /* VLSI -- vendor 0x1004 */
  248. case 0x00051004:
  249. s = "VLSI 82C592 Host to PCI bridge";
  250. break;
  251. /* XXX Here is MVP3, I got the datasheet but NO M/B to test it */
  252. /* totally. Please let me know if anything wrong. -F */
  253. /* XXX need info on the MVP3 -- any takers? */
  254. case 0x05981106:
  255. s = "VIA 82C598MVP (Apollo MVP3) host bridge";
  256. break;
  257. /* AcerLabs -- vendor 0x10b9 */
  258. /* Funny : The datasheet told me vendor id is "10b8",sub-vendor */
  259. /* id is '10b9" but the register always shows "10b9". -Foxfair */
  260. case 0x154110b9:
  261. s = "AcerLabs M1541 (Aladdin-V) PCI host bridge";
  262. break;
  263. /* OPTi -- vendor 0x1045 */
  264. case 0xc7011045:
  265. s = "OPTi 82C700 host to PCI bridge";
  266. break;
  267. case 0xc8221045:
  268. s = "OPTi 82C822 host to PCI Bridge";
  269. break;
  270. /* ServerWorks -- vendor 0x1166 */
  271. case 0x00051166:
  272. s = "ServerWorks NB6536 2.0HE host to PCI bridge";
  273. *busnum = legacy_pcib_read_config(0, bus, slot, func, 0x44, 1);
  274. break;
  275. case 0x00061166:
  276. /* FALLTHROUGH */
  277. case 0x00081166:
  278. /* FALLTHROUGH */
  279. case 0x02011166:
  280. /* FALLTHROUGH */
  281. case 0x010f1014: /* IBM re-badged ServerWorks chipset */
  282. s = "ServerWorks host to PCI bridge";
  283. *busnum = legacy_pcib_read_config(0, bus, slot, func, 0x44, 1);
  284. break;
  285. case 0x00091166:
  286. s = "ServerWorks NB6635 3.0LE host to PCI bridge";
  287. *busnum = legacy_pcib_read_config(0, bus, slot, func, 0x44, 1);
  288. break;
  289. case 0x00101166:
  290. s = "ServerWorks CIOB30 host to PCI bridge";
  291. *busnum = legacy_pcib_read_config(0, bus, slot, func, 0x44, 1);
  292. break;
  293. case 0x00111166:
  294. /* FALLTHROUGH */
  295. case 0x03021014: /* IBM re-badged ServerWorks chipset */
  296. s = "ServerWorks CMIC-HE host to PCI-X bridge";
  297. *busnum = legacy_pcib_read_config(0, bus, slot, func, 0x44, 1);
  298. break;
  299. /* XXX unknown chipset, but working */
  300. case 0x00171166:
  301. /* FALLTHROUGH */
  302. case 0x01011166:
  303. case 0x01101166:
  304. case 0x02251166:
  305. s = "ServerWorks host to PCI bridge(unknown chipset)";
  306. *busnum = legacy_pcib_read_config(0, bus, slot, func, 0x44, 1);
  307. break;
  308. /* Compaq/HP -- vendor 0x0e11 */
  309. case 0x60100e11:
  310. s = "Compaq/HP Model 6010 HotPlug PCI Bridge";
  311. *busnum = legacy_pcib_read_config(0, bus, slot, func, 0xc8, 1);
  312. break;
  313. /* Integrated Micro Solutions -- vendor 0x10e0 */
  314. case 0x884910e0:
  315. s = "Integrated Micro Solutions VL Bridge";
  316. break;
  317. default:
  318. if (class == PCIC_BRIDGE && subclass == PCIS_BRIDGE_HOST)
  319. s = "Host to PCI bridge";
  320. break;
  321. }
  322. return s;
  323. #else
  324. const char *s = NULL;
  325. *busnum = 0;
  326. if (class == PCIC_BRIDGE && subclass == PCIS_BRIDGE_HOST)
  327. s = "Host to PCI bridge";
  328. return s;
  329. #endif
  330. }
  331. /*
  332. * Scan the first pci bus for host-pci bridges and add pcib instances
  333. * to the nexus for each bridge.
  334. */
  335. static void
  336. legacy_pcib_identify(driver_t *driver, device_t parent)
  337. {
  338. int bus, slot, func;
  339. uint8_t hdrtype;
  340. int found = 0;
  341. int pcifunchigh;
  342. int found824xx = 0;
  343. int found_orion = 0;
  344. device_t child;
  345. devclass_t pci_devclass;
  346. if (pci_cfgregopen() == 0)
  347. return;
  348. /*
  349. * Check to see if we haven't already had a PCI bus added
  350. * via some other means. If we have, bail since otherwise
  351. * we're going to end up duplicating it.
  352. */
  353. if ((pci_devclass = devclass_find("pci")) &&
  354. devclass_get_device(pci_devclass, 0))
  355. return;
  356. bus = 0;
  357. retry:
  358. for (slot = 0; slot <= PCI_SLOTMAX; slot++) {
  359. func = 0;
  360. hdrtype = legacy_pcib_read_config(0, bus, slot, func,
  361. PCIR_HDRTYPE, 1);
  362. /*
  363. * When enumerating bus devices, the standard says that
  364. * one should check the header type and ignore the slots whose
  365. * header types that the software doesn't know about. We use
  366. * this to filter out devices.
  367. */
  368. if ((hdrtype & PCIM_HDRTYPE) > PCI_MAXHDRTYPE)
  369. continue;
  370. if ((hdrtype & PCIM_MFDEV) &&
  371. (!found_orion || hdrtype != 0xff))
  372. pcifunchigh = PCI_FUNCMAX;
  373. else
  374. pcifunchigh = 0;
  375. for (func = 0; func <= pcifunchigh; func++) {
  376. /*
  377. * Read the IDs and class from the device.
  378. */
  379. uint32_t id;
  380. uint8_t class, subclass, busnum;
  381. const char *s;
  382. device_t *devs;
  383. int ndevs, i;
  384. id = legacy_pcib_read_config(0, bus, slot, func,
  385. PCIR_DEVVENDOR, 4);
  386. if (id == -1)
  387. continue;
  388. class = legacy_pcib_read_config(0, bus, slot, func,
  389. PCIR_CLASS, 1);
  390. subclass = legacy_pcib_read_config(0, bus, slot, func,
  391. PCIR_SUBCLASS, 1);
  392. s = legacy_pcib_is_host_bridge(bus, slot, func,
  393. id, class, subclass,
  394. &busnum);
  395. if (s == NULL)
  396. continue;
  397. /*
  398. * Check to see if the physical bus has already
  399. * been seen. Eg: hybrid 32 and 64 bit host
  400. * bridges to the same logical bus.
  401. */
  402. if (device_get_children(parent, &devs, &ndevs) == 0) {
  403. for (i = 0; s != NULL && i < ndevs; i++) {
  404. if (strcmp(device_get_name(devs[i]),
  405. "pcib") != 0)
  406. continue;
  407. if (legacy_get_pcibus(devs[i]) == busnum)
  408. s = NULL;
  409. }
  410. free(devs, M_TEMP);
  411. }
  412. if (s == NULL)
  413. continue;
  414. /*
  415. * Add at priority 100 to make sure we
  416. * go after any motherboard resources
  417. */
  418. child = BUS_ADD_CHILD(parent, 100,
  419. "pcib", busnum);
  420. device_set_desc(child, s);
  421. legacy_set_pcibus(child, busnum);
  422. legacy_set_pcislot(child, slot);
  423. legacy_set_pcifunc(child, func);
  424. found = 1;
  425. if (id == 0x12258086)
  426. found824xx = 1;
  427. if (id == 0x84c48086)
  428. found_orion = 1;
  429. }
  430. }
  431. if (found824xx && bus == 0) {
  432. bus++;
  433. goto retry;
  434. }
  435. /*
  436. * Make sure we add at least one bridge since some old
  437. * hardware doesn't actually have a host-pci bridge device.
  438. * Note that pci_cfgregopen() thinks we have PCI devices..
  439. */
  440. if (!found) {
  441. if (bootverbose)
  442. printf(
  443. "legacy_pcib_identify: no bridge found, adding pcib0 anyway\n");
  444. child = BUS_ADD_CHILD(parent, 100, "pcib", 0);
  445. legacy_set_pcibus(child, 0);
  446. }
  447. }
  448. static int
  449. legacy_pcib_probe(device_t dev)
  450. {
  451. if (pci_cfgregopen() == 0)
  452. return ENXIO;
  453. return -100;
  454. }
  455. static int
  456. legacy_pcib_attach(device_t dev)
  457. {
  458. #ifdef __HAVE_PIR
  459. device_t pir;
  460. #endif
  461. int bus;
  462. bus = pcib_get_bus(dev);
  463. #ifdef __HAVE_PIR
  464. /*
  465. * Look for a PCI BIOS interrupt routing table as that will be
  466. * our method of routing interrupts if we have one.
  467. */
  468. if (pci_pir_probe(bus, 0)) {
  469. pir = BUS_ADD_CHILD(device_get_parent(dev), 0, "pir", 0);
  470. if (pir != NULL)
  471. device_probe_and_attach(pir);
  472. }
  473. #endif
  474. device_add_child(dev, "pci", -1);
  475. return bus_generic_attach(dev);
  476. }
  477. int
  478. legacy_pcib_read_ivar(device_t dev, device_t child, int which,
  479. uintptr_t *result)
  480. {
  481. switch (which) {
  482. case PCIB_IVAR_DOMAIN:
  483. *result = 0;
  484. return 0;
  485. case PCIB_IVAR_BUS:
  486. *result = legacy_get_pcibus(dev);
  487. return 0;
  488. }
  489. return ENOENT;
  490. }
  491. int
  492. legacy_pcib_write_ivar(device_t dev, device_t child, int which,
  493. uintptr_t value)
  494. {
  495. switch (which) {
  496. case PCIB_IVAR_DOMAIN:
  497. return EINVAL;
  498. case PCIB_IVAR_BUS:
  499. legacy_set_pcibus(dev, value);
  500. return 0;
  501. }
  502. return ENOENT;
  503. }
  504. /*
  505. * Helper routine for x86 Host-PCI bridge driver resource allocation.
  506. * This is used to adjust the start address of wildcard allocation
  507. * requests to avoid low addresses that are known to be problematic.
  508. *
  509. * If no memory preference is given, use upper 32MB slot most BIOSes
  510. * use for their memory window. This is typically only used on older
  511. * laptops that don't have PCI buses behind a PCI bridge, so assuming
  512. * > 32MB is likely OK.
  513. *
  514. * However, this can cause problems for other chipsets, so we make
  515. * this tunable by hw.pci.host_mem_start.
  516. */
  517. SYSCTL_DECL(_hw_pci);
  518. static unsigned long host_mem_start = 0x80000000;
  519. SYSCTL_ULONG(_hw_pci, OID_AUTO, host_mem_start, CTLFLAG_RDTUN, &host_mem_start,
  520. 0, "Limit the host bridge memory to being above this address.");
  521. rman_res_t
  522. hostb_alloc_start(int type, rman_res_t start, rman_res_t end, rman_res_t count)
  523. {
  524. if (start + count - 1 != end) {
  525. if (type == SYS_RES_MEMORY && start < host_mem_start)
  526. start = host_mem_start;
  527. if (type == SYS_RES_IOPORT && start < 0x1000)
  528. start = 0x1000;
  529. }
  530. return (start);
  531. }
  532. struct resource *
  533. legacy_pcib_alloc_resource(device_t dev, device_t child, int type, int *rid,
  534. rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
  535. {
  536. #if defined(NEW_PCIB) && defined(PCI_RES_BUS)
  537. if (type == PCI_RES_BUS)
  538. return (pci_domain_alloc_bus(0, child, rid, start, end, count,
  539. flags));
  540. #endif
  541. start = hostb_alloc_start(type, start, end, count);
  542. return (bus_generic_alloc_resource(dev, child, type, rid, start, end,
  543. count, flags));
  544. }
  545. #if defined(NEW_PCIB) && defined(PCI_RES_BUS)
  546. int
  547. legacy_pcib_adjust_resource(device_t dev, device_t child, int type,
  548. struct resource *r, rman_res_t start, rman_res_t end)
  549. {
  550. if (type == PCI_RES_BUS)
  551. return (pci_domain_adjust_bus(0, child, r, start, end));
  552. return (bus_generic_adjust_resource(dev, child, type, r, start, end));
  553. }
  554. int
  555. legacy_pcib_release_resource(device_t dev, device_t child, int type, int rid,
  556. struct resource *r)
  557. {
  558. if (type == PCI_RES_BUS)
  559. return (pci_domain_release_bus(0, child, rid, r));
  560. return (bus_generic_release_resource(dev, child, type, rid, r));
  561. }
  562. #endif
  563. static device_method_t legacy_pcib_methods[] = {
  564. /* Device interface */
  565. DEVMETHOD(device_identify, legacy_pcib_identify),
  566. DEVMETHOD(device_probe, legacy_pcib_probe),
  567. DEVMETHOD(device_attach, legacy_pcib_attach),
  568. DEVMETHOD(device_shutdown, bus_generic_shutdown),
  569. DEVMETHOD(device_suspend, bus_generic_suspend),
  570. DEVMETHOD(device_resume, bus_generic_resume),
  571. /* Bus interface */
  572. DEVMETHOD(bus_read_ivar, legacy_pcib_read_ivar),
  573. DEVMETHOD(bus_write_ivar, legacy_pcib_write_ivar),
  574. DEVMETHOD(bus_alloc_resource, legacy_pcib_alloc_resource),
  575. #if defined(NEW_PCIB) && defined(PCI_RES_BUS)
  576. DEVMETHOD(bus_adjust_resource, legacy_pcib_adjust_resource),
  577. DEVMETHOD(bus_release_resource, legacy_pcib_release_resource),
  578. #else
  579. DEVMETHOD(bus_adjust_resource, bus_generic_adjust_resource),
  580. DEVMETHOD(bus_release_resource, bus_generic_release_resource),
  581. #endif
  582. DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
  583. DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
  584. DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
  585. DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
  586. /* pcib interface */
  587. DEVMETHOD(pcib_maxslots, legacy_pcib_maxslots),
  588. DEVMETHOD(pcib_read_config, legacy_pcib_read_config),
  589. DEVMETHOD(pcib_write_config, legacy_pcib_write_config),
  590. DEVMETHOD(pcib_route_interrupt, legacy_pcib_route_interrupt),
  591. DEVMETHOD(pcib_alloc_msi, legacy_pcib_alloc_msi),
  592. DEVMETHOD(pcib_release_msi, pcib_release_msi),
  593. DEVMETHOD(pcib_alloc_msix, legacy_pcib_alloc_msix),
  594. DEVMETHOD(pcib_release_msix, pcib_release_msix),
  595. DEVMETHOD(pcib_map_msi, legacy_pcib_map_msi),
  596. DEVMETHOD(pcib_request_feature, pcib_request_feature_allow),
  597. DEVMETHOD_END
  598. };
  599. static devclass_t hostb_devclass;
  600. DEFINE_CLASS_0(pcib, legacy_pcib_driver, legacy_pcib_methods, 1);
  601. DRIVER_MODULE(pcib, legacy, legacy_pcib_driver, hostb_devclass, 0, 0);
  602. /*
  603. * Install placeholder to claim the resources owned by the
  604. * PCI bus interface. This could be used to extract the
  605. * config space registers in the extreme case where the PnP
  606. * ID is available and the PCI BIOS isn't, but for now we just
  607. * eat the PnP ID and do nothing else.
  608. *
  609. * we silence this probe, as it will generally confuse people.
  610. */
  611. static struct isa_pnp_id pcibus_pnp_ids[] = {
  612. { 0x030ad041 /* PNP0A03 */, "PCI Bus" },
  613. { 0x080ad041 /* PNP0A08 */, "PCIe Bus" },
  614. { 0 }
  615. };
  616. static int
  617. pcibus_pnp_probe(device_t dev)
  618. {
  619. int result;
  620. if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, pcibus_pnp_ids)) <= 0)
  621. device_quiet(dev);
  622. return(result);
  623. }
  624. static int
  625. pcibus_pnp_attach(device_t dev)
  626. {
  627. return(0);
  628. }
  629. static device_method_t pcibus_pnp_methods[] = {
  630. /* Device interface */
  631. DEVMETHOD(device_probe, pcibus_pnp_probe),
  632. DEVMETHOD(device_attach, pcibus_pnp_attach),
  633. DEVMETHOD(device_detach, bus_generic_detach),
  634. DEVMETHOD(device_shutdown, bus_generic_shutdown),
  635. DEVMETHOD(device_suspend, bus_generic_suspend),
  636. DEVMETHOD(device_resume, bus_generic_resume),
  637. { 0, 0 }
  638. };
  639. static devclass_t pcibus_pnp_devclass;
  640. DEFINE_CLASS_0(pcibus_pnp, pcibus_pnp_driver, pcibus_pnp_methods, 1);
  641. DRIVER_MODULE(pcibus_pnp, isa, pcibus_pnp_driver, pcibus_pnp_devclass, 0, 0);
  642. #ifdef __HAVE_PIR
  643. /*
  644. * Provide a PCI-PCI bridge driver for PCI buses behind PCI-PCI bridges
  645. * that appear in the PCIBIOS Interrupt Routing Table to use the routing
  646. * table for interrupt routing when possible.
  647. */
  648. static int pcibios_pcib_probe(device_t bus);
  649. static device_method_t pcibios_pcib_pci_methods[] = {
  650. /* Device interface */
  651. DEVMETHOD(device_probe, pcibios_pcib_probe),
  652. /* pcib interface */
  653. DEVMETHOD(pcib_route_interrupt, legacy_pcib_route_interrupt),
  654. {0, 0}
  655. };
  656. static devclass_t pcib_devclass;
  657. DEFINE_CLASS_1(pcib, pcibios_pcib_driver, pcibios_pcib_pci_methods,
  658. sizeof(struct pcib_softc), pcib_driver);
  659. DRIVER_MODULE(pcibios_pcib, pci, pcibios_pcib_driver, pcib_devclass, 0, 0);
  660. ISA_PNP_INFO(pcibus_pnp_ids);
  661. static int
  662. pcibios_pcib_probe(device_t dev)
  663. {
  664. int bus;
  665. if ((pci_get_class(dev) != PCIC_BRIDGE) ||
  666. (pci_get_subclass(dev) != PCIS_BRIDGE_PCI))
  667. return (ENXIO);
  668. bus = pci_read_config(dev, PCIR_SECBUS_1, 1);
  669. if (bus == 0)
  670. return (ENXIO);
  671. if (!pci_pir_probe(bus, 1))
  672. return (ENXIO);
  673. device_set_desc(dev, "PCIBIOS PCI-PCI bridge");
  674. return (-2000);
  675. }
  676. #endif