xref: /freebsd/sys/dev/bhnd/bhndb/bhndbvar.h (revision caeff9a3c2626660d3e080d4d3b35bc53ec4417f)
14ad7e9b0SAdrian Chadd /*-
28e35bf83SLandon J. Fuller  * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org>
38e35bf83SLandon J. Fuller  * Copyright (c) 2017 The FreeBSD Foundation
44ad7e9b0SAdrian Chadd  * All rights reserved.
54ad7e9b0SAdrian Chadd  *
68e35bf83SLandon J. Fuller  * Portions of this software were developed by Landon Fuller
78e35bf83SLandon J. Fuller  * under sponsorship from the FreeBSD Foundation.
88e35bf83SLandon J. Fuller  *
94ad7e9b0SAdrian Chadd  * Redistribution and use in source and binary forms, with or without
104ad7e9b0SAdrian Chadd  * modification, are permitted provided that the following conditions
114ad7e9b0SAdrian Chadd  * are met:
124ad7e9b0SAdrian Chadd  * 1. Redistributions of source code must retain the above copyright
134ad7e9b0SAdrian Chadd  *    notice, this list of conditions and the following disclaimer,
144ad7e9b0SAdrian Chadd  *    without modification.
154ad7e9b0SAdrian Chadd  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
164ad7e9b0SAdrian Chadd  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
174ad7e9b0SAdrian Chadd  *    redistribution must be conditioned upon including a substantially
184ad7e9b0SAdrian Chadd  *    similar Disclaimer requirement for further binary redistribution.
194ad7e9b0SAdrian Chadd  *
204ad7e9b0SAdrian Chadd  * NO WARRANTY
214ad7e9b0SAdrian Chadd  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
224ad7e9b0SAdrian Chadd  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
234ad7e9b0SAdrian Chadd  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
244ad7e9b0SAdrian Chadd  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
254ad7e9b0SAdrian Chadd  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
264ad7e9b0SAdrian Chadd  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
274ad7e9b0SAdrian Chadd  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
284ad7e9b0SAdrian Chadd  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
294ad7e9b0SAdrian Chadd  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
304ad7e9b0SAdrian Chadd  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
314ad7e9b0SAdrian Chadd  * THE POSSIBILITY OF SUCH DAMAGES.
324ad7e9b0SAdrian Chadd  *
334ad7e9b0SAdrian Chadd  * $FreeBSD$
344ad7e9b0SAdrian Chadd  */
354ad7e9b0SAdrian Chadd 
364ad7e9b0SAdrian Chadd #ifndef _BHND_BHNDBVAR_H_
374ad7e9b0SAdrian Chadd #define _BHND_BHNDBVAR_H_
384ad7e9b0SAdrian Chadd 
394ad7e9b0SAdrian Chadd #include <sys/param.h>
404ad7e9b0SAdrian Chadd #include <sys/bus.h>
414ad7e9b0SAdrian Chadd #include <sys/kernel.h>
424ad7e9b0SAdrian Chadd #include <sys/lock.h>
434ad7e9b0SAdrian Chadd #include <sys/malloc.h>
444ad7e9b0SAdrian Chadd #include <sys/mutex.h>
454ad7e9b0SAdrian Chadd #include <sys/rman.h>
464ad7e9b0SAdrian Chadd 
474ad7e9b0SAdrian Chadd #include <dev/bhnd/bhndvar.h>
484ad7e9b0SAdrian Chadd #include "bhndb.h"
494ad7e9b0SAdrian Chadd 
504ad7e9b0SAdrian Chadd #include "bhndb_if.h"
514ad7e9b0SAdrian Chadd 
524ad7e9b0SAdrian Chadd /*
534ad7e9b0SAdrian Chadd  * Definitions shared by bhndb(4) driver implementations.
544ad7e9b0SAdrian Chadd  */
554ad7e9b0SAdrian Chadd 
564ad7e9b0SAdrian Chadd DECLARE_CLASS(bhndb_driver);
574ad7e9b0SAdrian Chadd 
58*caeff9a3SLandon J. Fuller /* forward declarations */
59*caeff9a3SLandon J. Fuller struct bhndb_intr_isrc;
604ad7e9b0SAdrian Chadd struct bhndb_resources;
6189294a78SLandon J. Fuller struct bhndb_host_resources;
624ad7e9b0SAdrian Chadd 
6389294a78SLandon J. Fuller int				 bhndb_attach(device_t dev,
6489294a78SLandon J. Fuller 				     struct bhnd_chipid *cid,
6589294a78SLandon J. Fuller 				     struct bhnd_core_info *cores, u_int ncores,
6689294a78SLandon J. Fuller 				     struct bhnd_core_info *bridge_core,
6789294a78SLandon J. Fuller 				     bhnd_erom_class_t *erom_class);
684ad7e9b0SAdrian Chadd 
694ad7e9b0SAdrian Chadd int				 bhndb_generic_probe(device_t dev);
704ad7e9b0SAdrian Chadd int				 bhndb_generic_detach(device_t dev);
714ad7e9b0SAdrian Chadd int				 bhndb_generic_suspend(device_t dev);
724ad7e9b0SAdrian Chadd int				 bhndb_generic_resume(device_t dev);
7389294a78SLandon J. Fuller int				 bhndb_generic_init_full_config(device_t dev,
7489294a78SLandon J. Fuller 				     device_t child,
754ad7e9b0SAdrian Chadd 				     const struct bhndb_hw_priority *hw_prio_table);
764ad7e9b0SAdrian Chadd 
7789294a78SLandon J. Fuller int				 bhnd_generic_br_suspend_child(device_t dev,
7889294a78SLandon J. Fuller 				     device_t child);
7989294a78SLandon J. Fuller int				 bhnd_generic_br_resume_child(device_t dev,
8089294a78SLandon J. Fuller 				     device_t child);
8189294a78SLandon J. Fuller 
8289294a78SLandon J. Fuller int				 bhndb_find_hostb_core(
8389294a78SLandon J. Fuller 				     struct bhnd_core_info *cores, u_int ncores,
8489294a78SLandon J. Fuller 				     bhnd_devclass_t bridge_devclass,
8589294a78SLandon J. Fuller 				     struct bhnd_core_info *core);
8689294a78SLandon J. Fuller 
87*caeff9a3SLandon J. Fuller struct bhndb_intr_isrc		*bhndb_alloc_intr_isrc(device_t owner, int rid,
88*caeff9a3SLandon J. Fuller 				     rman_res_t start, rman_res_t end,
89*caeff9a3SLandon J. Fuller 				     rman_res_t count, u_int flags);
90*caeff9a3SLandon J. Fuller void				 bhndb_free_intr_isrc(
91*caeff9a3SLandon J. Fuller 				     struct bhndb_intr_isrc *isrc);
92*caeff9a3SLandon J. Fuller 
9389294a78SLandon J. Fuller int				 bhndb_alloc_host_resources(device_t dev,
9489294a78SLandon J. Fuller 				     const struct bhndb_hwcfg *hwcfg,
9589294a78SLandon J. Fuller 				     struct bhndb_host_resources **resources);
9689294a78SLandon J. Fuller void				 bhndb_release_host_resources(
9789294a78SLandon J. Fuller 				     struct bhndb_host_resources *resources);
9889294a78SLandon J. Fuller struct resource			*bhndb_host_resource_for_range(
9989294a78SLandon J. Fuller 				     struct bhndb_host_resources *resources,
10089294a78SLandon J. Fuller 				     int type, rman_res_t start,
10189294a78SLandon J. Fuller 				     rman_res_t count);
10289294a78SLandon J. Fuller struct resource			*bhndb_host_resource_for_regwin(
10389294a78SLandon J. Fuller 				     struct bhndb_host_resources *resources,
10489294a78SLandon J. Fuller 				     const struct bhndb_regwin *win);
10589294a78SLandon J. Fuller 
10689294a78SLandon J. Fuller size_t				 bhndb_regwin_count(
10789294a78SLandon J. Fuller 				     const struct bhndb_regwin *table,
10889294a78SLandon J. Fuller 				     bhndb_regwin_type_t type);
10989294a78SLandon J. Fuller 
11089294a78SLandon J. Fuller const struct bhndb_regwin	*bhndb_regwin_find_type(
11189294a78SLandon J. Fuller 				     const struct bhndb_regwin *table,
11289294a78SLandon J. Fuller 				     bhndb_regwin_type_t type,
11389294a78SLandon J. Fuller 				     bus_size_t min_size);
11489294a78SLandon J. Fuller 
11589294a78SLandon J. Fuller const struct bhndb_regwin	*bhndb_regwin_find_core(
11689294a78SLandon J. Fuller 				     const struct bhndb_regwin *table,
11789294a78SLandon J. Fuller 				     bhnd_devclass_t class, int unit,
11889294a78SLandon J. Fuller 				     bhnd_port_type port_type, u_int port,
11989294a78SLandon J. Fuller 				     u_int region);
12089294a78SLandon J. Fuller 
12189294a78SLandon J. Fuller const struct bhndb_regwin	*bhndb_regwin_find_best(
12289294a78SLandon J. Fuller 				     const struct bhndb_regwin *table,
12389294a78SLandon J. Fuller 				     bhnd_devclass_t class, int unit,
12489294a78SLandon J. Fuller 				     bhnd_port_type port_type, u_int port,
12589294a78SLandon J. Fuller 				     u_int region, bus_size_t min_size);
12689294a78SLandon J. Fuller 
12789294a78SLandon J. Fuller bool				 bhndb_regwin_match_core(
12889294a78SLandon J. Fuller 				     const struct bhndb_regwin *regw,
12989294a78SLandon J. Fuller 				     struct bhnd_core_info *core);
1304ad7e9b0SAdrian Chadd 
131e9378f45SAdrian Chadd /**
132e9378f45SAdrian Chadd  * bhndb child address space. Children either operate in the bridged
133e9378f45SAdrian Chadd  * SoC address space, or within the address space mapped to the host
134e9378f45SAdrian Chadd  * device (e.g. the PCI BAR(s)).
135e9378f45SAdrian Chadd  */
136e9378f45SAdrian Chadd typedef enum {
137e9378f45SAdrian Chadd 	BHNDB_ADDRSPACE_BRIDGED,	/**< bridged (SoC) address space */
138e9378f45SAdrian Chadd 	BHNDB_ADDRSPACE_NATIVE		/**< host address space */
139e9378f45SAdrian Chadd } bhndb_addrspace;
140e9378f45SAdrian Chadd 
1414ad7e9b0SAdrian Chadd /** bhndb child instance state */
1424ad7e9b0SAdrian Chadd struct bhndb_devinfo {
143e9378f45SAdrian Chadd 	bhndb_addrspace		addrspace;	/**< child address space. */
1444ad7e9b0SAdrian Chadd 	struct resource_list    resources;	/**< child resources. */
1454ad7e9b0SAdrian Chadd };
1464ad7e9b0SAdrian Chadd 
1474ad7e9b0SAdrian Chadd /**
148*caeff9a3SLandon J. Fuller  * Host interrupt source to which bridged interrupts may be routed.
149*caeff9a3SLandon J. Fuller  */
150*caeff9a3SLandon J. Fuller struct bhndb_intr_isrc {
151*caeff9a3SLandon J. Fuller 	device_t	 is_owner;	/**< host device (e.g. the pci device). */
152*caeff9a3SLandon J. Fuller 	struct resource	*is_res;	/**< irq resource */
153*caeff9a3SLandon J. Fuller 	int		 is_rid;	/**< irq resource ID */
154*caeff9a3SLandon J. Fuller };
155*caeff9a3SLandon J. Fuller 
156*caeff9a3SLandon J. Fuller /**
15789294a78SLandon J. Fuller  * Host resources allocated for a bridge hardware configuration.
15889294a78SLandon J. Fuller  */
15989294a78SLandon J. Fuller struct bhndb_host_resources {
16089294a78SLandon J. Fuller 	device_t			 owner;			/**< device owning the allocated resources */
16189294a78SLandon J. Fuller 	const struct bhndb_hwcfg	*cfg;			/**< bridge hardware configuration */
16289294a78SLandon J. Fuller 	struct resource_spec		*resource_specs;	/**< resource specification table */
16389294a78SLandon J. Fuller 	struct resource			**resources;		/**< allocated resource table */
16489294a78SLandon J. Fuller };
16589294a78SLandon J. Fuller 
16689294a78SLandon J. Fuller /**
1674ad7e9b0SAdrian Chadd  * bhndb driver instance state. Must be first member of all subclass
1684ad7e9b0SAdrian Chadd  * softc structures.
1694ad7e9b0SAdrian Chadd  */
1704ad7e9b0SAdrian Chadd struct bhndb_softc {
1714ad7e9b0SAdrian Chadd 	device_t			 dev;		/**< bridge device */
1724ad7e9b0SAdrian Chadd 	struct bhnd_chipid		 chipid;	/**< chip identification */
17389294a78SLandon J. Fuller 	struct bhnd_core_info		 bridge_core;	/**< bridge core info */
1744ad7e9b0SAdrian Chadd 
1754ad7e9b0SAdrian Chadd 	device_t			 parent_dev;	/**< parent device */
1764ad7e9b0SAdrian Chadd 	device_t			 bus_dev;	/**< child bhnd(4) bus */
1774ad7e9b0SAdrian Chadd 
1788e35bf83SLandon J. Fuller 	struct bhnd_service_registry	 services;	/**< local service registry */
1798e35bf83SLandon J. Fuller 
1804ad7e9b0SAdrian Chadd 	struct mtx			 sc_mtx;	/**< resource lock. */
1814ad7e9b0SAdrian Chadd 	struct bhndb_resources		*bus_res;	/**< bus resource state */
182*caeff9a3SLandon J. Fuller 	STAILQ_HEAD(,bhndb_intr_handler) bus_intrs;	/**< attached child interrupt handlers */
1834ad7e9b0SAdrian Chadd };
1844ad7e9b0SAdrian Chadd 
1854ad7e9b0SAdrian Chadd #endif /* _BHND_BHNDBVAR_H_ */
186