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;
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;
59133589Smarius
60152683Smarius	static const struct ofw_bus_devinfo *
61152683Smarius	ofw_bus_default_get_devinfo(device_t bus, device_t dev)
62152683Smarius	{
63152683Smarius
64152683Smarius		return (NULL);
65152683Smarius	}
66152683Smarius
67133589Smarius	static const char *
68133589Smarius	ofw_bus_default_get_compat(device_t bus, device_t dev)
69133589Smarius	{
70133589Smarius
71133589Smarius		return (NULL);
72133589Smarius	}
73133589Smarius
74133589Smarius	static const char *
75133589Smarius	ofw_bus_default_get_model(device_t bus, device_t dev)
76133589Smarius	{
77133589Smarius
78133589Smarius		return (NULL);
79133589Smarius	}
80133589Smarius
81133589Smarius	static const char *
82133589Smarius	ofw_bus_default_get_name(device_t bus, device_t dev)
83133589Smarius	{
84133589Smarius
85133589Smarius		return (NULL);
86133589Smarius	}
87133589Smarius
88133589Smarius	static phandle_t
89133589Smarius	ofw_bus_default_get_node(device_t bus, device_t dev)
90133589Smarius	{
91133589Smarius
92233018Snwhitehorn		return (-1);
93133589Smarius	}
94133589Smarius
95133589Smarius	static const char *
96133589Smarius	ofw_bus_default_get_type(device_t bus, device_t dev)
97133589Smarius	{
98133589Smarius
99133589Smarius		return (NULL);
100133589Smarius	}
101133589Smarius};
102133589Smarius
103152683Smarius# Get the ofw_bus_devinfo struct for the device dev on the bus. Used for bus
104152683Smarius# drivers which use the generic methods in ofw_bus_subr.c to implement the
105152683Smarius# reset of this interface. The default method will return NULL, which means
106152683Smarius# there is no such struct associated with the device.
107152683SmariusMETHOD const struct ofw_bus_devinfo * get_devinfo {
108152683Smarius	device_t bus;
109152683Smarius	device_t dev;
110152683Smarius} DEFAULT ofw_bus_default_get_devinfo;
111152683Smarius
112133589Smarius# Get the alternate firmware name for the device dev on the bus. The default
113133589Smarius# method will return NULL, which means the device doesn't have such a property.
114133589SmariusMETHOD const char * get_compat {
115133589Smarius	device_t bus;
116133589Smarius	device_t dev;
117133589Smarius} DEFAULT ofw_bus_default_get_compat;
118133589Smarius
119133589Smarius# Get the firmware model name for the device dev on the bus. The default method
120133589Smarius# will return NULL, which means the device doesn't have such a property.
121133589SmariusMETHOD const char * get_model {
122133589Smarius	device_t bus;
123133589Smarius	device_t dev;
124133589Smarius} DEFAULT ofw_bus_default_get_model;
125133589Smarius
126133589Smarius# Get the firmware name for the device dev on the bus. The default method will
127133589Smarius# return NULL, which means the device doesn't have such a property.
128133589SmariusMETHOD const char * get_name {
129133589Smarius	device_t bus;
130133589Smarius	device_t dev;
131133589Smarius} DEFAULT ofw_bus_default_get_name;
132133589Smarius
133133589Smarius# Get the firmware node for the device dev on the bus. The default method will
134133589Smarius# return 0, which signals that there is no such node.
135133589SmariusMETHOD phandle_t get_node {
136133589Smarius	device_t bus;
137133589Smarius	device_t dev;
138133589Smarius} DEFAULT ofw_bus_default_get_node;
139133589Smarius
140133589Smarius# Get the firmware device type for the device dev on the bus. The default
141133589Smarius# method will return NULL, which means the device doesn't have such a property.
142133589SmariusMETHOD const char * get_type {
143133589Smarius	device_t bus;
144133589Smarius	device_t dev;
145133589Smarius} DEFAULT ofw_bus_default_get_type;
146