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