/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2017 The FreeBSD Foundation4*5* This software was developed by Landon Fuller under sponsorship from6* the FreeBSD Foundation.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions10* are met:11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in the15* documentation and/or other materials provided with the distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND18* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE20* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE21* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT25* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY26* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF27* SUCH DAMAGE.28*/2930#ifndef _BHND_BHND_PRIVATE_H_31#define _BHND_BHND_PRIVATE_H_3233#include <sys/param.h>34#include <sys/queue.h>3536#include "bhnd_types.h"3738/*39* Private bhnd(4) driver definitions.40*/4142/**43* A bhnd(4) service registry entry.44*/45struct bhnd_service_entry {46device_t provider; /**< service provider */47bhnd_service_t service; /**< service implemented */48uint32_t flags; /**< entry flags (see BHND_SPF_*) */49volatile u_int refs; /**< reference count; updated atomically50with only a shared lock held */5152STAILQ_ENTRY(bhnd_service_entry) link;53};5455/**56* bhnd(4) per-core PMU clkctl quirks.57*/58enum {59/** On BCM4328-derived chipsets, the CLK_CTL_ST register CCS_HTAVAIL60* and CCS_ALPAVAIL bits are swapped in the ChipCommon and PCMCIA61* cores; the BHND_CCS0_* constants should be used. */62BHND_CLKCTL_QUIRK_CCS0 = 163};6465/**66* Per-core bhnd(4) PMU clkctl registers.67*/68struct bhnd_core_clkctl {69device_t cc_dev; /**< core device */70device_t cc_pmu_dev; /**< pmu device */71uint32_t cc_quirks; /**< core-specific clkctl quirks */72struct bhnd_resource *cc_res; /**< resource mapping core's clkctl register */73bus_size_t cc_res_offset; /**< offset to clkctl register */74u_int cc_max_latency; /**< maximum PMU transition latency, in microseconds */75struct mtx cc_mtx; /**< register read/modify/write lock */76};7778#define BHND_ASSERT_CLKCTL_AVAIL(_clkctl) \79KASSERT(!bhnd_is_hw_suspended((_clkctl)->cc_dev), \80("reading clkctl on suspended core will trigger system livelock"))8182#define BHND_CLKCTL_LOCK_INIT(_clkctl) mtx_init(&(_clkctl)->cc_mtx, \83device_get_nameunit((_clkctl)->cc_dev), NULL, MTX_DEF)84#define BHND_CLKCTL_LOCK(_clkctl) mtx_lock(&(_clkctl)->cc_mtx)85#define BHND_CLKCTL_UNLOCK(_clkctl) mtx_unlock(&(_clkctl)->cc_mtx)86#define BHND_CLKCTL_LOCK_ASSERT(_clkctl, what) \87mtx_assert(&(_clkctl)->cc_mtx, what)88#define BHND_CLKCTL_LOCK_DESTROY(_clkctl) mtx_destroy(&(_clkctl->cc_mtx))8990#define BHND_CLKCTL_READ_4(_clkctl) \91bhnd_bus_read_4((_clkctl)->cc_res, (_clkctl)->cc_res_offset)9293#define BHND_CLKCTL_WRITE_4(_clkctl, _val) \94bhnd_bus_write_4((_clkctl)->cc_res, (_clkctl)->cc_res_offset, (_val))9596#define BHND_CLKCTL_SET_4(_clkctl, _val, _mask) \97BHND_CLKCTL_WRITE_4((_clkctl), \98((_val) & (_mask)) | (BHND_CLKCTL_READ_4(_clkctl) & ~(_mask)))99100#endif /* _BHND_BHND_PRIVATE_H_ */101102103