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: releng/11.0/sys/dev/ofw/ofw_bus_if.m 265310 2014-05-04 04:01:26Z loos $
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;
49261403Snwhitehorn		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;
60256994Snwhitehorn	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	}
103256994Snwhitehorn
104256994Snwhitehorn	int
105256994Snwhitehorn	ofw_bus_default_map_intr(device_t bus, device_t dev, phandle_t iparent,
106261351Snwhitehorn	    int icells, pcell_t *interrupt)
107256994Snwhitehorn	{
108256994Snwhitehorn		/* Propagate up the bus hierarchy until someone handles it. */	
109256994Snwhitehorn		if (device_get_parent(bus) != NULL)
110256994Snwhitehorn			return OFW_BUS_MAP_INTR(device_get_parent(bus), dev,
111261351Snwhitehorn			    iparent, icells, interrupt);
112256994Snwhitehorn
113256994Snwhitehorn		/* If that fails, then assume a one-domain system */
114261351Snwhitehorn		return (interrupt[0]);
115256994Snwhitehorn	}
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
149258046Sloos# 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;
161256994Snwhitehorn
162256994Snwhitehorn# Map an (interrupt parent, IRQ) pair to a unique system-wide interrupt number.
163261351Snwhitehorn# If the interrupt encoding includes a sense field, the interrupt sense will
164261351Snwhitehorn# also be configured.
165256994SnwhitehornMETHOD int map_intr {
166256994Snwhitehorn	device_t bus;
167256994Snwhitehorn	device_t dev;
168256994Snwhitehorn	phandle_t iparent;
169261351Snwhitehorn	int icells;
170261351Snwhitehorn	pcell_t *interrupt;
171256994Snwhitehorn} DEFAULT ofw_bus_default_map_intr;
172