scmi.h revision 1.1 1 /* $NetBSD: scmi.h,v 1.1 2025/01/08 22:55:35 jmcneill Exp $ */
2
3 /*
4 * Copyright (c) 2023 Mark Kettenis <kettenis (at) openbsd.org>
5 * Copyright (c) 2024 Tobias Heider <tobhe (at) openbsd.org>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 #pragma once
21
22 #include <sys/param.h>
23 #include <sys/device.h>
24 #include <sys/systm.h>
25 #include <sys/bus.h>
26 #include <sys/kmem.h>
27 #include <sys/mutex.h>
28
29 struct scmi_shmem {
30 uint32_t reserved1;
31 uint32_t channel_status;
32 #define SCMI_CHANNEL_ERROR (1 << 1)
33 #define SCMI_CHANNEL_FREE (1 << 0)
34 uint32_t reserved2;
35 uint32_t reserved3;
36 uint32_t channel_flags;
37 uint32_t length;
38 uint32_t message_header;
39 uint32_t message_payload[];
40 };
41
42 struct scmi_softc;
43
44 struct scmi_perf_level {
45 uint32_t pl_perf;
46 uint32_t pl_cost;
47 uint32_t pl_ifreq;
48 };
49
50 struct scmi_perf_domain {
51 struct scmi_softc *pd_sc;
52 uint32_t pd_domain_id;
53 size_t pd_nlevels;
54 struct scmi_perf_level *pd_levels;
55 int pd_curlevel;
56 char pd_name[16];
57 bool pd_can_level_set;
58 bool pd_level_index_mode;
59 uint32_t pd_rate_limit;
60 uint32_t pd_sustained_perf;
61
62 struct cpu_info *pd_ci; /* first CPU in domain */
63 u_int pd_busy;
64 char *pd_freq_available;
65 u_int pd_freq_target;
66 int pd_node_target;
67 int pd_node_current;
68 int pd_node_available;
69 };
70
71 struct scmi_perf_domain_map {
72 uint32_t pm_domain;
73 struct cpu_info *pm_ci; /* first CPU in domain */
74 };
75
76 struct scmi_softc {
77 device_t sc_dev;
78 bus_space_tag_t sc_iot;
79 volatile struct scmi_shmem *sc_shmem_tx;
80 volatile struct scmi_shmem *sc_shmem_rx;
81 kmutex_t sc_shmem_tx_lock;
82 kmutex_t sc_shmem_rx_lock;
83
84 uint32_t sc_smc_id;
85
86 void *sc_mbox_tx;
87 int (*sc_mbox_tx_send)(void *);
88 void *sc_mbox_rx;
89 int (*sc_mbox_rx_send)(void *);
90
91 size_t sc_perf_ndmap;
92 struct scmi_perf_domain_map *sc_perf_dmap;
93
94 uint16_t sc_ver_major;
95 uint16_t sc_ver_minor;
96
97 #if notyet
98 /* SCMI_CLOCK */
99 struct clock_device sc_cd;
100 #endif
101
102 /* SCMI_PERF */
103 int sc_perf_power_unit;
104 #define SCMI_POWER_UNIT_UW 0x2
105 #define SCMI_POWER_UNIT_MW 0x1
106 #define SCMI_POWER_UNIT_NONE 0x0
107 size_t sc_perf_ndomains;
108 struct scmi_perf_domain *sc_perf_domains;
109
110 int32_t (*sc_command)(struct scmi_softc *);
111 };
112
113 int scmi_init_smc(struct scmi_softc *);
114 int scmi_init_mbox(struct scmi_softc *);
115
116 void scmi_attach_perf(struct scmi_softc *);
117