ofw_bus_if.m revision 258046
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: head/sys/dev/ofw/ofw_bus_if.m 258046 2013-11-12 13:44:50Z 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;
49152683Smarius	};
50152683Smarius};
51152683Smarius
52133589SmariusCODE {
53152683Smarius	static ofw_bus_get_devinfo_t ofw_bus_default_get_devinfo;
54133589Smarius	static ofw_bus_get_compat_t ofw_bus_default_get_compat;
55133589Smarius	static ofw_bus_get_model_t ofw_bus_default_get_model;
56133589Smarius	static ofw_bus_get_name_t ofw_bus_default_get_name;
57133589Smarius	static ofw_bus_get_node_t ofw_bus_default_get_node;
58133589Smarius	static ofw_bus_get_type_t ofw_bus_default_get_type;
59256994Snwhitehorn	static ofw_bus_map_intr_t ofw_bus_default_map_intr;
60256994Snwhitehorn	static ofw_bus_config_intr_t ofw_bus_default_config_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,
106256994Snwhitehorn	    int irq)
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,
111256994Snwhitehorn			    iparent, irq);
112256994Snwhitehorn
113256994Snwhitehorn		/* If that fails, then assume a one-domain system */
114256994Snwhitehorn		return (irq);
115256994Snwhitehorn	}
116256994Snwhitehorn
117256994Snwhitehorn	int
118256994Snwhitehorn	ofw_bus_default_config_intr(device_t bus, device_t dev, int irq,
119256994Snwhitehorn	    int sense)
120256994Snwhitehorn	{
121256994Snwhitehorn		/* Propagate up the bus hierarchy until someone handles it. */	
122256994Snwhitehorn		if (device_get_parent(bus) != NULL)
123256994Snwhitehorn			return OFW_BUS_CONFIG_INTR(device_get_parent(bus), dev,
124256994Snwhitehorn			    irq, sense);
125256994Snwhitehorn
126256994Snwhitehorn		return (ENXIO);
127256994Snwhitehorn	}
128133589Smarius};
129133589Smarius
130152683Smarius# Get the ofw_bus_devinfo struct for the device dev on the bus. Used for bus
131152683Smarius# drivers which use the generic methods in ofw_bus_subr.c to implement the
132152683Smarius# reset of this interface. The default method will return NULL, which means
133152683Smarius# there is no such struct associated with the device.
134152683SmariusMETHOD const struct ofw_bus_devinfo * get_devinfo {
135152683Smarius	device_t bus;
136152683Smarius	device_t dev;
137152683Smarius} DEFAULT ofw_bus_default_get_devinfo;
138152683Smarius
139133589Smarius# Get the alternate firmware name for the device dev on the bus. The default
140133589Smarius# method will return NULL, which means the device doesn't have such a property.
141133589SmariusMETHOD const char * get_compat {
142133589Smarius	device_t bus;
143133589Smarius	device_t dev;
144133589Smarius} DEFAULT ofw_bus_default_get_compat;
145133589Smarius
146133589Smarius# Get the firmware model name for the device dev on the bus. The default method
147133589Smarius# will return NULL, which means the device doesn't have such a property.
148133589SmariusMETHOD const char * get_model {
149133589Smarius	device_t bus;
150133589Smarius	device_t dev;
151133589Smarius} DEFAULT ofw_bus_default_get_model;
152133589Smarius
153133589Smarius# Get the firmware name for the device dev on the bus. The default method will
154133589Smarius# return NULL, which means the device doesn't have such a property.
155133589SmariusMETHOD const char * get_name {
156133589Smarius	device_t bus;
157133589Smarius	device_t dev;
158133589Smarius} DEFAULT ofw_bus_default_get_name;
159133589Smarius
160133589Smarius# Get the firmware node for the device dev on the bus. The default method will
161258046Sloos# return -1, which signals that there is no such node.
162133589SmariusMETHOD phandle_t get_node {
163133589Smarius	device_t bus;
164133589Smarius	device_t dev;
165133589Smarius} DEFAULT ofw_bus_default_get_node;
166133589Smarius
167133589Smarius# Get the firmware device type for the device dev on the bus. The default
168133589Smarius# method will return NULL, which means the device doesn't have such a property.
169133589SmariusMETHOD const char * get_type {
170133589Smarius	device_t bus;
171133589Smarius	device_t dev;
172133589Smarius} DEFAULT ofw_bus_default_get_type;
173256994Snwhitehorn
174256994Snwhitehorn# Map an (interrupt parent, IRQ) pair to a unique system-wide interrupt number.
175256994SnwhitehornMETHOD int map_intr {
176256994Snwhitehorn	device_t bus;
177256994Snwhitehorn	device_t dev;
178256994Snwhitehorn	phandle_t iparent;
179256994Snwhitehorn	int irq;
180256994Snwhitehorn} DEFAULT ofw_bus_default_map_intr;
181256994Snwhitehorn
182256994Snwhitehorn# Configure an interrupt using the device-tree encoded sense key (the second
183256994Snwhitehorn# value in the interrupts property if interrupt-cells is 2). IRQ should be
184256994Snwhitehorn# encoded as from ofw_bus_map_intr().
185256994SnwhitehornMETHOD int config_intr {
186256994Snwhitehorn	device_t bus;
187256994Snwhitehorn	device_t dev;
188256994Snwhitehorn	int irq;
189256994Snwhitehorn	int sense;
190256994Snwhitehorn} DEFAULT ofw_bus_default_config_intr;
191256994Snwhitehorn
192