xref: /freebsd/sys/dev/dpaa2/dpaa2_mc_if.m (revision 61e21613)
1#-
2# SPDX-License-Identifier: BSD-2-Clause
3#
4# Copyright © 2021-2022 Dmitry Salychev
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 AND CONTRIBUTORS ``AS IS'' AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27
28#include <machine/bus.h>
29#include <dev/dpaa2/dpaa2_mc.h>
30
31/**
32 * @brief Interface of the DPAA2 Management Complex (MC) bus driver.
33 *
34 * It helps to manipulate DPAA2-specific resources (DPIOs, DPBPs, etc.)
35 */
36INTERFACE dpaa2_mc;
37
38#
39# Default implementation of the commands.
40#
41CODE {
42	static int
43	bypass_manage_dev(device_t dev, device_t dpaa2_dev, uint32_t flags)
44	{
45		if (device_get_parent(dev) != NULL)
46			return (DPAA2_MC_MANAGE_DEV(device_get_parent(dev),
47				dpaa2_dev, flags));
48		return (ENXIO);
49	}
50
51	static int
52	bypass_get_free_dev(device_t dev, device_t *dpaa2_dev,
53		enum dpaa2_dev_type devtype)
54	{
55		if (device_get_parent(dev) != NULL)
56			return (DPAA2_MC_GET_FREE_DEV(device_get_parent(dev),
57				dpaa2_dev, devtype));
58		return (ENXIO);
59	}
60
61	static int
62	bypass_get_dev(device_t dev, device_t *dpaa2_dev,
63		enum dpaa2_dev_type devtype, uint32_t obj_id)
64	{
65		if (device_get_parent(dev) != NULL)
66			return (DPAA2_MC_GET_DEV(device_get_parent(dev),
67				dpaa2_dev, devtype, obj_id));
68		return (ENXIO);
69	}
70
71	static int
72	bypass_get_shared_dev(device_t dev, device_t *dpaa2_dev,
73		enum dpaa2_dev_type devtype)
74	{
75		if (device_get_parent(dev) != NULL)
76			return (DPAA2_MC_GET_SHARED_DEV(device_get_parent(dev),
77				dpaa2_dev, devtype));
78		return (ENXIO);
79	}
80
81	static int
82	bypass_reserve_dev(device_t dev, device_t dpaa2_dev,
83		enum dpaa2_dev_type devtype)
84	{
85		if (device_get_parent(dev) != NULL)
86			return (DPAA2_MC_RESERVE_DEV(device_get_parent(dev),
87				dpaa2_dev, devtype));
88		return (ENXIO);
89	}
90
91	static int
92	bypass_release_dev(device_t dev, device_t dpaa2_dev,
93		enum dpaa2_dev_type devtype)
94	{
95		if (device_get_parent(dev) != NULL)
96			return (DPAA2_MC_RELEASE_DEV(device_get_parent(dev),
97				dpaa2_dev, devtype));
98		return (ENXIO);
99	}
100
101	static int
102	bypass_get_phy_dev(device_t dev, device_t *phy_dev, uint32_t id)
103	{
104		if (device_get_parent(dev) != NULL)
105			return (DPAA2_MC_GET_PHY_DEV(device_get_parent(dev),
106			    phy_dev, id));
107		return (ENXIO);
108	}
109}
110
111METHOD int manage_dev {
112	device_t	 dev;
113	device_t	 dpaa2_dev;
114	uint32_t	 flags;
115} DEFAULT bypass_manage_dev;
116
117METHOD int get_free_dev {
118	device_t	 dev;
119	device_t	*dpaa2_dev;
120	enum dpaa2_dev_type devtype;
121} DEFAULT bypass_get_free_dev;
122
123METHOD int get_dev {
124	device_t	 dev;
125	device_t	*dpaa2_dev;
126	enum dpaa2_dev_type devtype;
127	uint32_t	 obj_id;
128} DEFAULT bypass_get_dev;
129
130METHOD int get_shared_dev {
131	device_t	 dev;
132	device_t	*dpaa2_dev;
133	enum dpaa2_dev_type devtype;
134} DEFAULT bypass_get_shared_dev;
135
136METHOD int reserve_dev {
137	device_t	 dev;
138	device_t	 dpaa2_dev;
139	enum dpaa2_dev_type devtype;
140} DEFAULT bypass_reserve_dev;
141
142METHOD int release_dev {
143	device_t	 dev;
144	device_t	 dpaa2_dev;
145	enum dpaa2_dev_type devtype;
146} DEFAULT bypass_release_dev;
147
148METHOD int get_phy_dev {
149	device_t	 dev;
150	device_t	 *phy_dev;
151	uint32_t	 id;
152} DEFAULT bypass_get_phy_dev;
153