xref: /freebsd/sys/dev/bhnd/bcma/bcmavar.h (revision 2ff63af9)
14ad7e9b0SAdrian Chadd /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
36e778a7eSPedro F. Giffuni  *
4caeff9a3SLandon J. Fuller  * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org>
5caeff9a3SLandon J. Fuller  * Copyright (c) 2017 The FreeBSD Foundation
64ad7e9b0SAdrian Chadd  * All rights reserved.
74ad7e9b0SAdrian Chadd  *
8caeff9a3SLandon J. Fuller  * Portions of this software were developed by Landon Fuller
9caeff9a3SLandon J. Fuller  * under sponsorship from the FreeBSD Foundation.
10caeff9a3SLandon J. Fuller  *
114ad7e9b0SAdrian Chadd  * Redistribution and use in source and binary forms, with or without
124ad7e9b0SAdrian Chadd  * modification, are permitted provided that the following conditions
134ad7e9b0SAdrian Chadd  * are met:
144ad7e9b0SAdrian Chadd  * 1. Redistributions of source code must retain the above copyright
154ad7e9b0SAdrian Chadd  *    notice, this list of conditions and the following disclaimer,
164ad7e9b0SAdrian Chadd  *    without modification.
174ad7e9b0SAdrian Chadd  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
184ad7e9b0SAdrian Chadd  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
194ad7e9b0SAdrian Chadd  *    redistribution must be conditioned upon including a substantially
204ad7e9b0SAdrian Chadd  *    similar Disclaimer requirement for further binary redistribution.
214ad7e9b0SAdrian Chadd  *
224ad7e9b0SAdrian Chadd  * NO WARRANTY
234ad7e9b0SAdrian Chadd  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
244ad7e9b0SAdrian Chadd  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
254ad7e9b0SAdrian Chadd  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
264ad7e9b0SAdrian Chadd  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
274ad7e9b0SAdrian Chadd  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
284ad7e9b0SAdrian Chadd  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
294ad7e9b0SAdrian Chadd  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
304ad7e9b0SAdrian Chadd  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
314ad7e9b0SAdrian Chadd  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
324ad7e9b0SAdrian Chadd  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
334ad7e9b0SAdrian Chadd  * THE POSSIBILITY OF SUCH DAMAGES.
344ad7e9b0SAdrian Chadd  *
354ad7e9b0SAdrian Chadd  */
364ad7e9b0SAdrian Chadd 
374ad7e9b0SAdrian Chadd #ifndef _BCMA_BCMAVAR_H_
384ad7e9b0SAdrian Chadd #define _BCMA_BCMAVAR_H_
394ad7e9b0SAdrian Chadd 
404ad7e9b0SAdrian Chadd #include <sys/param.h>
414ad7e9b0SAdrian Chadd #include <sys/bus.h>
424ad7e9b0SAdrian Chadd #include <sys/limits.h>
434ad7e9b0SAdrian Chadd 
444ad7e9b0SAdrian Chadd #include <machine/bus.h>
454ad7e9b0SAdrian Chadd #include <sys/rman.h>
464ad7e9b0SAdrian Chadd 
474ad7e9b0SAdrian Chadd #include "bcma.h"
484ad7e9b0SAdrian Chadd 
494ad7e9b0SAdrian Chadd /*
504ad7e9b0SAdrian Chadd  * Internal definitions shared by bcma(4) driver implementations.
514ad7e9b0SAdrian Chadd  */
524ad7e9b0SAdrian Chadd 
53111d7cb2SLandon J. Fuller /** Base resource ID for per-core agent register allocations */
54111d7cb2SLandon J. Fuller #define	BCMA_AGENT_RID_BASE	100
55111d7cb2SLandon J. Fuller 
56111d7cb2SLandon J. Fuller /**
57111d7cb2SLandon J. Fuller  * Return the device's core index.
58111d7cb2SLandon J. Fuller  *
59111d7cb2SLandon J. Fuller  * @param _dinfo The bcma_devinfo instance to query.
60111d7cb2SLandon J. Fuller  */
61111d7cb2SLandon J. Fuller #define	BCMA_DINFO_COREIDX(_dinfo)	\
62111d7cb2SLandon J. Fuller 	((_dinfo)->corecfg->core_info.core_idx)
63111d7cb2SLandon J. Fuller 
644ad7e9b0SAdrian Chadd /** BCMA port identifier. */
654ad7e9b0SAdrian Chadd typedef u_int		bcma_pid_t;
664ad7e9b0SAdrian Chadd #define BCMA_PID_MAX	UINT_MAX	/**< Maximum bcma_pid_t value */
674ad7e9b0SAdrian Chadd 
684ad7e9b0SAdrian Chadd /** BCMA per-port region map identifier. */
694ad7e9b0SAdrian Chadd typedef u_int		bcma_rmid_t;
704ad7e9b0SAdrian Chadd #define	BCMA_RMID_MAX	UINT_MAX	/**< Maximum bcma_rmid_t value */
714ad7e9b0SAdrian Chadd 
724ad7e9b0SAdrian Chadd struct bcma_devinfo;
734ad7e9b0SAdrian Chadd struct bcma_corecfg;
74caeff9a3SLandon J. Fuller struct bcma_intr;
754ad7e9b0SAdrian Chadd struct bcma_map;
764ad7e9b0SAdrian Chadd struct bcma_mport;
774ad7e9b0SAdrian Chadd struct bcma_sport;
784ad7e9b0SAdrian Chadd 
794ad7e9b0SAdrian Chadd int			 bcma_probe(device_t dev);
804ad7e9b0SAdrian Chadd int			 bcma_attach(device_t dev);
814ad7e9b0SAdrian Chadd int			 bcma_detach(device_t dev);
82caeff9a3SLandon J. Fuller u_int			 bcma_get_intr_count(device_t dev, device_t child);
83caeff9a3SLandon J. Fuller int			 bcma_get_intr_ivec(device_t dev, device_t child,
84824b48efSLandon J. Fuller 			     u_int intr, uint32_t *ivec);
854ad7e9b0SAdrian Chadd 
86664a7497SLandon J. Fuller int			 bcma_add_children(device_t bus);
874ad7e9b0SAdrian Chadd 
884ad7e9b0SAdrian Chadd struct bcma_sport_list	*bcma_corecfg_get_port_list(struct bcma_corecfg *cfg,
894ad7e9b0SAdrian Chadd 			     bhnd_port_type type);
904ad7e9b0SAdrian Chadd 
91688fc8c0SLandon J. Fuller struct bcma_devinfo	*bcma_alloc_dinfo(device_t bus);
92caeff9a3SLandon J. Fuller int			 bcma_init_dinfo(device_t bus, device_t child,
93688fc8c0SLandon J. Fuller 			     struct bcma_devinfo *dinfo,
944ad7e9b0SAdrian Chadd 			     struct bcma_corecfg *corecfg);
95caeff9a3SLandon J. Fuller void			 bcma_free_dinfo(device_t bus, device_t child,
964ad7e9b0SAdrian Chadd 			     struct bcma_devinfo *dinfo);
974ad7e9b0SAdrian Chadd 
984ad7e9b0SAdrian Chadd struct bcma_corecfg	*bcma_alloc_corecfg(u_int core_index, int core_unit,
994ad7e9b0SAdrian Chadd 			     uint16_t vendor, uint16_t device, uint8_t hwrev);
1004ad7e9b0SAdrian Chadd void			 bcma_free_corecfg(struct bcma_corecfg *corecfg);
1014ad7e9b0SAdrian Chadd 
102caeff9a3SLandon J. Fuller struct bcma_intr	*bcma_alloc_intr(uint8_t bank, uint8_t sel,
103caeff9a3SLandon J. Fuller 			     uint8_t line);
104caeff9a3SLandon J. Fuller void			 bcma_free_intr(struct bcma_intr *intr);
105caeff9a3SLandon J. Fuller 
1064ad7e9b0SAdrian Chadd struct bcma_sport	*bcma_alloc_sport(bcma_pid_t port_num, bhnd_port_type port_type);
1074ad7e9b0SAdrian Chadd void			 bcma_free_sport(struct bcma_sport *sport);
1084ad7e9b0SAdrian Chadd 
1098a03f98aSLandon J. Fuller int			 bcma_dmp_wait_reset(device_t child,
1108a03f98aSLandon J. Fuller 			     struct bcma_devinfo *dinfo);
1118a03f98aSLandon J. Fuller int			 bcma_dmp_write_reset(device_t child,
1128a03f98aSLandon J. Fuller 			     struct bcma_devinfo *dinfo, uint32_t value);
1138a03f98aSLandon J. Fuller 
1144ad7e9b0SAdrian Chadd /** BCMA master port descriptor */
1154ad7e9b0SAdrian Chadd struct bcma_mport {
1164ad7e9b0SAdrian Chadd 	bcma_pid_t	mp_num;		/**< AXI port identifier (bus-unique) */
1174ad7e9b0SAdrian Chadd 	bcma_pid_t	mp_vid;		/**< AXI master virtual ID (core-unique) */
1184ad7e9b0SAdrian Chadd 	STAILQ_ENTRY(bcma_mport) mp_link;
1194ad7e9b0SAdrian Chadd };
1204ad7e9b0SAdrian Chadd 
1214ad7e9b0SAdrian Chadd /** BCMA memory region descriptor */
1224ad7e9b0SAdrian Chadd struct bcma_map {
1234ad7e9b0SAdrian Chadd 	bcma_rmid_t	m_region_num;	/**< region identifier (port-unique). */
1244ad7e9b0SAdrian Chadd 	bhnd_addr_t	m_base;		/**< base address */
1254ad7e9b0SAdrian Chadd 	bhnd_size_t	m_size;		/**< size */
1264ad7e9b0SAdrian Chadd 	int		m_rid;		/**< bus resource id, or -1. */
1274ad7e9b0SAdrian Chadd 
1284ad7e9b0SAdrian Chadd 	STAILQ_ENTRY(bcma_map) m_link;
1294ad7e9b0SAdrian Chadd };
1304ad7e9b0SAdrian Chadd 
131caeff9a3SLandon J. Fuller /** BCMA interrupt descriptor */
132caeff9a3SLandon J. Fuller struct bcma_intr {
133caeff9a3SLandon J. Fuller 	uint8_t		i_bank;		/**< OOB bank (see BCMA_OOB_BANK[A-D]) */
134caeff9a3SLandon J. Fuller 	uint8_t		i_sel;		/**< OOB selector (0-7) */
135caeff9a3SLandon J. Fuller 	uint8_t		i_busline;	/**< OOB bus line assigned to this selector */
136caeff9a3SLandon J. Fuller 	bool		i_mapped;	/**< if an irq has been mapped for this selector */
137caeff9a3SLandon J. Fuller 	int		i_rid;		/**< bus resource id, or -1 */
138caeff9a3SLandon J. Fuller 	rman_res_t	i_irq;		/**< the mapped bus irq, if any */
139caeff9a3SLandon J. Fuller 
140caeff9a3SLandon J. Fuller 	STAILQ_ENTRY(bcma_intr) i_link;
141caeff9a3SLandon J. Fuller };
142caeff9a3SLandon J. Fuller 
1434ad7e9b0SAdrian Chadd /** BCMA slave port descriptor */
1444ad7e9b0SAdrian Chadd struct bcma_sport {
1454ad7e9b0SAdrian Chadd 	bcma_pid_t	sp_num;		/**< slave port number (core-unique) */
1464ad7e9b0SAdrian Chadd 	bhnd_port_type	sp_type;	/**< port type */
1474ad7e9b0SAdrian Chadd 
1484ad7e9b0SAdrian Chadd 	u_long		sp_num_maps;	/**< number of regions mapped to this port */
1494ad7e9b0SAdrian Chadd 	STAILQ_HEAD(, bcma_map) sp_maps;
1504ad7e9b0SAdrian Chadd 	STAILQ_ENTRY(bcma_sport) sp_link;
1514ad7e9b0SAdrian Chadd };
1524ad7e9b0SAdrian Chadd 
1534ad7e9b0SAdrian Chadd STAILQ_HEAD(bcma_mport_list,	bcma_mport);
154caeff9a3SLandon J. Fuller STAILQ_HEAD(bcma_intr_list,	bcma_intr);
1554ad7e9b0SAdrian Chadd STAILQ_HEAD(bcma_sport_list,	bcma_sport);
1564ad7e9b0SAdrian Chadd 
1574ad7e9b0SAdrian Chadd /** BCMA IP core/block configuration */
1584ad7e9b0SAdrian Chadd struct bcma_corecfg {
1594ad7e9b0SAdrian Chadd 	struct bhnd_core_info	core_info;	/**< standard core info */
1604ad7e9b0SAdrian Chadd 
1614ad7e9b0SAdrian Chadd 	u_long		num_master_ports;	/**< number of master port descriptors. */
1624ad7e9b0SAdrian Chadd 	struct bcma_mport_list	master_ports;	/**< master port descriptors */
1634ad7e9b0SAdrian Chadd 
1644ad7e9b0SAdrian Chadd 	u_long		num_dev_ports;		/**< number of device slave port descriptors. */
1654ad7e9b0SAdrian Chadd 	struct bcma_sport_list	dev_ports;	/**< device port descriptors */
1664ad7e9b0SAdrian Chadd 
1674ad7e9b0SAdrian Chadd 	u_long		num_bridge_ports;	/**< number of bridge slave port descriptors. */
1684ad7e9b0SAdrian Chadd 	struct bcma_sport_list	bridge_ports;	/**< bridge port descriptors */
1694ad7e9b0SAdrian Chadd 
1704ad7e9b0SAdrian Chadd 	u_long		num_wrapper_ports;	/**< number of wrapper slave port descriptors. */
1714ad7e9b0SAdrian Chadd 	struct bcma_sport_list	wrapper_ports;	/**< wrapper port descriptors */
1724ad7e9b0SAdrian Chadd };
1734ad7e9b0SAdrian Chadd 
1744ad7e9b0SAdrian Chadd /**
1754ad7e9b0SAdrian Chadd  * BCMA per-device info
1764ad7e9b0SAdrian Chadd  */
1774ad7e9b0SAdrian Chadd struct bcma_devinfo {
1784ad7e9b0SAdrian Chadd 	struct resource_list	 resources;	/**< Slave port memory regions. */
1794ad7e9b0SAdrian Chadd 	struct bcma_corecfg	*corecfg;	/**< IP core/block config */
1804ad7e9b0SAdrian Chadd 
1814ad7e9b0SAdrian Chadd 	struct bhnd_resource	*res_agent;	/**< Agent (wrapper) resource, or NULL. Not
1824ad7e9b0SAdrian Chadd 						  *  all bcma(4) cores have or require an agent. */
1834ad7e9b0SAdrian Chadd 	int			 rid_agent;	/**< Agent resource ID, or -1 */
1848a03f98aSLandon J. Fuller 
185caeff9a3SLandon J. Fuller 	u_int			 num_intrs;	/**< number of interrupt descriptors. */
186caeff9a3SLandon J. Fuller 	struct bcma_intr_list	 intrs;		/**< interrupt descriptors */
187caeff9a3SLandon J. Fuller 
1884e96bf3aSLandon J. Fuller 	void			*pmu_info;	/**< Bus-managed PMU state, or NULL */
1894ad7e9b0SAdrian Chadd };
1904ad7e9b0SAdrian Chadd 
1914ad7e9b0SAdrian Chadd /** BMCA per-instance state */
1924ad7e9b0SAdrian Chadd struct bcma_softc {
1934ad7e9b0SAdrian Chadd 	struct bhnd_softc	bhnd_sc;	/**< bhnd state */
1944ad7e9b0SAdrian Chadd };
1954ad7e9b0SAdrian Chadd 
1964ad7e9b0SAdrian Chadd #endif /* _BCMA_BCMAVAR_H_ */
197