]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/bhnd/cores/pmu/bhnd_pmuvar.h
MFV r317781:
[FreeBSD/FreeBSD.git] / sys / dev / bhnd / cores / pmu / bhnd_pmuvar.h
1 /*-
2  * Copyright (c) 2015 Landon Fuller <landon@landonf.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer,
10  *    without modification.
11  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13  *    redistribution must be conditioned upon including a substantially
14  *    similar Disclaimer requirement for further binary redistribution.
15  *
16  * NO WARRANTY
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27  * THE POSSIBILITY OF SUCH DAMAGES.
28  * 
29  * $FreeBSD$
30  */
31
32 #ifndef _BHND_CORES_PMU_BHND_PMUVAR_H_
33 #define _BHND_CORES_PMU_BHND_PMUVAR_H_
34
35 #include <sys/types.h>
36 #include <sys/rman.h>
37
38 #include "bhnd_pmu.h"
39
40 struct bhnd_pmu_query;
41 struct bhnd_pmu_io;
42
43 DECLARE_CLASS(bhnd_pmu_driver);
44 extern devclass_t bhnd_pmu_devclass;
45
46 int             bhnd_pmu_probe(device_t dev);
47 int             bhnd_pmu_attach(device_t dev, struct bhnd_resource *res);
48 int             bhnd_pmu_detach(device_t dev);
49 int             bhnd_pmu_suspend(device_t dev);
50 int             bhnd_pmu_resume(device_t dev);
51
52 int             bhnd_pmu_query_init(struct bhnd_pmu_query *query, device_t dev,
53                     struct bhnd_chipid id, const struct bhnd_pmu_io *io,
54                     void *ctx);
55 void            bhnd_pmu_query_fini(struct bhnd_pmu_query *query);
56
57 uint32_t        bhnd_pmu_si_clock(struct bhnd_pmu_query *sc);
58 uint32_t        bhnd_pmu_cpu_clock(struct bhnd_pmu_query *sc);
59 uint32_t        bhnd_pmu_mem_clock(struct bhnd_pmu_query *sc);
60 uint32_t        bhnd_pmu_alp_clock(struct bhnd_pmu_query *sc);
61 uint32_t        bhnd_pmu_ilp_clock(struct bhnd_pmu_query *sc);
62
63 /* 
64  * BHND PMU device quirks / features
65  */
66 enum {
67         /** No quirks */
68         BPMU_QUIRK_NONE                 = 0,
69
70         /** On BCM4328-derived chipsets, the CLK_CTL_ST register CCS_HTAVAIL
71          *  and CCS_ALPAVAIL bits are swapped; the BHND_CCS0_* constants should
72          *  be used. */
73         BPMU_QUIRK_CLKCTL_CCS0  = 1
74 };
75
76
77 /**
78  * PMU read-only query support.
79  * 
80  * Provides support for querying PMU information prior to availability of
81  * the bhnd(4) bus.
82  */
83 struct bhnd_pmu_query {
84         device_t                         dev;           /**< owning device, or NULL */
85         struct bhnd_chipid               cid;           /**< chip identification */
86         uint32_t                         caps;          /**< pmu capability flags. */
87
88         const struct bhnd_pmu_io        *io;            /**< I/O operations */
89         void                            *io_ctx;        /**< I/O callback context */
90
91         uint32_t                         ilp_cps;       /**< measured ILP cycles per second, or 0 */
92 };
93
94 /**
95  * PMU abstract I/O operations.
96  */
97 struct bhnd_pmu_io {
98         /* Read 4 bytes from PMU @p reg */
99         uint32_t        (*rd4)(bus_size_t reg, void *ctx);
100
101         /* Read 4 bytes to PMU @p reg */
102         void            (*wr4)(bus_size_t reg, uint32_t val, void *ctx);
103
104         /* Read ChipCommon's CHIP_ST register */
105         uint32_t        (*rd_chipst)(void *ctx);
106 };
107
108 /**
109  * bhnd_pmu driver instance state.
110  */
111 struct bhnd_pmu_softc {
112         device_t                         dev;
113         uint32_t                         quirks;        /**< device quirk flags */
114         uint32_t                         caps;          /**< pmu capability flags. */
115         struct bhnd_chipid               cid;           /**< chip identification */
116
117         struct bhnd_pmu_query            query;         /**< query instance */
118
119         struct bhnd_board_info           board;         /**< board identification */
120         device_t                         chipc_dev;     /**< chipcommon device */
121
122         struct bhnd_resource            *res;           /**< pmu register block. */
123         int                              rid;           /**< pmu register RID */
124
125         struct mtx                       mtx;           /**< state mutex */
126
127         /* For compatibility with bhnd_pmu_query APIs and the shared
128          * BHND_PMU_(READ|WRITE) macros. */
129         const struct bhnd_pmu_io        *io;
130         void                            *io_ctx;
131
132 };
133
134 #define BPMU_LOCK_INIT(sc) \
135         mtx_init(&(sc)->mtx, device_get_nameunit((sc)->dev), \
136             "BHND chipc driver lock", MTX_DEF)
137 #define BPMU_LOCK(sc)                           mtx_lock(&(sc)->mtx)
138 #define BPMU_UNLOCK(sc)                 mtx_unlock(&(sc)->mtx)
139 #define BPMU_LOCK_ASSERT(sc, what)              mtx_assert(&(sc)->mtx, what)
140 #define BPMU_LOCK_DESTROY(sc)                   mtx_destroy(&(sc)->mtx)
141
142 #endif /* _BHND_CORES_PMU_BHND_PMUVAR_H_ */