1 /* $OpenBSD: acpidev.h,v 1.38 2015/08/12 05:59:54 mlarkin Exp $ */ 2 /* 3 * Copyright (c) 2005 Marco Peereboom <marco@openbsd.org> 4 * Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef __DEV_ACPI_ACPIDEV_H__ 20 #define __DEV_ACPI_ACPIDEV_H__ 21 22 #include <sys/sensors.h> 23 #include <sys/rwlock.h> 24 #include <dev/acpi/acpireg.h> 25 26 #define DEVNAME(s) ((s)->sc_dev.dv_xname) 27 28 #define ACPIDEV_NOPOLL 0 29 #define ACPIDEV_POLL 1 30 31 /* 32 * _BIF (Battery InFormation) 33 * Arguments: none 34 * Results : package _BIF (Battery InFormation) 35 * Package { 36 * // ASCIIZ is ASCII character string terminated with a 0x00. 37 * Power Unit //DWORD 38 * Design Capacity //DWORD 39 * Last Full Charge Capacity //DWORD 40 * Battery Technology //DWORD 41 * Design Voltage //DWORD 42 * Design Capacity of Warning //DWORD 43 * Design Capacity of Low //DWORD 44 * Battery Capacity Granularity 1 //DWORD 45 * Battery Capacity Granularity 2 //DWORD 46 * Model Number //ASCIIZ 47 * Serial Number //ASCIIZ 48 * Battery Type //ASCIIZ 49 * OEM Information //ASCIIZ 50 * } 51 */ 52 struct acpibat_bif { 53 u_int32_t bif_power_unit; 54 #define BIF_POWER_MW 0x00 55 #define BIF_POWER_MA 0x01 56 u_int32_t bif_capacity; 57 #define BIF_UNKNOWN 0xffffffff 58 u_int32_t bif_last_capacity; 59 u_int32_t bif_technology; 60 #define BIF_TECH_PRIMARY 0x00 61 #define BIF_TECH_SECONDARY 0x01 62 u_int32_t bif_voltage; 63 u_int32_t bif_warning; 64 u_int32_t bif_low; 65 u_int32_t bif_cap_granu1; 66 u_int32_t bif_cap_granu2; 67 char bif_model[20]; 68 char bif_serial[20]; 69 char bif_type[20]; 70 char bif_oem[20]; 71 }; 72 73 /* 74 * _OSC Definition for Control Method Battery 75 * Arguments: none 76 * Results : DWORD flags 77 */ 78 #define CMB_OSC_UUID "f18fc78b-0f15-4978-b793-53f833a1d35b" 79 #define CMB_OSC_GRANULARITY 0x01 80 #define CMB_OSC_WAKE_ON_LOW 0x02 81 82 /* 83 * _BST (Battery STatus) 84 * Arguments: none 85 * Results : package _BST (Battery STatus) 86 * Package { 87 * Battery State //DWORD 88 * Battery Present Rate //DWORD 89 * Battery Remaining Capacity //DWORD 90 * Battery Present Voltage //DWORD 91 * } 92 * 93 * Per the spec section 10.2.2.3 94 * Remaining Battery Percentage[%] = (Battery Remaining Capacity [=0 ~ 100] / 95 * Last Full Charged Capacity[=100]) * 100 96 * 97 * Remaining Battery Life [h] = Battery Remaining Capacity [mAh/mWh] / 98 * Battery Present Rate [=0xFFFFFFFF] = unknown 99 */ 100 struct acpibat_bst { 101 u_int32_t bst_state; 102 #define BST_DISCHARGE 0x01 103 #define BST_CHARGE 0x02 104 #define BST_CRITICAL 0x04 105 u_int32_t bst_rate; 106 #define BST_UNKNOWN 0xffffffff 107 u_int32_t bst_capacity; 108 u_int32_t bst_voltage; 109 }; 110 111 /* 112 * _BTP (Battery Trip Point) 113 * Arguments: DWORD level 114 * Results : none 115 */ 116 #define BTP_CLEAR_TRIP_POINT 0x00 117 118 /* 119 * _BTM (Battery TiMe) 120 * Arguments: DWORD rate of discharge 121 * Results : DWORD time in seconds or error/unknown 122 */ 123 #define BTM_CURRENT_RATE 0x00 124 125 #define BTM_RATE_TOO_LARGE 0x00 126 #define BTM_CRITICAL 0x00 127 #define BTM_UNKNOWN 0xffffffff 128 129 /* 130 * _BMD (Battery Maintenance Data) 131 * Arguments: none 132 * Results : package _BMD (Battery Maintenance Data) 133 * Package { 134 * Status Flags //DWORD 135 * Capability Flags //DWORD 136 * Recalibrate Count //DWORD 137 * Quick Recalibrate Time //DWORD 138 * Slow Recalibrate Time //DWORD 139 * } 140 */ 141 struct acpibat_bmd { 142 u_int32_t bmd_status; 143 #define BMD_AML_CALIBRATE_CYCLE 0x01 144 #define BMD_CHARGING_DISABLED 0x02 145 #define BMD_DISCHARGE_WHILE_AC 0x04 146 #define BMD_RECALIBRATE_BAT 0x08 147 #define BMD_GOTO_STANDBY_SPEED 0x10 148 u_int32_t bmd_capability; 149 #define BMD_CB_AML_CALIBRATION 0x01 150 #define BMD_CB_DISABLE_CHARGER 0x02 151 #define BMD_CB_DISCH_WHILE_AC 0x04 152 #define BMD_CB_AFFECT_ALL_BATT 0x08 153 #define BMD_CB_FULL_CHRG_FIRST 0x10 154 u_int32_t bmd_recalibrate_count; 155 #define BMD_ONLY_CALIB_IF_ST3 0x00 /* only recal when status bit 3 set */ 156 u_int32_t bmd_quick_recalibrate_time; 157 #define BMD_UNKNOWN 0xffffffff 158 u_int32_t bmd_slow_recalibrate_time; 159 }; 160 161 /* 162 * _BMC (Battery Maintenance Control) 163 * Arguments: DWORD flags 164 * Results : none 165 */ 166 #define BMC_AML_CALIBRATE 0x01 167 #define BMC_DISABLE_CHARGING 0x02 168 #define BMC_ALLOW_AC_DISCHARGE 0x04 169 170 /* AC device */ 171 /* 172 * _PSR (Power Source) 173 * Arguments: none 174 * Results : DWORD status 175 */ 176 #define PSR_OFFLINE 0x00 177 #define PSR_ONLINE 0x01 178 179 /* 180 * _PCL (Power Consumer List) 181 * Arguments: none 182 * Results : LIST of Power Class pointers 183 */ 184 185 /* hpet device */ 186 #define HPET_REG_SIZE 1024 187 188 #define HPET_CAPABILITIES 0x000 189 #define HPET_CONFIGURATION 0x010 190 #define HPET_INTERRUPT_STATUS 0x020 191 #define HPET_MAIN_COUNTER 0x0F0 192 #define HPET_TIMER0_CONFIG 0x100 193 #define HPET_TIMER0_COMPARE 0x108 194 #define HPET_TIMER0_INTERRUPT 0x110 195 #define HPET_TIMER1_CONFIG ((0x20 * 1) + HPET_TIMER0_CONFIG) 196 #define HPET_TIMER1_COMPARE ((0x20 * 1) + HPET_TIMER0_COMPARE) 197 #define HPET_TIMER1_INTERRUPT ((0x20 * 1) + HPET_TIMER0_INTERRUPT) 198 #define HPET_TIMER2_CONFIG ((0x20 * 2) + HPET_TIMER0_CONFIG) 199 #define HPET_TIMER2_COMPARE ((0x20 * 2) + HPET_TIMER0_COMPARE) 200 #define HPET_TIMER2_INTERRUPT ((0x20 * 2) + HPET_TIMER0_INTERRUPT) 201 202 /* Max period is 10^8 fs (100 ns) == 0x5F5E100 as per the HPET SDM */ 203 #define HPET_MAX_PERIOD 0x5F5E100 204 205 #define STA_PRESENT (1L << 0) 206 #define STA_ENABLED (1L << 1) 207 #define STA_SHOW_UI (1L << 2) 208 #define STA_DEV_OK (1L << 3) 209 #define STA_BATTERY (1L << 4) 210 211 /* 212 * _PSS (Performance Supported States) 213 * Arguments: none 214 * Results : package _PSS (Performance Supported States) 215 * Package { 216 * CoreFreq //DWORD 217 * Power //DWORD 218 * TransitionLatency //DWORD 219 * BusMasterLatency //DWORD 220 * Control //DWORD 221 * Status //DWORD 222 * } 223 */ 224 struct acpicpu_pss { 225 u_int32_t pss_core_freq; 226 u_int32_t pss_power; 227 u_int32_t pss_trans_latency; 228 u_int32_t pss_bus_latency; 229 u_int32_t pss_ctrl; 230 u_int32_t pss_status; 231 }; 232 233 int acpicpu_fetch_pss(struct acpicpu_pss **); 234 void acpicpu_set_notify(void (*)(struct acpicpu_pss *, int)); 235 /* 236 * XXX this is returned in a buffer and is not a "natural" type. 237 * 238 * GRD (Generic Register Descriptor ) 239 * 240 */ 241 struct acpi_grd { 242 u_int8_t grd_descriptor; 243 u_int16_t grd_length; 244 struct acpi_gas grd_gas; 245 } __packed; 246 247 /* 248 * _PCT (Performance Control ) 249 * Arguments: none 250 * Results : package _PCT (Performance Control) 251 * Package { 252 * Perf_Ctrl_register //Register 253 * Perf_Status_register //Register 254 * } 255 */ 256 struct acpicpu_pct { 257 struct acpi_grd pct_ctrl; 258 struct acpi_grd pct_status; 259 }; 260 261 /* softc for fake apm devices */ 262 struct acpiac_softc { 263 struct device sc_dev; 264 265 struct acpi_softc *sc_acpi; 266 struct aml_node *sc_devnode; 267 268 int sc_ac_stat; 269 270 struct ksensor sc_sens[1]; 271 struct ksensordev sc_sensdev; 272 }; 273 274 struct acpibat_softc { 275 struct device sc_dev; 276 277 struct acpi_softc *sc_acpi; 278 struct aml_node *sc_devnode; 279 280 struct acpibat_bif sc_bif; 281 struct acpibat_bst sc_bst; 282 volatile int sc_bat_present; 283 284 struct ksensor sc_sens[9]; 285 struct ksensordev sc_sensdev; 286 }; 287 288 TAILQ_HEAD(aml_nodelisth, aml_nodelist); 289 290 struct acpidock_softc { 291 struct device sc_dev; 292 293 struct acpi_softc *sc_acpi; 294 struct aml_node *sc_devnode; 295 296 struct aml_nodelisth sc_deps_h; 297 struct aml_nodelist *sc_deps; 298 299 struct ksensor sc_sens; 300 struct ksensordev sc_sensdev; 301 302 int sc_docked; 303 int sc_sta; 304 305 #define ACPIDOCK_STATUS_UNKNOWN -1 306 #define ACPIDOCK_STATUS_UNDOCKED 0 307 #define ACPIDOCK_STATUS_DOCKED 1 308 }; 309 310 #define ACPIDOCK_EVENT_INSERT 0 311 #define ACPIDOCK_EVENT_DEVCHECK 1 312 #define ACPIDOCK_EVENT_EJECT 3 313 314 #define ACPIEC_MAX_EVENTS 256 315 316 struct acpiec_event { 317 struct aml_node *event; 318 }; 319 320 struct acpiec_softc { 321 struct device sc_dev; 322 323 int sc_ecbusy; 324 325 /* command/status register */ 326 bus_space_tag_t sc_cmd_bt; 327 bus_space_handle_t sc_cmd_bh; 328 329 /* data register */ 330 bus_space_tag_t sc_data_bt; 331 bus_space_handle_t sc_data_bh; 332 333 struct acpi_softc *sc_acpi; 334 struct aml_node *sc_devnode; 335 u_int32_t sc_gpe; 336 struct acpiec_event sc_events[ACPIEC_MAX_EVENTS]; 337 int sc_gotsci; 338 int sc_glk; 339 }; 340 341 void acpibtn_disable_psw(void); 342 void acpibtn_enable_psw(void); 343 int acpibtn_numopenlids(void); 344 #endif /* __DEV_ACPI_ACPIDEV_H__ */ 345