1098ca2bdSWarner Losh#- 226280d88SMarius Strobl# Copyright (c) 2001, 2003 by Thomas Moestl <tmm@FreeBSD.org> 3bba6f0a9SMarius Strobl# Copyright (c) 2004, 2005 by Marius Strobl <marius@FreeBSD.org> 426280d88SMarius Strobl# All rights reserved. 526280d88SMarius Strobl# 626280d88SMarius Strobl# Redistribution and use in source and binary forms, with or without 726280d88SMarius Strobl# modification, are permitted provided that the following conditions 826280d88SMarius Strobl# are met: 926280d88SMarius Strobl# 1. Redistributions of source code must retain the above copyright 1026280d88SMarius Strobl# notice, this list of conditions and the following disclaimer. 1126280d88SMarius Strobl# 2. Redistributions in binary form must reproduce the above copyright 1226280d88SMarius Strobl# notice, this list of conditions and the following disclaimer in the 1326280d88SMarius Strobl# documentation and/or other materials provided with the distribution. 1426280d88SMarius Strobl# 1526280d88SMarius Strobl# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1626280d88SMarius Strobl# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1726280d88SMarius Strobl# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1826280d88SMarius Strobl# IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 1926280d88SMarius Strobl# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 2026280d88SMarius Strobl# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 2126280d88SMarius Strobl# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 2226280d88SMarius Strobl# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2326280d88SMarius Strobl# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 2426280d88SMarius Strobl# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2526280d88SMarius Strobl# 2626280d88SMarius Strobl 27bba6f0a9SMarius Strobl# Interface for retrieving the package handle and a subset, namely 28bba6f0a9SMarius Strobl# 'compatible', 'device_type', 'model' and 'name', of the standard 29bba6f0a9SMarius Strobl# properties of a device on an Open Firmware assisted bus for use 30bba6f0a9SMarius Strobl# in device drivers. The rest of the standard properties, 'address', 31bba6f0a9SMarius Strobl# 'interrupts', 'reg' and 'status', are not covered by this interface 32bba6f0a9SMarius Strobl# as they are expected to be only of interest in the respective bus 33bba6f0a9SMarius Strobl# driver. 34bba6f0a9SMarius Strobl 3526280d88SMarius Strobl#include <sys/bus.h> 3626280d88SMarius Strobl 3726280d88SMarius Strobl#include <dev/ofw/openfirm.h> 3826280d88SMarius Strobl 3926280d88SMarius StroblINTERFACE ofw_bus; 4026280d88SMarius Strobl 41bba6f0a9SMarius StroblHEADER { 42bba6f0a9SMarius Strobl struct ofw_bus_devinfo { 43bba6f0a9SMarius Strobl phandle_t obd_node; 44bba6f0a9SMarius Strobl char *obd_compat; 45bba6f0a9SMarius Strobl char *obd_model; 46bba6f0a9SMarius Strobl char *obd_name; 47bba6f0a9SMarius Strobl char *obd_type; 48*e4be5a16SNathan Whitehorn char *obd_status; 49bba6f0a9SMarius Strobl }; 50bba6f0a9SMarius Strobl}; 51bba6f0a9SMarius Strobl 5226280d88SMarius StroblCODE { 53bba6f0a9SMarius Strobl static ofw_bus_get_devinfo_t ofw_bus_default_get_devinfo; 5426280d88SMarius Strobl static ofw_bus_get_compat_t ofw_bus_default_get_compat; 5526280d88SMarius Strobl static ofw_bus_get_model_t ofw_bus_default_get_model; 5626280d88SMarius Strobl static ofw_bus_get_name_t ofw_bus_default_get_name; 5726280d88SMarius Strobl static ofw_bus_get_node_t ofw_bus_default_get_node; 5826280d88SMarius Strobl static ofw_bus_get_type_t ofw_bus_default_get_type; 59f2148482SNathan Whitehorn static ofw_bus_map_intr_t ofw_bus_default_map_intr; 6026280d88SMarius Strobl 61bba6f0a9SMarius Strobl static const struct ofw_bus_devinfo * 62bba6f0a9SMarius Strobl ofw_bus_default_get_devinfo(device_t bus, device_t dev) 63bba6f0a9SMarius Strobl { 64bba6f0a9SMarius Strobl 65bba6f0a9SMarius Strobl return (NULL); 66bba6f0a9SMarius Strobl } 67bba6f0a9SMarius Strobl 6826280d88SMarius Strobl static const char * 6926280d88SMarius Strobl ofw_bus_default_get_compat(device_t bus, device_t dev) 7026280d88SMarius Strobl { 7126280d88SMarius Strobl 7226280d88SMarius Strobl return (NULL); 7326280d88SMarius Strobl } 7426280d88SMarius Strobl 7526280d88SMarius Strobl static const char * 7626280d88SMarius Strobl ofw_bus_default_get_model(device_t bus, device_t dev) 7726280d88SMarius Strobl { 7826280d88SMarius Strobl 7926280d88SMarius Strobl return (NULL); 8026280d88SMarius Strobl } 8126280d88SMarius Strobl 8226280d88SMarius Strobl static const char * 8326280d88SMarius Strobl ofw_bus_default_get_name(device_t bus, device_t dev) 8426280d88SMarius Strobl { 8526280d88SMarius Strobl 8626280d88SMarius Strobl return (NULL); 8726280d88SMarius Strobl } 8826280d88SMarius Strobl 8926280d88SMarius Strobl static phandle_t 9026280d88SMarius Strobl ofw_bus_default_get_node(device_t bus, device_t dev) 9126280d88SMarius Strobl { 9226280d88SMarius Strobl 930d8d9edaSNathan Whitehorn return (-1); 9426280d88SMarius Strobl } 9526280d88SMarius Strobl 9626280d88SMarius Strobl static const char * 9726280d88SMarius Strobl ofw_bus_default_get_type(device_t bus, device_t dev) 9826280d88SMarius Strobl { 9926280d88SMarius Strobl 10026280d88SMarius Strobl return (NULL); 10126280d88SMarius Strobl } 102f2148482SNathan Whitehorn 103f2148482SNathan Whitehorn int 104f2148482SNathan Whitehorn ofw_bus_default_map_intr(device_t bus, device_t dev, phandle_t iparent, 105bbc6da03SNathan Whitehorn int icells, pcell_t *interrupt) 106f2148482SNathan Whitehorn { 107f2148482SNathan Whitehorn /* Propagate up the bus hierarchy until someone handles it. */ 108f2148482SNathan Whitehorn if (device_get_parent(bus) != NULL) 109f2148482SNathan Whitehorn return OFW_BUS_MAP_INTR(device_get_parent(bus), dev, 110bbc6da03SNathan Whitehorn iparent, icells, interrupt); 111f2148482SNathan Whitehorn 112f2148482SNathan Whitehorn /* If that fails, then assume a one-domain system */ 113bbc6da03SNathan Whitehorn return (interrupt[0]); 114f2148482SNathan Whitehorn } 11526280d88SMarius Strobl}; 11626280d88SMarius Strobl 117bba6f0a9SMarius Strobl# Get the ofw_bus_devinfo struct for the device dev on the bus. Used for bus 118bba6f0a9SMarius Strobl# drivers which use the generic methods in ofw_bus_subr.c to implement the 119bba6f0a9SMarius Strobl# reset of this interface. The default method will return NULL, which means 120bba6f0a9SMarius Strobl# there is no such struct associated with the device. 121bba6f0a9SMarius StroblMETHOD const struct ofw_bus_devinfo * get_devinfo { 122bba6f0a9SMarius Strobl device_t bus; 123bba6f0a9SMarius Strobl device_t dev; 124bba6f0a9SMarius Strobl} DEFAULT ofw_bus_default_get_devinfo; 125bba6f0a9SMarius Strobl 12626280d88SMarius Strobl# Get the alternate firmware name for the device dev on the bus. The default 12726280d88SMarius Strobl# method will return NULL, which means the device doesn't have such a property. 12826280d88SMarius StroblMETHOD const char * get_compat { 12926280d88SMarius Strobl device_t bus; 13026280d88SMarius Strobl device_t dev; 13126280d88SMarius Strobl} DEFAULT ofw_bus_default_get_compat; 13226280d88SMarius Strobl 13326280d88SMarius Strobl# Get the firmware model name for the device dev on the bus. The default method 13426280d88SMarius Strobl# will return NULL, which means the device doesn't have such a property. 13526280d88SMarius StroblMETHOD const char * get_model { 13626280d88SMarius Strobl device_t bus; 13726280d88SMarius Strobl device_t dev; 13826280d88SMarius Strobl} DEFAULT ofw_bus_default_get_model; 13926280d88SMarius Strobl 14026280d88SMarius Strobl# Get the firmware name for the device dev on the bus. The default method will 14126280d88SMarius Strobl# return NULL, which means the device doesn't have such a property. 14226280d88SMarius StroblMETHOD const char * get_name { 14326280d88SMarius Strobl device_t bus; 14426280d88SMarius Strobl device_t dev; 14526280d88SMarius Strobl} DEFAULT ofw_bus_default_get_name; 14626280d88SMarius Strobl 14726280d88SMarius Strobl# Get the firmware node for the device dev on the bus. The default method will 1488ad579caSLuiz Otavio O Souza# return -1, which signals that there is no such node. 14926280d88SMarius StroblMETHOD phandle_t get_node { 15026280d88SMarius Strobl device_t bus; 15126280d88SMarius Strobl device_t dev; 15226280d88SMarius Strobl} DEFAULT ofw_bus_default_get_node; 15326280d88SMarius Strobl 15426280d88SMarius Strobl# Get the firmware device type for the device dev on the bus. The default 15526280d88SMarius Strobl# method will return NULL, which means the device doesn't have such a property. 15626280d88SMarius StroblMETHOD const char * get_type { 15726280d88SMarius Strobl device_t bus; 15826280d88SMarius Strobl device_t dev; 15926280d88SMarius Strobl} DEFAULT ofw_bus_default_get_type; 160f2148482SNathan Whitehorn 161f2148482SNathan Whitehorn# Map an (interrupt parent, IRQ) pair to a unique system-wide interrupt number. 162bbc6da03SNathan Whitehorn# If the interrupt encoding includes a sense field, the interrupt sense will 163bbc6da03SNathan Whitehorn# also be configured. 164f2148482SNathan WhitehornMETHOD int map_intr { 165f2148482SNathan Whitehorn device_t bus; 166f2148482SNathan Whitehorn device_t dev; 167f2148482SNathan Whitehorn phandle_t iparent; 168bbc6da03SNathan Whitehorn int icells; 169bbc6da03SNathan Whitehorn pcell_t *interrupt; 170f2148482SNathan Whitehorn} DEFAULT ofw_bus_default_map_intr; 171