xenpv.c revision 267536
1264790Sbapt/* 2264790Sbapt * Copyright (c) 2014 Roger Pau Monn�� <roger.pau@citrix.com> 3264790Sbapt * All rights reserved. 4264790Sbapt * 5264790Sbapt * Redistribution and use in source and binary forms, with or without 6264790Sbapt * modification, are permitted provided that the following conditions 7264790Sbapt * are met: 8264790Sbapt * 1. Redistributions of source code must retain the above copyright 9264790Sbapt * notice, this list of conditions and the following disclaimer. 10264790Sbapt * 2. Redistributions in binary form must reproduce the above copyright 11264790Sbapt * notice, this list of conditions and the following disclaimer in the 12264790Sbapt * documentation and/or other materials provided with the distribution. 13264790Sbapt * 14264790Sbapt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND 15264790Sbapt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16264790Sbapt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17264790Sbapt * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18264790Sbapt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19264790Sbapt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20264790Sbapt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21264790Sbapt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22264790Sbapt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23264790Sbapt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24264790Sbapt * SUCH DAMAGE. 25264790Sbapt */ 26264790Sbapt 27264790Sbapt#include <sys/cdefs.h> 28264790Sbapt__FBSDID("$FreeBSD: head/sys/x86/xen/xenpv.c 267536 2014-06-16 08:54:04Z royger $"); 29264790Sbapt 30264790Sbapt#include <sys/param.h> 31264790Sbapt#include <sys/systm.h> 32264790Sbapt#include <sys/bus.h> 33264790Sbapt#include <sys/kernel.h> 34264790Sbapt#include <sys/module.h> 35264790Sbapt#include <sys/pcpu.h> 36264790Sbapt#include <sys/smp.h> 37264790Sbapt 38264790Sbapt#include <xen/xen-os.h> 39264790Sbapt#include <xen/gnttab.h> 40264790Sbapt 41264790Sbaptstatic devclass_t xenpv_devclass; 42264790Sbapt 43264790Sbaptstatic void 44264790Sbaptxenpv_identify(driver_t *driver, device_t parent) 45264790Sbapt{ 46264790Sbapt if (!xen_domain()) 47264790Sbapt return; 48264790Sbapt 49264790Sbapt /* Make sure there's only one xenpv device. */ 50264790Sbapt if (devclass_get_device(xenpv_devclass, 0)) 51264790Sbapt return; 52264790Sbapt 53264790Sbapt if (BUS_ADD_CHILD(parent, 0, "xenpv", 0) == NULL) 54264790Sbapt panic("Unable to attach xenpv bus."); 55264790Sbapt} 56264790Sbapt 57264790Sbaptstatic int 58264790Sbaptxenpv_probe(device_t dev) 59264790Sbapt{ 60264790Sbapt 61264790Sbapt device_set_desc(dev, "Xen PV bus"); 62264790Sbapt return (BUS_PROBE_NOWILDCARD); 63264790Sbapt} 64264790Sbapt 65264790Sbaptstatic int 66264790Sbaptxenpv_attach(device_t dev) 67264790Sbapt{ 68264790Sbapt device_t child; 69264790Sbapt int error; 70264790Sbapt 71264790Sbapt /* Initialize grant table before any Xen specific device is attached */ 72264790Sbapt error = gnttab_init(dev); 73264790Sbapt if (error != 0) { 74264790Sbapt device_printf(dev, "error initializing grant table: %d\n", 75264790Sbapt error); 76264790Sbapt return (error); 77264790Sbapt } 78264790Sbapt 79264790Sbapt /* 80264790Sbapt * Let our child drivers identify any child devices that they 81264790Sbapt * can find. Once that is done attach any devices that we 82264790Sbapt * found. 83264790Sbapt */ 84264790Sbapt bus_generic_probe(dev); 85264790Sbapt bus_generic_attach(dev); 86264790Sbapt 87264790Sbapt if (!devclass_get_device(devclass_find("isa"), 0)) { 88264790Sbapt child = BUS_ADD_CHILD(dev, 0, "isa", 0); 89264790Sbapt if (child == NULL) 90264790Sbapt panic("Failed to attach ISA bus."); 91264790Sbapt device_probe_and_attach(child); 92264790Sbapt } 93264790Sbapt 94264790Sbapt return (0); 95264790Sbapt} 96264790Sbapt 97264790Sbaptstatic device_method_t xenpv_methods[] = { 98264790Sbapt /* Device interface */ 99264790Sbapt DEVMETHOD(device_identify, xenpv_identify), 100264790Sbapt DEVMETHOD(device_probe, xenpv_probe), 101264790Sbapt DEVMETHOD(device_attach, xenpv_attach), 102264790Sbapt DEVMETHOD(device_suspend, bus_generic_suspend), 103264790Sbapt DEVMETHOD(device_resume, bus_generic_resume), 104264790Sbapt 105264790Sbapt /* Bus interface */ 106264790Sbapt DEVMETHOD(bus_add_child, bus_generic_add_child), 107264790Sbapt DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource), 108264790Sbapt DEVMETHOD(bus_release_resource, bus_generic_release_resource), 109264790Sbapt DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 110264790Sbapt DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 111264790Sbapt 112264790Sbapt DEVMETHOD_END 113264790Sbapt}; 114264790Sbapt 115264790Sbaptstatic driver_t xenpv_driver = { 116264790Sbapt "xenpv", 117264790Sbapt xenpv_methods, 118264790Sbapt 0, 119264790Sbapt}; 120264790Sbapt 121264790SbaptDRIVER_MODULE(xenpv, nexus, xenpv_driver, xenpv_devclass, 0, 0); 122264790Sbapt