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