1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 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 * $FreeBSD$ 31 */ 32 33 #ifndef _BHND_BHND_PRIVATE_H_ 34 #define _BHND_BHND_PRIVATE_H_ 35 36 #include <sys/param.h> 37 #include <sys/queue.h> 38 39 #include "bhnd_types.h" 40 41 /* 42 * Private bhnd(4) driver definitions. 43 */ 44 45 /** 46 * A bhnd(4) service registry entry. 47 */ 48 struct bhnd_service_entry { 49 device_t provider; /**< service provider */ 50 bhnd_service_t service; /**< service implemented */ 51 uint32_t flags; /**< entry flags (see BHND_SPF_*) */ 52 volatile u_int refs; /**< reference count; updated atomically 53 with only a shared lock held */ 54 55 STAILQ_ENTRY(bhnd_service_entry) link; 56 }; 57 58 /** 59 * bhnd(4) per-core PMU clkctl quirks. 60 */ 61 enum { 62 /** On BCM4328-derived chipsets, the CLK_CTL_ST register CCS_HTAVAIL 63 * and CCS_ALPAVAIL bits are swapped in the ChipCommon and PCMCIA 64 * cores; the BHND_CCS0_* constants should be used. */ 65 BHND_CLKCTL_QUIRK_CCS0 = 1 66 }; 67 68 /** 69 * Per-core bhnd(4) PMU clkctl registers. 70 */ 71 struct bhnd_core_clkctl { 72 device_t cc_dev; /**< core device */ 73 device_t cc_pmu_dev; /**< pmu device */ 74 uint32_t cc_quirks; /**< core-specific clkctl quirks */ 75 struct bhnd_resource *cc_res; /**< resource mapping core's clkctl register */ 76 bus_size_t cc_res_offset; /**< offset to clkctl register */ 77 u_int cc_max_latency; /**< maximum PMU transition latency, in microseconds */ 78 struct mtx cc_mtx; /**< register read/modify/write lock */ 79 }; 80 81 #define BHND_ASSERT_CLKCTL_AVAIL(_clkctl) \ 82 KASSERT(!bhnd_is_hw_suspended((_clkctl)->cc_dev), \ 83 ("reading clkctl on suspended core will trigger system livelock")) 84 85 #define BHND_CLKCTL_LOCK_INIT(_clkctl) mtx_init(&(_clkctl)->cc_mtx, \ 86 device_get_nameunit((_clkctl)->cc_dev), NULL, MTX_DEF) 87 #define BHND_CLKCTL_LOCK(_clkctl) mtx_lock(&(_clkctl)->cc_mtx) 88 #define BHND_CLKCTL_UNLOCK(_clkctl) mtx_unlock(&(_clkctl)->cc_mtx) 89 #define BHND_CLKCTL_LOCK_ASSERT(_clkctl, what) \ 90 mtx_assert(&(_clkctl)->cc_mtx, what) 91 #define BHND_CLKCTL_LOCK_DESTROY(_clkctl) mtx_destroy(&(_clkctl->cc_mtx)) 92 93 #define BHND_CLKCTL_READ_4(_clkctl) \ 94 bhnd_bus_read_4((_clkctl)->cc_res, (_clkctl)->cc_res_offset) 95 96 #define BHND_CLKCTL_WRITE_4(_clkctl, _val) \ 97 bhnd_bus_write_4((_clkctl)->cc_res, (_clkctl)->cc_res_offset, (_val)) 98 99 #define BHND_CLKCTL_SET_4(_clkctl, _val, _mask) \ 100 BHND_CLKCTL_WRITE_4((_clkctl), \ 101 ((_val) & (_mask)) | (BHND_CLKCTL_READ_4(_clkctl) & ~(_mask))) 102 103 #endif /* _BHND_BHND_PRIVATE_H_ */ 104