Indentation fix, cleanup.
[AROS.git] / arch / all-pc / hpet / hpet_init.c
blob347b17fee69f656ad24aae34262358b939453d97
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/asmcall.h>
7 #include <aros/debug.h>
8 #include <aros/symbolsets.h>
9 #include <exec/memory.h>
10 #include <utility/hooks.h>
11 #include <proto/exec.h>
12 #include <proto/acpica.h>
14 #include "hpet_intern.h"
16 /* acpica.library is optional */
17 struct Library *ACPICABase = NULL;
19 AROS_UFH3(static BOOL, hpetEnumFunc,
20 AROS_UFHA(struct Hook *, hook, A0),
21 AROS_UFHA(ACPI_TABLE_HPET *, table, A2),
22 AROS_UFHA(struct HPETBase *, base, A1))
24 AROS_USERFUNC_INIT
26 ULONG n;
28 if (table->Address.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
29 return FALSE;
31 n = (table->Id & HPET_NUM_COMPARATORS_MASK) >> HPET_NUM_COMPARATORS_SHIFT;
33 if (base->units)
35 IPTR blk = table->Address.Address + 0x0100;
36 ULONG i;
38 for (i = 0; i < n; i++)
40 base->units[base->unitCnt + i].base = table->Address.Address;
41 base->units[base->unitCnt + i].block = blk;
42 base->units[base->unitCnt + i].Owner = NULL;
44 blk += 0x0020;
48 base->unitCnt += n;
49 return TRUE;
51 AROS_USERFUNC_EXIT
54 static const struct Hook enumHook =
56 .h_Entry = (APTR)hpetEnumFunc
59 static int hpet_Init(struct HPETBase *base)
61 base->unitCnt = 0;
63 ACPICABase = OpenLibrary("acpica.library", 0);
64 if (!ACPICABase)
65 return FALSE;
67 /* During the 1st pass base->units is NULL, so we will just count HPETs */
68 AcpiScanTables("HPET", &enumHook, base);
70 D(bug("[HPET] %u units total\n", base->unitCnt));
71 if (base->unitCnt) {
72 base->units = AllocMem(sizeof(struct HPETUnit) * base->unitCnt, MEMF_CLEAR);
73 if (base->units) {
74 InitSemaphore(&base->lock);
76 /* Fill in the data */
77 base->unitCnt = 0;
78 AcpiScanTables("HPET", &enumHook, base);
79 CloseLibrary(ACPICABase);
80 ACPICABase = NULL;
82 return TRUE;
86 CloseLibrary(ACPICABase);
87 ACPICABase = NULL;
88 return TRUE;
91 ADD2INITLIB(hpet_Init, 0);