1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Solaris x86 ACPI CA services
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/file.h>
#include <sys/errno.h>
#include <sys/conf.h>
#include <sys/modctl.h>
#include <sys/open.h>
#include <sys/stat.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/esunddi.h>
#include <sys/acpi/acpi.h>
#include <sys/acpica.h>
/*
*
*/
static struct modlmisc modlmisc = {
&mod_miscops,
"ACPI interpreter",
};
static struct modlinkage modlinkage = {
MODREV_1, /* MODREV_1 manual */
(void *)&modlmisc, /* module linkage */
NULL, /* list terminator */
};
/*
* Local data
*/
static kmutex_t acpica_module_lock;
/*
* State of acpica subsystem
* After successful initialization, will be ACPICA_INITIALIZED
*/
int acpica_init_state = ACPICA_NOT_INITIALIZED;
/*
* Following are set by acpica_process_user_options()
*
* acpica_enable = FALSE prevents initialization of ACPI CA
* completely
*
* acpi_init_level determines level of ACPI CA functionality
* enabled in acpica_init()
*/
int acpica_enable;
UINT32 acpi_init_level;
/*
* Non-zero enables lax behavior with respect to some
* common ACPI BIOS issues; see ACPI CA documentation
* Setting this to zero causes ACPI CA to enforce strict
* compliance with ACPI specification
*/
int acpica_enable_interpreter_slack = 1;
/*
* For non-DEBUG builds, set the ACPI CA debug level to 0
* to quiet chatty BIOS output into /var/adm/messages
* Field-patchable for diagnostic use.
*/
#ifdef DEBUG
int acpica_muzzle_debug_output = 0;
#else
int acpica_muzzle_debug_output = 1;
#endif
int
_init(void)
{
int error = EBUSY;
int status;
mutex_init(&acpica_module_lock, NULL, MUTEX_DRIVER, NULL);
if ((error = mod_install(&modlinkage)) != 0) {
mutex_destroy(&acpica_module_lock);
}
AcpiGbl_EnableInterpreterSlack = (acpica_enable_interpreter_slack != 0);
if ((status = AcpiInitializeSubsystem()) != AE_OK) {
cmn_err(CE_WARN, "!acpica: error pre-init:1:%d", status);
}
return (error);
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}
int
_fini(void)
{
/*
* acpica module is never unloaded at run-time; there's always
* a PSM depending on it, at the very least
*/
return (EBUSY);
}
/*
* Install acpica-provided address-space handlers
*/
static int
acpica_install_handlers()
{
ACPI_STATUS rv = AE_OK;
/*
* Install ACPI CA default handlers
*/
if (AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
ACPI_ADR_SPACE_SYSTEM_MEMORY,
ACPI_DEFAULT_HANDLER, NULL, NULL) != AE_OK) {
cmn_err(CE_WARN, "!acpica: no default handler for"
" system memory");
rv = AE_ERROR;
}
if (AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
ACPI_ADR_SPACE_SYSTEM_IO,
ACPI_DEFAULT_HANDLER, NULL, NULL) != AE_OK) {
cmn_err(CE_WARN, "!acpica: no default handler for"
" system I/O");
rv = AE_ERROR;
}
if (AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
ACPI_ADR_SPACE_PCI_CONFIG,
ACPI_DEFAULT_HANDLER, NULL, NULL) != AE_OK) {
cmn_err(CE_WARN, "!acpica: no default handler for"
" PCI Config");
rv = AE_ERROR;
}
return (rv);
}
/*
* Find the BIOS date, and return TRUE if supplied
* date is same or later than the BIOS date, or FALSE
* if the BIOS date can't be fetched for any reason
*/
static int
acpica_check_bios_date(int yy, int mm, int dd)
{
char *datep;
int bios_year, bios_month, bios_day;
/* If firmware has no bios, skip the check */
if (ddi_prop_exists(DDI_DEV_T_ANY, ddi_root_node(), 0, "bios-free"))
return (TRUE);
/*
* PC BIOSes contain a string in the form of
* "mm/dd/yy" at absolute address 0xffff5,
* where mm, dd and yy are all ASCII digits.
* We map the string, pluck out the values,
* and accept all BIOSes from 1 Jan 1999 on
* as valid.
*/
if ((int)AcpiOsMapMemory(0xffff5, 8, (void **) &datep) != AE_OK)
return (FALSE);
/* year */
bios_year = ((int)(*(datep + 6) - '0') * 10) + (*(datep + 7) - '0');
/* month */
bios_month = ((int)(*datep - '0') * 10) + (*(datep + 1) - '0');
/* day */
bios_day = ((int)(*(datep + 3) - '0') * 10) + (*(datep + 4) - '0');
AcpiOsUnmapMemory((void *) datep, 8);
if (bios_year < 0 || bios_year > 99 || bios_month < 0 ||
bios_month > 99 || bios_day < 0 || bios_day > 99) {
/* non-digit chars in BIOS date */
return (FALSE);
}
/*
* Adjust for 2-digit year; note to grand-children:
* need a new scheme before 2080 rolls around
*/
bios_year += (bios_year >= 80 && bios_year <= 99) ?
1900 : 2000;
if (bios_year < yy)
return (FALSE);
else if (bios_year > yy)
return (TRUE);
if (bios_month < mm)
return (FALSE);
else if (bios_month > mm)
return (TRUE);
if (bios_day < dd)
return (FALSE);
return (TRUE);
}
/*
* Check for Metropolis systems with BIOSes older than 10/12/04
* return TRUE if BIOS requires legacy mode, FALSE otherwise
*/
static int
acpica_metro_old_bios()
{
ACPI_TABLE_HEADER *fadt;
/* get the FADT */
if (AcpiGetFirmwareTable(FADT_SIG, 1, ACPI_LOGICAL_ADDRESSING,
(ACPI_TABLE_HEADER **)&fadt) != AE_OK)
return (FALSE);
/* compare OEM Table ID to "SUNmetro" - no match, return false */
if (strncmp("SUNmetro", fadt->OemTableId, 8))
return (FALSE);
/* On a Metro - return FALSE if later than 10/12/04 */
return (!acpica_check_bios_date(2004, 10, 12));
}
/*
* Process acpi-user-options property if present
*/
static void
acpica_process_user_options()
{
static int processed = 0;
int acpi_user_options;
char *acpi_prop;
/*
* return if acpi-user-options has already been processed
*/
if (processed)
return;
else
processed = 1;
/* converts acpi-user-options from type string to int, if any */
if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(),
DDI_PROP_DONTPASS, "acpi-user-options", &acpi_prop) ==
DDI_PROP_SUCCESS) {
long data;
int ret;
ret = ddi_strtol(acpi_prop, NULL, 0, &data);
if (ret == 0) {
e_ddi_prop_remove(DDI_DEV_T_NONE, ddi_root_node(),
"acpi-user-options");
e_ddi_prop_update_int(DDI_DEV_T_NONE, ddi_root_node(),
"acpi-user-options", data);
}
ddi_prop_free(acpi_prop);
}
/*
* fetch the optional options property
*/
acpi_user_options = ddi_prop_get_int(DDI_DEV_T_ANY, ddi_root_node(), 0,
"acpi-user-options", 0);
/*
* Note that 'off' has precedence over 'on'
* Also note - all cases of ACPI_OUSER_MASK
* provided here, no default: case is present
*/
switch (acpi_user_options & ACPI_OUSER_MASK) {
case ACPI_OUSER_DFLT:
acpica_enable = acpica_check_bios_date(1999, 1, 1);
break;
case ACPI_OUSER_ON:
acpica_enable = TRUE;
break;
case ACPI_OUSER_OFF:
case ACPI_OUSER_OFF | ACPI_OUSER_ON:
acpica_enable = FALSE;
break;
}
acpi_init_level = ACPI_FULL_INITIALIZATION;
/*
* special test here; may be generalized in the
* future - test for a machines that are known to
* work only in legacy mode, and set OUSER_LEGACY if
* we're on one
*/
if (acpica_metro_old_bios())
acpi_user_options |= ACPI_OUSER_LEGACY;
/*
* If legacy mode is specified, set initialization
* options to avoid entering ACPI mode and hooking SCI
* - basically try to act like legacy acpi_intp
*/
if ((acpi_user_options & ACPI_OUSER_LEGACY) != 0)
acpi_init_level |= (ACPI_NO_ACPI_ENABLE | ACPI_NO_HANDLER_INIT);
/*
* modify default ACPI CA debug output level for non-DEBUG builds
* (to avoid BIOS debug chatter in /var/adm/messages)
*/
if (acpica_muzzle_debug_output)
AcpiDbgLevel = 0;
}
/*
* Initialize the CA subsystem if it hasn't been done already
*/
int
acpica_init()
{
ACPI_STATUS status;
/*
* Make sure user options are processed,
* then fail to initialize if ACPI CA has been
* disabled
*/
acpica_process_user_options();
if (!acpica_enable)
return (AE_ERROR);
mutex_enter(&acpica_module_lock);
if (acpica_init_state == ACPICA_NOT_INITIALIZED) {
if ((status = AcpiLoadTables()) != AE_OK) {
goto error;
}
if ((status = acpica_install_handlers()) != AE_OK) {
goto error;
}
if ((status = AcpiEnableSubsystem(acpi_init_level)) != AE_OK) {
goto error;
}
if ((status = AcpiInitializeObjects(0)) != AE_OK) {
goto error;
}
/*
* Initialize EC
*/
acpica_ec_init();
acpica_init_state = ACPICA_INITIALIZED;
error:
if (acpica_init_state != ACPICA_INITIALIZED) {
cmn_err(CE_NOTE, "!failed to initialize"
" ACPI services");
}
} else
status = AE_OK;
/*
* Set acpi-status to 13 if acpica has been initialized successfully.
* This indicates that acpica is up and running. This variable name
* and value were chosen in order to remain compatible with acpi_intp.
*/
e_ddi_prop_update_int(DDI_DEV_T_NONE, ddi_root_node(), "acpi-status",
(status == AE_OK) ? (ACPI_BOOT_INIT | ACPI_BOOT_ENABLE |
ACPI_BOOT_BOOTCONF) : 0);
mutex_exit(&acpica_module_lock);
return (status);
}
/*
* SCI handling
*/
ACPI_STATUS
acpica_get_sci(int *sci_irq, iflag_t *sci_flags)
{
APIC_HEADER *ap;
MULTIPLE_APIC_TABLE *mat;
MADT_INTERRUPT_OVERRIDE *mio;
FADT_DESCRIPTOR *fadt;
int madt_seen, madt_size;
/*
* Make sure user options are processed,
* then return error if ACPI CA has been
* disabled or system is not running in ACPI
* and won't need/understand SCI
*/
acpica_process_user_options();
if ((!acpica_enable) || (acpi_init_level & ACPI_NO_ACPI_ENABLE))
return (AE_ERROR);
/*
* according to Intel ACPI developers, SCI
* conforms to PCI bus conventions; level/low
* unless otherwise directed by overrides.
*/
sci_flags->intr_el = INTR_EL_LEVEL;
sci_flags->intr_po = INTR_PO_ACTIVE_LOW;
sci_flags->bustype = BUS_PCI; /* we *do* conform to PCI */
/* get the SCI from the FADT */
if (AcpiGetFirmwareTable(FADT_SIG, 1, ACPI_LOGICAL_ADDRESSING,
(ACPI_TABLE_HEADER **)&fadt) != AE_OK)
return (AE_ERROR);
*sci_irq = fadt->SciInt;
/* search for ISOs that modify it */
/* if we don't find a MADT, that's OK; no ISOs then */
if (AcpiGetFirmwareTable(APIC_SIG, 1, ACPI_LOGICAL_ADDRESSING,
(ACPI_TABLE_HEADER **) &mat) != AE_OK) {
return (AE_OK);
}
ap = (APIC_HEADER *) (mat + 1);
madt_size = mat->Length;
madt_seen = sizeof (*mat);
while (madt_seen < madt_size) {
switch (ap->Type) {
case APIC_XRUPT_OVERRIDE:
mio = (MADT_INTERRUPT_OVERRIDE *) ap;
if (mio->Source == *sci_irq) {
*sci_irq = mio->Interrupt;
sci_flags->intr_el = mio->TriggerMode;
sci_flags->intr_po = mio->Polarity;
}
break;
}
/* advance to next entry */
madt_seen += ap->Length;
ap = (APIC_HEADER *)(((char *)ap) + ap->Length);
}
/*
* One more check; if ISO said "conform", revert to default
*/
if (sci_flags->intr_el == INTR_EL_CONFORM)
sci_flags->intr_el = INTR_EL_LEVEL;
if (sci_flags->intr_po == INTR_PO_CONFORM)
sci_flags->intr_po = INTR_PO_ACTIVE_LOW;
return (AE_OK);
}
|