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