xref: /freebsd/sys/dev/bhnd/bcma/bcmavar.h (revision d9f0ce31900a48d1a2bfc1c8c86f79d1e831451a)
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 /** BCMA port identifier. */
49 typedef u_int		bcma_pid_t;
50 #define BCMA_PID_MAX	UINT_MAX	/**< Maximum bcma_pid_t value */
51 
52 /** BCMA per-port region map identifier. */
53 typedef u_int		bcma_rmid_t;
54 #define	BCMA_RMID_MAX	UINT_MAX	/**< Maximum bcma_rmid_t value */
55 
56 struct bcma_devinfo;
57 struct bcma_corecfg;
58 struct bcma_map;
59 struct bcma_mport;
60 struct bcma_sport;
61 
62 int			 bcma_probe(device_t dev);
63 int			 bcma_attach(device_t dev);
64 int			 bcma_detach(device_t dev);
65 
66 int			 bcma_add_children(device_t bus,
67 			     struct resource *erom_res, bus_size_t erom_offset);
68 
69 struct bcma_sport_list	*bcma_corecfg_get_port_list(struct bcma_corecfg *cfg,
70 			     bhnd_port_type type);
71 
72 struct bcma_devinfo	*bcma_alloc_dinfo(device_t bus,
73 			     struct bcma_corecfg *corecfg);
74 void			 bcma_free_dinfo(device_t bus,
75 			     struct bcma_devinfo *dinfo);
76 
77 struct bcma_corecfg	*bcma_alloc_corecfg(u_int core_index, int core_unit,
78 			     uint16_t vendor, uint16_t device, uint8_t hwrev);
79 void			 bcma_free_corecfg(struct bcma_corecfg *corecfg);
80 
81 struct bcma_sport	*bcma_alloc_sport(bcma_pid_t port_num, bhnd_port_type port_type);
82 void			 bcma_free_sport(struct bcma_sport *sport);
83 
84 /** BCMA master port descriptor */
85 struct bcma_mport {
86 	bcma_pid_t	mp_num;		/**< AXI port identifier (bus-unique) */
87 	bcma_pid_t	mp_vid;		/**< AXI master virtual ID (core-unique) */
88 	STAILQ_ENTRY(bcma_mport) mp_link;
89 };
90 
91 /** BCMA memory region descriptor */
92 struct bcma_map {
93 	bcma_rmid_t	m_region_num;	/**< region identifier (port-unique). */
94 	bhnd_addr_t	m_base;		/**< base address */
95 	bhnd_size_t	m_size;		/**< size */
96 	int		m_rid;		/**< bus resource id, or -1. */
97 
98 	STAILQ_ENTRY(bcma_map) m_link;
99 };
100 
101 /** BCMA slave port descriptor */
102 struct bcma_sport {
103 	bcma_pid_t	sp_num;		/**< slave port number (core-unique) */
104 	bhnd_port_type	sp_type;	/**< port type */
105 
106 	u_long		sp_num_maps;	/**< number of regions mapped to this port */
107 	STAILQ_HEAD(, bcma_map) sp_maps;
108 	STAILQ_ENTRY(bcma_sport) sp_link;
109 };
110 
111 STAILQ_HEAD(bcma_mport_list, bcma_mport);
112 STAILQ_HEAD(bcma_sport_list, bcma_sport);
113 
114 /** BCMA IP core/block configuration */
115 struct bcma_corecfg {
116 	struct bhnd_core_info	core_info;	/**< standard core info */
117 
118 	u_long		num_master_ports;	/**< number of master port descriptors. */
119 	struct bcma_mport_list	master_ports;	/**< master port descriptors */
120 
121 	u_long		num_dev_ports;		/**< number of device slave port descriptors. */
122 	struct bcma_sport_list	dev_ports;	/**< device port descriptors */
123 
124 	u_long		num_bridge_ports;	/**< number of bridge slave port descriptors. */
125 	struct bcma_sport_list	bridge_ports;	/**< bridge port descriptors */
126 
127 	u_long		num_wrapper_ports;	/**< number of wrapper slave port descriptors. */
128 	struct bcma_sport_list	wrapper_ports;	/**< wrapper port descriptors */
129 };
130 
131 /**
132  * BCMA per-device info
133  */
134 struct bcma_devinfo {
135 	struct resource_list	resources;	/**< Slave port memory regions. */
136 	struct bcma_corecfg	*corecfg;	/**< IP core/block config */
137 
138 	struct bhnd_resource	*res_agent;	/**< Agent (wrapper) resource, or NULL. Not
139 						  *  all bcma(4) cores have or require an agent. */
140 	int			 rid_agent;	/**< Agent resource ID, or -1 */
141 };
142 
143 
144 /** BMCA per-instance state */
145 struct bcma_softc {
146 	struct bhnd_softc	bhnd_sc;	/**< bhnd state */
147 };
148 
149 #endif /* _BCMA_BCMAVAR_H_ */