xref: /freebsd/sys/dev/bhnd/bcma/bcmavar.h (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org>
5  * Copyright (c) 2017 The FreeBSD Foundation
6  * All rights reserved.
7  *
8  * Portions of this software were developed by Landon Fuller
9  * under sponsorship from the FreeBSD Foundation.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
19  *    redistribution must be conditioned upon including a substantially
20  *    similar Disclaimer requirement for further binary redistribution.
21  *
22  * NO WARRANTY
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
26  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
27  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
28  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
31  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33  * THE POSSIBILITY OF SUCH DAMAGES.
34  *
35  * $FreeBSD$
36  */
37 
38 #ifndef _BCMA_BCMAVAR_H_
39 #define _BCMA_BCMAVAR_H_
40 
41 #include <sys/param.h>
42 #include <sys/bus.h>
43 #include <sys/limits.h>
44 
45 #include <machine/bus.h>
46 #include <sys/rman.h>
47 
48 #include "bcma.h"
49 
50 /*
51  * Internal definitions shared by bcma(4) driver implementations.
52  */
53 
54 /** Base resource ID for per-core agent register allocations */
55 #define	BCMA_AGENT_RID_BASE	100
56 
57 /**
58  * Return the device's core index.
59  *
60  * @param _dinfo The bcma_devinfo instance to query.
61  */
62 #define	BCMA_DINFO_COREIDX(_dinfo)	\
63 	((_dinfo)->corecfg->core_info.core_idx)
64 
65 /** BCMA port identifier. */
66 typedef u_int		bcma_pid_t;
67 #define BCMA_PID_MAX	UINT_MAX	/**< Maximum bcma_pid_t value */
68 
69 /** BCMA per-port region map identifier. */
70 typedef u_int		bcma_rmid_t;
71 #define	BCMA_RMID_MAX	UINT_MAX	/**< Maximum bcma_rmid_t value */
72 
73 struct bcma_devinfo;
74 struct bcma_corecfg;
75 struct bcma_intr;
76 struct bcma_map;
77 struct bcma_mport;
78 struct bcma_sport;
79 
80 int			 bcma_probe(device_t dev);
81 int			 bcma_attach(device_t dev);
82 int			 bcma_detach(device_t dev);
83 u_int			 bcma_get_intr_count(device_t dev, device_t child);
84 int			 bcma_get_intr_ivec(device_t dev, device_t child,
85 			     u_int intr, uint32_t *ivec);
86 
87 int			 bcma_add_children(device_t bus);
88 
89 struct bcma_sport_list	*bcma_corecfg_get_port_list(struct bcma_corecfg *cfg,
90 			     bhnd_port_type type);
91 
92 struct bcma_devinfo	*bcma_alloc_dinfo(device_t bus);
93 int			 bcma_init_dinfo(device_t bus, device_t child,
94 			     struct bcma_devinfo *dinfo,
95 			     struct bcma_corecfg *corecfg);
96 void			 bcma_free_dinfo(device_t bus, device_t child,
97 			     struct bcma_devinfo *dinfo);
98 
99 struct bcma_corecfg	*bcma_alloc_corecfg(u_int core_index, int core_unit,
100 			     uint16_t vendor, uint16_t device, uint8_t hwrev);
101 void			 bcma_free_corecfg(struct bcma_corecfg *corecfg);
102 
103 struct bcma_intr	*bcma_alloc_intr(uint8_t bank, uint8_t sel,
104 			     uint8_t line);
105 void			 bcma_free_intr(struct bcma_intr *intr);
106 
107 struct bcma_sport	*bcma_alloc_sport(bcma_pid_t port_num, bhnd_port_type port_type);
108 void			 bcma_free_sport(struct bcma_sport *sport);
109 
110 int			 bcma_dmp_wait_reset(device_t child,
111 			     struct bcma_devinfo *dinfo);
112 int			 bcma_dmp_write_reset(device_t child,
113 			     struct bcma_devinfo *dinfo, uint32_t value);
114 
115 /** BCMA master port descriptor */
116 struct bcma_mport {
117 	bcma_pid_t	mp_num;		/**< AXI port identifier (bus-unique) */
118 	bcma_pid_t	mp_vid;		/**< AXI master virtual ID (core-unique) */
119 	STAILQ_ENTRY(bcma_mport) mp_link;
120 };
121 
122 /** BCMA memory region descriptor */
123 struct bcma_map {
124 	bcma_rmid_t	m_region_num;	/**< region identifier (port-unique). */
125 	bhnd_addr_t	m_base;		/**< base address */
126 	bhnd_size_t	m_size;		/**< size */
127 	int		m_rid;		/**< bus resource id, or -1. */
128 
129 	STAILQ_ENTRY(bcma_map) m_link;
130 };
131 
132 /** BCMA interrupt descriptor */
133 struct bcma_intr {
134 	uint8_t		i_bank;		/**< OOB bank (see BCMA_OOB_BANK[A-D]) */
135 	uint8_t		i_sel;		/**< OOB selector (0-7) */
136 	uint8_t		i_busline;	/**< OOB bus line assigned to this selector */
137 	bool		i_mapped;	/**< if an irq has been mapped for this selector */
138 	int		i_rid;		/**< bus resource id, or -1 */
139 	rman_res_t	i_irq;		/**< the mapped bus irq, if any */
140 
141 	STAILQ_ENTRY(bcma_intr) i_link;
142 };
143 
144 /** BCMA slave port descriptor */
145 struct bcma_sport {
146 	bcma_pid_t	sp_num;		/**< slave port number (core-unique) */
147 	bhnd_port_type	sp_type;	/**< port type */
148 
149 	u_long		sp_num_maps;	/**< number of regions mapped to this port */
150 	STAILQ_HEAD(, bcma_map) sp_maps;
151 	STAILQ_ENTRY(bcma_sport) sp_link;
152 };
153 
154 STAILQ_HEAD(bcma_mport_list,	bcma_mport);
155 STAILQ_HEAD(bcma_intr_list,	bcma_intr);
156 STAILQ_HEAD(bcma_sport_list,	bcma_sport);
157 
158 /** BCMA IP core/block configuration */
159 struct bcma_corecfg {
160 	struct bhnd_core_info	core_info;	/**< standard core info */
161 
162 	u_long		num_master_ports;	/**< number of master port descriptors. */
163 	struct bcma_mport_list	master_ports;	/**< master port descriptors */
164 
165 	u_long		num_dev_ports;		/**< number of device slave port descriptors. */
166 	struct bcma_sport_list	dev_ports;	/**< device port descriptors */
167 
168 	u_long		num_bridge_ports;	/**< number of bridge slave port descriptors. */
169 	struct bcma_sport_list	bridge_ports;	/**< bridge port descriptors */
170 
171 	u_long		num_wrapper_ports;	/**< number of wrapper slave port descriptors. */
172 	struct bcma_sport_list	wrapper_ports;	/**< wrapper port descriptors */
173 };
174 
175 /**
176  * BCMA per-device info
177  */
178 struct bcma_devinfo {
179 	struct resource_list	 resources;	/**< Slave port memory regions. */
180 	struct bcma_corecfg	*corecfg;	/**< IP core/block config */
181 
182 	struct bhnd_resource	*res_agent;	/**< Agent (wrapper) resource, or NULL. Not
183 						  *  all bcma(4) cores have or require an agent. */
184 	int			 rid_agent;	/**< Agent resource ID, or -1 */
185 
186 	u_int			 num_intrs;	/**< number of interrupt descriptors. */
187 	struct bcma_intr_list	 intrs;		/**< interrupt descriptors */
188 
189 	void			*pmu_info;	/**< Bus-managed PMU state, or NULL */
190 };
191 
192 /** BMCA per-instance state */
193 struct bcma_softc {
194 	struct bhnd_softc	bhnd_sc;	/**< bhnd state */
195 };
196 
197 #endif /* _BCMA_BCMAVAR_H_ */
198