1 /*        $NetBSD: apple_smc.h,v 1.3 2014/04/01 17:48:52 riastradh Exp $        */
2 
3 /*
4  * Apple System Management Controller Interface
5  */
6 
7 /*-
8  * Copyright (c) 2013 The NetBSD Foundation, Inc.
9  * All rights reserved.
10  *
11  * This code is derived from software contributed to The NetBSD Foundation
12  * by Taylor R. Campbell.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef   _DEV_IC_APPLE_SMC_H_
37 #define   _DEV_IC_APPLE_SMC_H_
38 
39 #include <sys/types.h>
40 
41 struct apple_smc_tag;
42 
43 struct apple_smc_attach_args {
44           struct apple_smc_tag          *asa_smc;
45 };
46 
47 struct apple_smc_key;
48 
49 struct apple_smc_desc {
50           uint8_t asd_size;
51 
52           char asd_type[4];
53 #define   APPLE_SMC_TYPE_UINT8          "ui8 "
54 #define   APPLE_SMC_TYPE_UINT16         "ui16"
55 #define   APPLE_SMC_TYPE_UINT32         "ui32"
56 #define   APPLE_SMC_TYPE_SINT8          "si8 "
57 #define   APPLE_SMC_TYPE_SINT16         "si16"
58 #define   APPLE_SMC_TYPE_SINT32         "si32"
59 #define   APPLE_SMC_TYPE_STRING         "ch8*"
60 #define   APPLE_SMC_TYPE_FANDESC        "{fds" /* fan description */
61 #define   APPLE_SMC_TYPE_FPE2 "fpe2" /* fan RPM */
62 #define   APPLE_SMC_TYPE_SP78 "sp78" /* temperature in a weird scale */
63 
64           uint8_t asd_flags;
65 #define   APPLE_SMC_FLAG_UNKNOWN0       0x01
66 #define   APPLE_SMC_FLAG_UNKNOWN1       0x02
67 #define   APPLE_SMC_FLAG_UNKNOWN2       0x04
68 #define   APPLE_SMC_FLAG_UNKNOWN3       0x08
69 #define   APPLE_SMC_FLAG_UNKNOWN4       0x10
70 #define   APPLE_SMC_FLAG_UNKNOWN5       0x20
71 #define   APPLE_SMC_FLAG_WRITE          0x40
72 #define   APPLE_SMC_FLAG_READ 0x80
73 } __packed;
74 
75 uint32_t  apple_smc_nkeys(struct apple_smc_tag *);
76 int                 apple_smc_nth_key(struct apple_smc_tag *,
77                         uint32_t, const char[4 + 1],
78                         struct apple_smc_key **);
79 int                 apple_smc_named_key(struct apple_smc_tag *,
80                         const char[4 + 1], const char[4 + 1],
81                         struct apple_smc_key **);
82 void                apple_smc_release_key(struct apple_smc_tag *,
83                         struct apple_smc_key *);
84 int                 apple_smc_key_search(struct apple_smc_tag *, const char[4 + 1],
85                         uint32_t *);
86 const char *        apple_smc_key_name(const struct apple_smc_key *);
87 uint32_t  apple_smc_key_index(const struct apple_smc_key *);
88 const struct apple_smc_desc *
89                     apple_smc_key_desc(const struct apple_smc_key *);
90 
91 int       apple_smc_read_key(struct apple_smc_tag *,
92               const struct apple_smc_key *, void *, uint8_t);
93 int       apple_smc_read_key_1(struct apple_smc_tag *,
94               const struct apple_smc_key *, uint8_t *);
95 int       apple_smc_read_key_2(struct apple_smc_tag *,
96               const struct apple_smc_key *, uint16_t *);
97 int       apple_smc_read_key_4(struct apple_smc_tag *,
98               const struct apple_smc_key *, uint32_t *);
99 
100 int       apple_smc_write_key(struct apple_smc_tag *,
101               const struct apple_smc_key *, const void *, uint8_t);
102 int       apple_smc_write_key_1(struct apple_smc_tag *,
103               const struct apple_smc_key *, uint8_t);
104 int       apple_smc_write_key_2(struct apple_smc_tag *,
105               const struct apple_smc_key *, uint16_t);
106 int       apple_smc_write_key_4(struct apple_smc_tag *,
107               const struct apple_smc_key *, uint32_t);
108 
109 #endif  /* _DEV_IC_APPLE_SMC_H_ */
110