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