xref: /freebsd/sys/dev/ofw/ofw_bus_if.m (revision e0c4386e)
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
27# Interface for retrieving the package handle and a subset, namely
28# 'compatible', 'device_type', 'model' and 'name', of the standard
29# properties of a device on an Open Firmware assisted bus for use
30# in device drivers. The rest of the standard properties, 'address',
31# 'interrupts', 'reg' and 'status', are not covered by this interface
32# as they are expected to be only of interest in the respective bus
33# driver.
34
35#include <sys/bus.h>
36
37#include <dev/ofw/openfirm.h>
38
39INTERFACE ofw_bus;
40
41HEADER {
42	struct ofw_bus_devinfo {
43		phandle_t	obd_node;
44		char		*obd_compat;
45		char		*obd_model;
46		char		*obd_name;
47		char		*obd_type;
48		char		*obd_status;
49	};
50};
51
52CODE {
53	static ofw_bus_get_devinfo_t ofw_bus_default_get_devinfo;
54	static ofw_bus_get_compat_t ofw_bus_default_get_compat;
55	static ofw_bus_get_model_t ofw_bus_default_get_model;
56	static ofw_bus_get_name_t ofw_bus_default_get_name;
57	static ofw_bus_get_node_t ofw_bus_default_get_node;
58	static ofw_bus_get_type_t ofw_bus_default_get_type;
59	static ofw_bus_map_intr_t ofw_bus_default_map_intr;
60
61	static const struct ofw_bus_devinfo *
62	ofw_bus_default_get_devinfo(device_t bus, device_t dev)
63	{
64
65		return (NULL);
66	}
67
68	static const char *
69	ofw_bus_default_get_compat(device_t bus, device_t dev)
70	{
71
72		return (NULL);
73	}
74
75	static const char *
76	ofw_bus_default_get_model(device_t bus, device_t dev)
77	{
78
79		return (NULL);
80	}
81
82	static const char *
83	ofw_bus_default_get_name(device_t bus, device_t dev)
84	{
85
86		return (NULL);
87	}
88
89	static phandle_t
90	ofw_bus_default_get_node(device_t bus, device_t dev)
91	{
92
93		return (-1);
94	}
95
96	static const char *
97	ofw_bus_default_get_type(device_t bus, device_t dev)
98	{
99
100		return (NULL);
101	}
102
103	int
104	ofw_bus_default_map_intr(device_t bus, device_t dev, phandle_t iparent,
105	    int icells, pcell_t *interrupt)
106	{
107		/* Propagate up the bus hierarchy until someone handles it. */
108		if (device_get_parent(bus) != NULL)
109			return OFW_BUS_MAP_INTR(device_get_parent(bus), dev,
110			    iparent, icells, interrupt);
111
112		/* If that fails, then assume a one-domain system */
113		return (interrupt[0]);
114	}
115};
116
117# Get the ofw_bus_devinfo struct for the device dev on the bus. Used for bus
118# drivers which use the generic methods in ofw_bus_subr.c to implement the
119# reset of this interface. The default method will return NULL, which means
120# there is no such struct associated with the device.
121METHOD const struct ofw_bus_devinfo * get_devinfo {
122	device_t bus;
123	device_t dev;
124} DEFAULT ofw_bus_default_get_devinfo;
125
126# Get the alternate firmware name for the device dev on the bus. The default
127# method will return NULL, which means the device doesn't have such a property.
128METHOD const char * get_compat {
129	device_t bus;
130	device_t dev;
131} DEFAULT ofw_bus_default_get_compat;
132
133# Get the firmware model name for the device dev on the bus. The default method
134# will return NULL, which means the device doesn't have such a property.
135METHOD const char * get_model {
136	device_t bus;
137	device_t dev;
138} DEFAULT ofw_bus_default_get_model;
139
140# Get the firmware name for the device dev on the bus. The default method will
141# return NULL, which means the device doesn't have such a property.
142METHOD const char * get_name {
143	device_t bus;
144	device_t dev;
145} DEFAULT ofw_bus_default_get_name;
146
147# Get the firmware node for the device dev on the bus. The default method will
148# return -1, which signals that there is no such node.
149METHOD phandle_t get_node {
150	device_t bus;
151	device_t dev;
152} DEFAULT ofw_bus_default_get_node;
153
154# Get the firmware device type for the device dev on the bus. The default
155# method will return NULL, which means the device doesn't have such a property.
156METHOD const char * get_type {
157	device_t bus;
158	device_t dev;
159} DEFAULT ofw_bus_default_get_type;
160
161# Map an (interrupt parent, IRQ) pair to a unique system-wide interrupt number.
162# If the interrupt encoding includes a sense field, the interrupt sense will
163# also be configured.
164METHOD int map_intr {
165	device_t bus;
166	device_t dev;
167	phandle_t iparent;
168	int icells;
169	pcell_t *interrupt;
170} DEFAULT ofw_bus_default_map_intr;
171