From 1093cd82e0daf4ab31ba49e4f5067a2a158a1b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Wed, 10 Dec 2014 11:35:41 +0000 Subject: [PATCH] xen: convert the Grant-table code to a NewBus device This allows the Grant-table code to attach directly to the xenpv bus, allowing us to remove the grant-table initialization done in xenpv. Sponsored by: Citrix Systems R&D --- sys/dev/xen/grant_table/grant_table.c | 70 ++++++++++++++++++++++++--- sys/x86/xen/xenpv.c | 9 ---- sys/xen/gnttab.h | 2 - 3 files changed, 63 insertions(+), 18 deletions(-) diff --git a/sys/dev/xen/grant_table/grant_table.c b/sys/dev/xen/grant_table/grant_table.c index 9ab3145b4fee..25116575c023 100644 --- a/sys/dev/xen/grant_table/grant_table.c +++ b/sys/dev/xen/grant_table/grant_table.c @@ -659,16 +659,59 @@ gnttab_expand(unsigned int req_entries) return (error); } -int -gnttab_init(device_t dev) +MTX_SYSINIT(gnttab, &gnttab_list_lock, "GNTTAB LOCK", MTX_DEF); + +/*------------------ Private Device Attachment Functions --------------------*/ +/** + * \brief Identify instances of this device type in the system. + * + * \param driver The driver performing this identify action. + * \param parent The NewBus parent device for any devices this method adds. + */ +static void +granttable_identify(driver_t *driver __unused, device_t parent) +{ + + KASSERT(xen_domain(), + ("Trying to attach grant-table device on non Xen domain")); + /* + * A single device instance for our driver is always present + * in a system operating under Xen. + */ + if (BUS_ADD_CHILD(parent, 0, driver->name, 0) == NULL) + panic("unable to attach Xen Grant-table device"); +} + +/** + * \brief Probe for the existence of the Xen Grant-table device + * + * \param dev NewBus device_t for this instance. + * + * \return Always returns 0 indicating success. + */ +static int +granttable_probe(device_t dev) +{ + + device_set_desc(dev, "Xen Grant-table Device"); + return (BUS_PROBE_NOWILDCARD); +} + +/** + * \brief Attach the Xen Grant-table device. + * + * \param dev NewBus device_t for this instance. + * + * \return On success, 0. Otherwise an errno value indicating the + * type of failure. + */ +static int +granttable_attach(device_t dev) { int i; unsigned int max_nr_glist_frames; unsigned int nr_init_grefs; - if (!is_running_on_xen()) - return (ENODEV); - nr_grant_frames = 1; boot_max_nr_grant_frames = __max_nr_grant_frames(); @@ -714,7 +757,20 @@ gnttab_init(device_t dev) free(gnttab_list[i], M_DEVBUF); free(gnttab_list, M_DEVBUF); return (ENOMEM); - } -MTX_SYSINIT(gnttab, &gnttab_list_lock, "GNTTAB LOCK", MTX_DEF); +/*-------------------- Private Device Attachment Data -----------------------*/ +static device_method_t granttable_methods[] = { + /* Device interface */ + DEVMETHOD(device_identify, granttable_identify), + DEVMETHOD(device_probe, granttable_probe), + DEVMETHOD(device_attach, granttable_attach), + + DEVMETHOD_END +}; + +DEFINE_CLASS_0(granttable, granttable_driver, granttable_methods, 0); +devclass_t granttable_devclass; + +DRIVER_MODULE_ORDERED(granttable, xenpv, granttable_driver, granttable_devclass, + NULL, NULL, SI_ORDER_FIRST); diff --git a/sys/x86/xen/xenpv.c b/sys/x86/xen/xenpv.c index 9dd5db4a23be..bdda88374f27 100644 --- a/sys/x86/xen/xenpv.c +++ b/sys/x86/xen/xenpv.c @@ -66,15 +66,6 @@ static int xenpv_attach(device_t dev) { device_t child; - int error; - - /* Initialize grant table before any Xen specific device is attached */ - error = gnttab_init(dev); - if (error != 0) { - device_printf(dev, "error initializing grant table: %d\n", - error); - return (error); - } /* * Let our child drivers identify any child devices that they diff --git a/sys/xen/gnttab.h b/sys/xen/gnttab.h index afbe600607a0..d0a44aeabfae 100644 --- a/sys/xen/gnttab.h +++ b/sys/xen/gnttab.h @@ -51,8 +51,6 @@ struct gnttab_free_callback { uint16_t count; }; -int gnttab_init(device_t); - /* * Allocate a grant table reference and return it in *result. Returns * zero on success or errno on error.