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 _BHND_CORES_PCIE2_BHND_PCIE2_VAR_H_
33 #define _BHND_CORES_PCIE2_BHND_PCIE2_VAR_H_
34 
35 #include <sys/param.h>
36 #include <sys/bus.h>
37 
38 /*
39  * Shared PCIe-G2 Bridge/Host Bridge definitions.
40  */
41 
42 DECLARE_CLASS(bhnd_pcie2_driver);
43 struct bhnd_pcie2_softc;
44 
45 int		bhnd_pcie2_generic_probe(device_t dev);
46 int		bhnd_pcie2_generic_attach(device_t dev);
47 int		bhnd_pcie2_generic_detach(device_t dev);
48 int		bhnd_pcie2_generic_suspend(device_t dev);
49 int		bhnd_pcie2_generic_resume(device_t dev);
50 
51 
52 uint32_t	bhnd_pcie2_read_proto_reg(struct bhnd_pcie2_softc *sc,
53 		    uint32_t addr);
54 void		bhnd_pcie2_write_proto_reg(struct bhnd_pcie2_softc *sc,
55 		    uint32_t addr, uint32_t val);
56 int		bhnd_pcie2_mdio_read(struct bhnd_pcie2_softc *sc, int phy,
57 		    int reg);
58 int		bhnd_pcie2_mdio_write(struct bhnd_pcie2_softc *sc, int phy,
59 		    int reg, int val);
60 int		bhnd_pcie2_mdio_read_ext(struct bhnd_pcie2_softc *sc, int phy,
61 		    int devaddr, int reg);
62 int		bhnd_pcie2_mdio_write_ext(struct bhnd_pcie2_softc *sc,
63 		    int phy, int devaddr, int reg, int val);
64 
65 /**
66  * bhnd_pcie2 child device info
67  */
68 struct bhnd_pcie2_devinfo {
69 	struct resource_list	resources;
70 };
71 
72 /*
73  * Generic PCIe-G2 bridge/end-point driver state.
74  *
75  * Must be first member of all subclass softc structures.
76  */
77 struct bhnd_pcie2_softc {
78 	device_t		 dev;		/**< pci device */
79 	uint32_t		 quirks;	/**< quirk flags */
80 
81 	struct mtx		 mtx;		/**< state mutex used to protect
82 						     interdependent register
83 						     accesses. */
84 
85 	struct bhnd_resource	*mem_res;	/**< device register block. */
86 	int			 mem_rid;	/**< register block RID */
87 };
88 
89 
90 #define	BHND_PCIE2_LOCK_INIT(sc) \
91 	mtx_init(&(sc)->mtx, device_get_nameunit((sc)->dev), \
92 	    "BHND PCIe-G2 driver lock", MTX_DEF)
93 #define	BHND_PCIE2_LOCK(sc)			mtx_lock(&(sc)->mtx)
94 #define	BHND_PCIE2_UNLOCK(sc)			mtx_unlock(&(sc)->mtx)
95 #define	BHND_PCIE2_LOCK_ASSERT(sc, what)	mtx_assert(&(sc)->mtx, what)
96 #define	BHND_PCIE2_LOCK_DESTROY(sc)		mtx_destroy(&(sc)->mtx)
97 
98 #endif /* _BHND_CORES_PCIE2_BHND_PCIE2_VAR_H_ */