xref: /freebsd/sys/dev/bhnd/bhnd_private.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2017 The FreeBSD Foundation
5  *
6  * This software was developed by Landon Fuller under sponsorship from
7  * the FreeBSD Foundation.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #ifndef _BHND_BHND_PRIVATE_H_
32 #define _BHND_BHND_PRIVATE_H_
33 
34 #include <sys/param.h>
35 #include <sys/queue.h>
36 
37 #include "bhnd_types.h"
38 
39 /*
40  * Private bhnd(4) driver definitions.
41  */
42 
43 /**
44  * A bhnd(4) service registry entry.
45  */
46 struct bhnd_service_entry {
47 	device_t	provider;	/**< service provider */
48 	bhnd_service_t	service;	/**< service implemented */
49 	uint32_t	flags;		/**< entry flags (see BHND_SPF_*) */
50 	volatile u_int	refs;		/**< reference count; updated atomically
51 					     with only a shared lock held */
52 
53 	STAILQ_ENTRY(bhnd_service_entry) link;
54 };
55 
56 /**
57  * bhnd(4) per-core PMU clkctl quirks.
58  */
59 enum {
60 	/** On BCM4328-derived chipsets, the CLK_CTL_ST register CCS_HTAVAIL
61 	 *  and CCS_ALPAVAIL bits are swapped in the ChipCommon and PCMCIA
62 	 *  cores; the BHND_CCS0_* constants should be used. */
63 	BHND_CLKCTL_QUIRK_CCS0	= 1
64 };
65 
66 /**
67  * Per-core bhnd(4) PMU clkctl registers.
68  */
69 struct bhnd_core_clkctl {
70 	device_t		 cc_dev;		/**< core device */
71 	device_t		 cc_pmu_dev;		/**< pmu device */
72 	uint32_t		 cc_quirks;		/**< core-specific clkctl quirks */
73 	struct bhnd_resource	*cc_res;		/**< resource mapping core's clkctl register */
74 	bus_size_t		 cc_res_offset;		/**< offset to clkctl register */
75 	u_int			 cc_max_latency;	/**< maximum PMU transition latency, in microseconds */
76 	struct mtx		 cc_mtx;		/**< register read/modify/write lock */
77 };
78 
79 #define	BHND_ASSERT_CLKCTL_AVAIL(_clkctl)			\
80 	KASSERT(!bhnd_is_hw_suspended((_clkctl)->cc_dev),	\
81 	    ("reading clkctl on suspended core will trigger system livelock"))
82 
83 #define	BHND_CLKCTL_LOCK_INIT(_clkctl)		mtx_init(&(_clkctl)->cc_mtx, \
84     device_get_nameunit((_clkctl)->cc_dev), NULL, MTX_DEF)
85 #define	BHND_CLKCTL_LOCK(_clkctl)		mtx_lock(&(_clkctl)->cc_mtx)
86 #define	BHND_CLKCTL_UNLOCK(_clkctl)		mtx_unlock(&(_clkctl)->cc_mtx)
87 #define	BHND_CLKCTL_LOCK_ASSERT(_clkctl, what)	\
88     mtx_assert(&(_clkctl)->cc_mtx, what)
89 #define	BHND_CLKCTL_LOCK_DESTROY(_clkctl)	mtx_destroy(&(_clkctl->cc_mtx))
90 
91 #define	BHND_CLKCTL_READ_4(_clkctl)		\
92 	bhnd_bus_read_4((_clkctl)->cc_res, (_clkctl)->cc_res_offset)
93 
94 #define	BHND_CLKCTL_WRITE_4(_clkctl, _val)	\
95 	bhnd_bus_write_4((_clkctl)->cc_res, (_clkctl)->cc_res_offset, (_val))
96 
97 #define	BHND_CLKCTL_SET_4(_clkctl, _val, _mask)	\
98 	BHND_CLKCTL_WRITE_4((_clkctl),		\
99 	    ((_val) & (_mask)) | (BHND_CLKCTL_READ_4(_clkctl) & ~(_mask)))
100 
101 #endif /* _BHND_BHND_PRIVATE_H_ */
102