1139749Simp#- 2133589Smarius# Copyright (c) 2001, 2003 by Thomas Moestl <tmm@FreeBSD.org> 3152683Smarius# Copyright (c) 2004, 2005 by Marius Strobl <marius@FreeBSD.org> 4133589Smarius# All rights reserved. 5133589Smarius# 6133589Smarius# Redistribution and use in source and binary forms, with or without 7133589Smarius# modification, are permitted provided that the following conditions 8133589Smarius# are met: 9133589Smarius# 1. Redistributions of source code must retain the above copyright 10133589Smarius# notice, this list of conditions and the following disclaimer. 11133589Smarius# 2. Redistributions in binary form must reproduce the above copyright 12133589Smarius# notice, this list of conditions and the following disclaimer in the 13133589Smarius# documentation and/or other materials provided with the distribution. 14133589Smarius# 15133589Smarius# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16133589Smarius# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17133589Smarius# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18133589Smarius# IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 19133589Smarius# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20133589Smarius# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21133589Smarius# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22133589Smarius# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23133589Smarius# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 24133589Smarius# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25133589Smarius# 26133589Smarius# $FreeBSD$ 27133589Smarius 28152683Smarius# Interface for retrieving the package handle and a subset, namely 29152683Smarius# 'compatible', 'device_type', 'model' and 'name', of the standard 30152683Smarius# properties of a device on an Open Firmware assisted bus for use 31152683Smarius# in device drivers. The rest of the standard properties, 'address', 32152683Smarius# 'interrupts', 'reg' and 'status', are not covered by this interface 33152683Smarius# as they are expected to be only of interest in the respective bus 34152683Smarius# driver. 35152683Smarius 36133589Smarius#include <sys/bus.h> 37133589Smarius 38133589Smarius#include <dev/ofw/openfirm.h> 39133589Smarius 40133589SmariusINTERFACE ofw_bus; 41133589Smarius 42152683SmariusHEADER { 43152683Smarius struct ofw_bus_devinfo { 44152683Smarius phandle_t obd_node; 45152683Smarius char *obd_compat; 46152683Smarius char *obd_model; 47152683Smarius char *obd_name; 48152683Smarius char *obd_type; 49266128Sian char *obd_status; 50152683Smarius }; 51152683Smarius}; 52152683Smarius 53133589SmariusCODE { 54152683Smarius static ofw_bus_get_devinfo_t ofw_bus_default_get_devinfo; 55133589Smarius static ofw_bus_get_compat_t ofw_bus_default_get_compat; 56133589Smarius static ofw_bus_get_model_t ofw_bus_default_get_model; 57133589Smarius static ofw_bus_get_name_t ofw_bus_default_get_name; 58133589Smarius static ofw_bus_get_node_t ofw_bus_default_get_node; 59133589Smarius static ofw_bus_get_type_t ofw_bus_default_get_type; 60265969Sian static ofw_bus_map_intr_t ofw_bus_default_map_intr; 61133589Smarius 62152683Smarius static const struct ofw_bus_devinfo * 63152683Smarius ofw_bus_default_get_devinfo(device_t bus, device_t dev) 64152683Smarius { 65152683Smarius 66152683Smarius return (NULL); 67152683Smarius } 68152683Smarius 69133589Smarius static const char * 70133589Smarius ofw_bus_default_get_compat(device_t bus, device_t dev) 71133589Smarius { 72133589Smarius 73133589Smarius return (NULL); 74133589Smarius } 75133589Smarius 76133589Smarius static const char * 77133589Smarius ofw_bus_default_get_model(device_t bus, device_t dev) 78133589Smarius { 79133589Smarius 80133589Smarius return (NULL); 81133589Smarius } 82133589Smarius 83133589Smarius static const char * 84133589Smarius ofw_bus_default_get_name(device_t bus, device_t dev) 85133589Smarius { 86133589Smarius 87133589Smarius return (NULL); 88133589Smarius } 89133589Smarius 90133589Smarius static phandle_t 91133589Smarius ofw_bus_default_get_node(device_t bus, device_t dev) 92133589Smarius { 93133589Smarius 94233018Snwhitehorn return (-1); 95133589Smarius } 96133589Smarius 97133589Smarius static const char * 98133589Smarius ofw_bus_default_get_type(device_t bus, device_t dev) 99133589Smarius { 100133589Smarius 101133589Smarius return (NULL); 102133589Smarius } 103265969Sian 104265969Sian int 105265969Sian ofw_bus_default_map_intr(device_t bus, device_t dev, phandle_t iparent, 106266128Sian int icells, pcell_t *interrupt) 107265969Sian { 108265969Sian /* Propagate up the bus hierarchy until someone handles it. */ 109265969Sian if (device_get_parent(bus) != NULL) 110265969Sian return OFW_BUS_MAP_INTR(device_get_parent(bus), dev, 111266128Sian iparent, icells, interrupt); 112265969Sian 113265969Sian /* If that fails, then assume a one-domain system */ 114266128Sian return (interrupt[0]); 115265969Sian } 116133589Smarius}; 117133589Smarius 118152683Smarius# Get the ofw_bus_devinfo struct for the device dev on the bus. Used for bus 119152683Smarius# drivers which use the generic methods in ofw_bus_subr.c to implement the 120152683Smarius# reset of this interface. The default method will return NULL, which means 121152683Smarius# there is no such struct associated with the device. 122152683SmariusMETHOD const struct ofw_bus_devinfo * get_devinfo { 123152683Smarius device_t bus; 124152683Smarius device_t dev; 125152683Smarius} DEFAULT ofw_bus_default_get_devinfo; 126152683Smarius 127133589Smarius# Get the alternate firmware name for the device dev on the bus. The default 128133589Smarius# method will return NULL, which means the device doesn't have such a property. 129133589SmariusMETHOD const char * get_compat { 130133589Smarius device_t bus; 131133589Smarius device_t dev; 132133589Smarius} DEFAULT ofw_bus_default_get_compat; 133133589Smarius 134133589Smarius# Get the firmware model name for the device dev on the bus. The default method 135133589Smarius# will return NULL, which means the device doesn't have such a property. 136133589SmariusMETHOD const char * get_model { 137133589Smarius device_t bus; 138133589Smarius device_t dev; 139133589Smarius} DEFAULT ofw_bus_default_get_model; 140133589Smarius 141133589Smarius# Get the firmware name for the device dev on the bus. The default method will 142133589Smarius# return NULL, which means the device doesn't have such a property. 143133589SmariusMETHOD const char * get_name { 144133589Smarius device_t bus; 145133589Smarius device_t dev; 146133589Smarius} DEFAULT ofw_bus_default_get_name; 147133589Smarius 148133589Smarius# Get the firmware node for the device dev on the bus. The default method will 149266105Sloos# return -1, which signals that there is no such node. 150133589SmariusMETHOD phandle_t get_node { 151133589Smarius device_t bus; 152133589Smarius device_t dev; 153133589Smarius} DEFAULT ofw_bus_default_get_node; 154133589Smarius 155133589Smarius# Get the firmware device type for the device dev on the bus. The default 156133589Smarius# method will return NULL, which means the device doesn't have such a property. 157133589SmariusMETHOD const char * get_type { 158133589Smarius device_t bus; 159133589Smarius device_t dev; 160133589Smarius} DEFAULT ofw_bus_default_get_type; 161265969Sian 162265969Sian# Map an (interrupt parent, IRQ) pair to a unique system-wide interrupt number. 163266128Sian# If the interrupt encoding includes a sense field, the interrupt sense will 164266128Sian# also be configured. 165265969SianMETHOD int map_intr { 166265969Sian device_t bus; 167265969Sian device_t dev; 168265969Sian phandle_t iparent; 169266128Sian int icells; 170266128Sian pcell_t *interrupt; 171265969Sian} DEFAULT ofw_bus_default_map_intr; 172