Lines Matching refs:pdev
108 struct pcifront_device *pdev; member
115 struct pcifront_device *pdev = NULL; in alloc_pdev() local
122 xenbus_dev_fatal(pdev->xdev, err, "Error scanning pci device instance number"); in alloc_pdev()
126 pdev = (struct pcifront_device *)malloc(sizeof(struct pcifront_device), M_DEVBUF, M_NOWAIT); in alloc_pdev()
127 if (pdev == NULL) { 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()
138 free(pdev, M_DEVBUF); in alloc_pdev()
139 pdev = NULL; 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()
153 STAILQ_INSERT_TAIL(&pdev_list, pdev, next); in alloc_pdev()
155 DPRINTF("Allocated pdev @ 0x%p (unit=%d)\n", pdev, unit); in alloc_pdev()
158 return pdev; in alloc_pdev()
163 get_pdev(struct pcifront_device *pdev) in get_pdev() argument
165 pdev->ref_cnt++; in get_pdev()
170 put_pdev(struct pcifront_device *pdev) in put_pdev() argument
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()
185 free(pdev, M_DEVBUF); in put_pdev()
190 pcifront_publish_info(struct pcifront_device *pdev) in pcifront_publish_info() argument
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()
238 xenbus_dev_fatal(pdev->xdev, err, in pcifront_publish_info()
250 pcifront_connect(struct pcifront_device *pdev) in pcifront_connect() argument
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()
268 get_pdev(pdev); 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()
285 pcifront_disconnect(struct pcifront_device *pdev) in pcifront_disconnect() argument
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()
308 struct pcifront_device *pdev; in pcifront_probe() local
312 if ((pdev = alloc_pdev(xdev)) == NULL) in pcifront_probe()
315 err = pcifront_publish_info(pdev); in pcifront_probe()
319 put_pdev(pdev); in pcifront_probe()
338 struct pcifront_device *pdev = xdev->data; in pcifront_backend_changed() local
343 pcifront_disconnect(pdev); in pcifront_backend_changed()
348 pcifront_disconnect(pdev); in pcifront_backend_changed()
353 pcifront_connect(pdev); in pcifront_backend_changed()
363 do_pci_op(struct pcifront_device *pdev, struct xen_pci_op *op) in do_pci_op() argument
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()
403 mtx_unlock(&pdev->sh_info_lock); in do_pci_op()
441 struct pcifront_device *pdev = (struct pcifront_device *)device_get_ivars(dev); in SYSINIT() local
442 DPRINTF("xpcife probe (unit=%d)\n", pdev->unit); in SYSINIT()
451 struct pcifront_device *pdev = (struct pcifront_device *)device_get_ivars(dev); 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()
463 xenbus_dev_fatal(pdev->xdev, err, in xpcife_attach()
478 err = xenbus_scanf(NULL, pdev->xdev->otherend, str, in xpcife_attach()
483 xenbus_dev_fatal(pdev->xdev, err, in xpcife_attach()
488 if (domain != pdev->xdev->otherend_id) { 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()
498 xenbus_dev_fatal(pdev->xdev, err, in xpcife_attach()
543 struct pcifront_device *pdev = (struct pcifront_device *)device_get_ivars(device_get_parent(dev)); in xpcib_probe() local
547 sc->domain = pdev->xdev->otherend_id; in xpcib_probe()
549 sc->pdev = pdev; in xpcib_probe()
604 err = do_pci_op(sc->pdev, &op); in xpcib_read_config()
632 err = do_pci_op(sc->pdev, &op); in xpcib_write_config()