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