xref: /OK3568_Linux_fs/kernel/drivers/xen/dbgp.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun #include <linux/pci.h>
3*4882a593Smuzhiyun #include <linux/usb.h>
4*4882a593Smuzhiyun #include <linux/usb/ehci_def.h>
5*4882a593Smuzhiyun #include <linux/usb/hcd.h>
6*4882a593Smuzhiyun #include <asm/xen/hypercall.h>
7*4882a593Smuzhiyun #include <xen/interface/physdev.h>
8*4882a593Smuzhiyun #include <xen/xen.h>
9*4882a593Smuzhiyun 
xen_dbgp_op(struct usb_hcd * hcd,int op)10*4882a593Smuzhiyun static int xen_dbgp_op(struct usb_hcd *hcd, int op)
11*4882a593Smuzhiyun {
12*4882a593Smuzhiyun #ifdef CONFIG_PCI
13*4882a593Smuzhiyun 	const struct device *ctrlr = hcd_to_bus(hcd)->controller;
14*4882a593Smuzhiyun #endif
15*4882a593Smuzhiyun 	struct physdev_dbgp_op dbgp;
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun 	if (!xen_initial_domain())
18*4882a593Smuzhiyun 		return 0;
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun 	dbgp.op = op;
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun #ifdef CONFIG_PCI
23*4882a593Smuzhiyun 	if (dev_is_pci(ctrlr)) {
24*4882a593Smuzhiyun 		const struct pci_dev *pdev = to_pci_dev(ctrlr);
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun 		dbgp.u.pci.seg = pci_domain_nr(pdev->bus);
27*4882a593Smuzhiyun 		dbgp.u.pci.bus = pdev->bus->number;
28*4882a593Smuzhiyun 		dbgp.u.pci.devfn = pdev->devfn;
29*4882a593Smuzhiyun 		dbgp.bus = PHYSDEVOP_DBGP_BUS_PCI;
30*4882a593Smuzhiyun 	} else
31*4882a593Smuzhiyun #endif
32*4882a593Smuzhiyun 		dbgp.bus = PHYSDEVOP_DBGP_BUS_UNKNOWN;
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun 	return HYPERVISOR_physdev_op(PHYSDEVOP_dbgp_op, &dbgp);
35*4882a593Smuzhiyun }
36*4882a593Smuzhiyun 
xen_dbgp_reset_prep(struct usb_hcd * hcd)37*4882a593Smuzhiyun int xen_dbgp_reset_prep(struct usb_hcd *hcd)
38*4882a593Smuzhiyun {
39*4882a593Smuzhiyun 	return xen_dbgp_op(hcd, PHYSDEVOP_DBGP_RESET_PREPARE);
40*4882a593Smuzhiyun }
41*4882a593Smuzhiyun 
xen_dbgp_external_startup(struct usb_hcd * hcd)42*4882a593Smuzhiyun int xen_dbgp_external_startup(struct usb_hcd *hcd)
43*4882a593Smuzhiyun {
44*4882a593Smuzhiyun 	return xen_dbgp_op(hcd, PHYSDEVOP_DBGP_RESET_DONE);
45*4882a593Smuzhiyun }
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun #ifndef CONFIG_EARLY_PRINTK_DBGP
48*4882a593Smuzhiyun #include <linux/export.h>
49*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(xen_dbgp_reset_prep);
50*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(xen_dbgp_external_startup);
51*4882a593Smuzhiyun #endif
52