1#- 2# Copyright (c) 2001, 2003 by Thomas Moestl <tmm@FreeBSD.org> 3# Copyright (c) 2004, 2005 by Marius Strobl <marius@FreeBSD.org> 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18# IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 19# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 24# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25# 26# $FreeBSD$ 27 28# Interface for retrieving the package handle and a subset, namely 29# 'compatible', 'device_type', 'model' and 'name', of the standard 30# properties of a device on an Open Firmware assisted bus for use 31# in device drivers. The rest of the standard properties, 'address', 32# 'interrupts', 'reg' and 'status', are not covered by this interface 33# as they are expected to be only of interest in the respective bus 34# driver. 35 36#include <sys/bus.h> 37 38#include <dev/ofw/openfirm.h> 39 40INTERFACE ofw_bus; 41 42HEADER { 43 struct ofw_bus_devinfo { 44 phandle_t obd_node; 45 char *obd_compat; 46 char *obd_model; 47 char *obd_name; 48 char *obd_type; 49 char *obd_status; 50 }; 51}; 52 53CODE { 54 static ofw_bus_get_devinfo_t ofw_bus_default_get_devinfo; 55 static ofw_bus_get_compat_t ofw_bus_default_get_compat; 56 static ofw_bus_get_model_t ofw_bus_default_get_model; 57 static ofw_bus_get_name_t ofw_bus_default_get_name; 58 static ofw_bus_get_node_t ofw_bus_default_get_node; 59 static ofw_bus_get_type_t ofw_bus_default_get_type; 60 static ofw_bus_map_intr_t ofw_bus_default_map_intr; 61 static ofw_bus_map_gpios_t ofw_bus_default_map_gpios; 62 63 static const struct ofw_bus_devinfo * 64 ofw_bus_default_get_devinfo(device_t bus, device_t dev) 65 { 66 67 return (NULL); 68 } 69 70 static const char * 71 ofw_bus_default_get_compat(device_t bus, device_t dev) 72 { 73 74 return (NULL); 75 } 76 77 static const char * 78 ofw_bus_default_get_model(device_t bus, device_t dev) 79 { 80 81 return (NULL); 82 } 83 84 static const char * 85 ofw_bus_default_get_name(device_t bus, device_t dev) 86 { 87 88 return (NULL); 89 } 90 91 static phandle_t 92 ofw_bus_default_get_node(device_t bus, device_t dev) 93 { 94 95 return (-1); 96 } 97 98 static const char * 99 ofw_bus_default_get_type(device_t bus, device_t dev) 100 { 101 102 return (NULL); 103 } 104 105 int 106 ofw_bus_default_map_intr(device_t bus, device_t dev, phandle_t iparent, 107 int icells, pcell_t *interrupt) 108 { 109 /* Propagate up the bus hierarchy until someone handles it. */ 110 if (device_get_parent(bus) != NULL) 111 return OFW_BUS_MAP_INTR(device_get_parent(bus), dev, 112 iparent, icells, interrupt); 113 114 /* If that fails, then assume a one-domain system */ 115 return (interrupt[0]); 116 } 117 118 int 119 ofw_bus_default_map_gpios(device_t bus, phandle_t dev, 120 phandle_t gparent, int gcells, pcell_t *gpios, uint32_t *pin, 121 uint32_t *flags) 122 { 123 /* Propagate up the bus hierarchy until someone handles it. */ 124 if (device_get_parent(bus) != NULL) 125 return OFW_BUS_MAP_GPIOS(device_get_parent(bus), dev, 126 gparent, gcells, gpios, pin, flags); 127 128 /* If that fails, then assume the FreeBSD defaults. */ 129 *pin = gpios[0]; 130 if (gcells == 2 || gcells == 3) 131 *flags = gpios[gcells - 1]; 132 133 return (0); 134 } 135}; 136 137# Get the ofw_bus_devinfo struct for the device dev on the bus. Used for bus 138# drivers which use the generic methods in ofw_bus_subr.c to implement the 139# reset of this interface. The default method will return NULL, which means 140# there is no such struct associated with the device. 141METHOD const struct ofw_bus_devinfo * get_devinfo { 142 device_t bus; 143 device_t dev; 144} DEFAULT ofw_bus_default_get_devinfo; 145 146# Get the alternate firmware name for the device dev on the bus. The default 147# method will return NULL, which means the device doesn't have such a property. 148METHOD const char * get_compat { 149 device_t bus; 150 device_t dev; 151} DEFAULT ofw_bus_default_get_compat; 152 153# Get the firmware model name for the device dev on the bus. The default method 154# will return NULL, which means the device doesn't have such a property. 155METHOD const char * get_model { 156 device_t bus; 157 device_t dev; 158} DEFAULT ofw_bus_default_get_model; 159 160# Get the firmware name for the device dev on the bus. The default method will 161# return NULL, which means the device doesn't have such a property. 162METHOD const char * get_name { 163 device_t bus; 164 device_t dev; 165} DEFAULT ofw_bus_default_get_name; 166 167# Get the firmware node for the device dev on the bus. The default method will 168# return -1, which signals that there is no such node. 169METHOD phandle_t get_node { 170 device_t bus; 171 device_t dev; 172} DEFAULT ofw_bus_default_get_node; 173 174# Get the firmware device type for the device dev on the bus. The default 175# method will return NULL, which means the device doesn't have such a property. 176METHOD const char * get_type { 177 device_t bus; 178 device_t dev; 179} DEFAULT ofw_bus_default_get_type; 180 181# Map an (interrupt parent, IRQ) pair to a unique system-wide interrupt number. 182# If the interrupt encoding includes a sense field, the interrupt sense will 183# also be configured. 184METHOD int map_intr { 185 device_t bus; 186 device_t dev; 187 phandle_t iparent; 188 int icells; 189 pcell_t *interrupt; 190} DEFAULT ofw_bus_default_map_intr; 191 192# Map the GPIO controller specific gpio-specifier to GPIO pin and flags. 193METHOD int map_gpios { 194 device_t bus; 195 phandle_t dev; 196 phandle_t gparent; 197 int gcells; 198 pcell_t *gpios; 199 uint32_t *pin; 200 uint32_t *flags; 201} DEFAULT ofw_bus_default_map_gpios; 202