Lines Matching +full:pci +full:- +full:domain
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
58 #include <machine/xen-os.h>
60 #include <machine/hypervisor-ifs.h>
65 #include <machine/xen-public/memory.h>
66 #include <machine/xen-public/io/pciif.h>
69 #include <dev/pci/pcivar.h>
82 #define INVALID_EVTCHN (-1)
106 int domain; member
111 /* Allocate a PCI device structure */
118 err = sscanf(xdev->nodename, "device/pci/%d", &unit); in alloc_pdev()
121 err = -EINVAL; in alloc_pdev()
122 xenbus_dev_fatal(pdev->xdev, err, "Error scanning pci device instance number"); in alloc_pdev()
128 err = -ENOMEM; in alloc_pdev()
132 pdev->unit = unit; in alloc_pdev()
133 pdev->xdev = xdev; in alloc_pdev()
134 pdev->ref_cnt = 1; in alloc_pdev()
136 pdev->sh_info = (struct xen_pci_sharedinfo *)malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT); in alloc_pdev()
137 if (pdev->sh_info == NULL) { in alloc_pdev()
140 err = -ENOMEM; in alloc_pdev()
144 pdev->sh_info->flags = 0; in alloc_pdev()
146 xdev->data = pdev; in alloc_pdev()
148 mtx_init(&pdev->sh_info_lock, "info_lock", "pci shared dev info lock", MTX_DEF); in alloc_pdev()
150 pdev->evtchn = INVALID_EVTCHN; in alloc_pdev()
151 pdev->gnt_ref = INVALID_GRANT_REF; in alloc_pdev()
165 pdev->ref_cnt++; in get_pdev()
172 if (--pdev->ref_cnt > 0) in put_pdev()
175 DPRINTF("freeing pdev @ 0x%p (ref_cnt=%d)\n", pdev, pdev->ref_cnt); in put_pdev()
177 if (pdev->evtchn != INVALID_EVTCHN) in put_pdev()
178 xenbus_free_evtchn(pdev->xdev, pdev->evtchn); in put_pdev()
180 if (pdev->gnt_ref != INVALID_GRANT_REF) in put_pdev()
181 gnttab_end_foreign_access(pdev->gnt_ref, 0, (void *)pdev->sh_info); in put_pdev()
183 pdev->xdev->data = NULL; in put_pdev()
195 err = xenbus_grant_ring(pdev->xdev, virt_to_mfn(pdev->sh_info)); in pcifront_publish_info()
201 pdev->gnt_ref = err; in pcifront_publish_info()
203 err = xenbus_alloc_evtchn(pdev->xdev, &pdev->evtchn); in pcifront_publish_info()
210 xenbus_dev_fatal(pdev->xdev, err, in pcifront_publish_info()
216 err = xenbus_printf(trans, pdev->xdev->nodename, in pcifront_publish_info()
217 "pci-op-ref", "%u", pdev->gnt_ref); in pcifront_publish_info()
219 err = xenbus_printf(trans, pdev->xdev->nodename, in pcifront_publish_info()
220 "event-channel", "%u", pdev->evtchn); in pcifront_publish_info()
222 err = xenbus_printf(trans, pdev->xdev->nodename, in pcifront_publish_info()
225 err = xenbus_switch_state(pdev->xdev, trans, in pcifront_publish_info()
230 xenbus_dev_fatal(pdev->xdev, err, in pcifront_publish_info()
235 if (err == -EAGAIN) in pcifront_publish_info()
238 xenbus_dev_fatal(pdev->xdev, err, in pcifront_publish_info()
259 return -1; in pcifront_connect()
263 pdev->ndev = BUS_ADD_CHILD(nexus, 0, "xpcife", pdev->unit); in pcifront_connect()
264 if (!pdev->ndev) { in pcifront_connect()
265 WPRINTF("could not create xpcife%d!\n", pdev->unit); in pcifront_connect()
266 return -EFAULT; in pcifront_connect()
269 device_set_ivars(pdev->ndev, pdev); in pcifront_connect()
272 xenbus_switch_state(pdev->xdev, NULL, XenbusStateConnected); in pcifront_connect()
274 printf("pcifront: connected to %s\n", pdev->xdev->nodename); in pcifront_connect()
277 device_probe_and_attach(pdev->ndev); in pcifront_connect()
290 prev_state = xenbus_read_driver_state(pdev->xdev->nodename); in pcifront_disconnect()
293 err = xenbus_switch_state(pdev->xdev, NULL, XenbusStateClosing); in pcifront_disconnect()
295 /* TODO - need to detach the newbus devices */ in pcifront_disconnect()
323 /* Remove the xenbus PCI device */
327 DPRINTF("removing xenbus device node (%s)\n", xdev->nodename); in pcifront_remove()
328 if (xdev->data) in pcifront_remove()
329 put_pdev(xdev->data); in pcifront_remove()
338 struct pcifront_device *pdev = xdev->data; in pcifront_backend_changed()
342 DPRINTF("backend closing (%s)\n", xdev->nodename); in pcifront_backend_changed()
347 DPRINTF("backend closed (%s)\n", xdev->nodename); in pcifront_backend_changed()
352 DPRINTF("backend connected (%s)\n", xdev->nodename); in pcifront_backend_changed()
361 /* Process PCI operation */
366 struct xen_pci_op *active_op = &pdev->sh_info->op; in do_pci_op()
367 evtchn_port_t port = pdev->evtchn; in do_pci_op()
370 mtx_lock(&pdev->sh_info_lock); in do_pci_op()
376 set_bit(_XEN_PCIF_active, (unsigned long *)&pdev->sh_info->flags); in do_pci_op()
385 (_XEN_PCIF_active, (unsigned long *)&pdev->sh_info->flags)) { in do_pci_op()
393 (unsigned long *)&pdev->sh_info->flags); in do_pci_op()
401 err = op->err; in do_pci_op()
403 mtx_unlock(&pdev->sh_info_lock); in do_pci_op()
410 { "pci" },
426 if ((xen_start_info->flags & SIF_INITDOMAIN)) in pcifront_init()
442 DPRINTF("xpcife probe (unit=%d)\n", pdev->unit); in SYSINIT()
454 unsigned int domain, bus; in xpcife_attach() local
456 DPRINTF("xpcife attach (unit=%d)\n", pdev->unit); in xpcife_attach()
458 err = xenbus_scanf(NULL, pdev->xdev->otherend, in xpcife_attach()
462 err = -EINVAL; in xpcife_attach()
463 xenbus_dev_fatal(pdev->xdev, err, in xpcife_attach()
464 "Error reading number of PCI roots"); in xpcife_attach()
472 len = snprintf(str, sizeof(str), "root-%d", i); in xpcife_attach()
473 if (unlikely(len >= (sizeof(str) - 1))) { in xpcife_attach()
474 err = -ENOMEM; in xpcife_attach()
478 err = xenbus_scanf(NULL, pdev->xdev->otherend, str, in xpcife_attach()
479 "%x:%x", &domain, &bus); in xpcife_attach()
482 err = -EINVAL; in xpcife_attach()
483 xenbus_dev_fatal(pdev->xdev, err, in xpcife_attach()
484 "Error reading PCI root %d", i); in xpcife_attach()
488 if (domain != pdev->xdev->otherend_id) { in xpcife_attach()
489 err = -EINVAL; in xpcife_attach()
490 xenbus_dev_fatal(pdev->xdev, err, in xpcife_attach()
491 "Domain mismatch %d != %d", domain, pdev->xdev->otherend_id); in xpcife_attach()
497 err = -ENOMEM; in xpcife_attach()
498 xenbus_dev_fatal(pdev->xdev, err, in xpcife_attach()
547 sc->domain = pdev->xdev->otherend_id; in xpcib_probe()
548 sc->bus = device_get_unit(dev); in xpcib_probe()
549 sc->pdev = pdev; in xpcib_probe()
560 DPRINTF("xpcib attach (bus=%d)\n", sc->bus); in xpcib_attach()
562 device_add_child(dev, "pci", DEVICE_UNIT_ANY); in xpcib_attach()
573 *result = sc->bus; in xpcib_read_ivar()
596 .domain = sc->domain, in xpcib_read_config()
597 .bus = sc->bus, in xpcib_read_config()
604 err = do_pci_op(sc->pdev, &op); in xpcib_read_config()
623 .domain = sc->domain, in xpcib_write_config()
624 .bus = sc->bus, in xpcib_write_config()
632 err = do_pci_op(sc->pdev, &op); in xpcib_write_config()
642 pcicfgregs *cfg = &dinfo->cfg; in xpcib_route_interrupt()
644 DPRINTF("route intr (pin=%d, line=%d)\n", pin, cfg->intline); in xpcib_route_interrupt()
646 return cfg->intline; in xpcib_route_interrupt()
685 * c-set-style: "BSD"
686 * c-basic-offset: 4
687 * tab-width: 4
688 * indent-tabs-mode: t