24792b951c896edcc04daac06ab7f6cbe9508726
[AROS.git] / arch / all-pc / acpi / scanentries.c
blob24792b951c896edcc04daac06ab7f6cbe9508726
1 #include <resources/acpi.h>
2 #include <utility/hooks.h>
4 struct HeaderData
6 unsigned int id;
7 unsigned int len;
8 };
10 static const struct HeaderData headers[] =
12 {ACPI_MAKE_ID('A','P','I','C'), sizeof(struct ACPI_TABLE_TYPE_MADT)},
13 {0, 0}
16 /*****************************************************************************
18 NAME */
19 #include <proto/acpi.h>
21 AROS_LH4(ULONG, ACPI_ScanEntries,
23 /* SYNOPSIS */
24 AROS_LHA(struct ACPI_TABLE_DEF_HEADER *, table, A0),
25 AROS_LHA(WORD, type, D0),
26 AROS_LHA(const struct Hook *, hook, A1),
27 AROS_LHA(APTR, userdata, A2),
29 /* LOCATION */
30 struct ACPIBase *, ACPIBase, 2, Acpi)
32 /* FUNCTION
33 Scan entries with the given type in the given table.
34 The supplied hook will be called for each entry
36 INPUTS
37 table - a pointer to a table to scan
38 type - type of entries needed, or ACPI_ENTRY_TYPE_ALL to
39 enumerate all entries
40 hook - a hook to call. The hook will be called with 'object'
41 argument set to entry pointer, and 'paramPacket' set to
42 'userdata' argument. You can pass a NULL here in order just
43 to count the number of entries.
44 userdata - a user-supplied data to pass to the hook.
46 RESULT
47 Total number of processed entries. The entry is considered processed if
48 either supplied hook returns nonzero value, or there's no hook supplied.
50 NOTES
52 EXAMPLE
54 BUGS
56 SEE ALSO
58 INTERNALS
60 ******************************************************************************/
62 AROS_LIBFUNC_INIT
64 struct ACPI_TABLE_DEF_ENTRY_HEADER *entry = NULL;
65 ULONG count = 0;
66 const struct HeaderData *hdr;
67 unsigned long end;
69 for (hdr = headers; hdr->id; hdr++)
71 if (hdr->id == table->signature)
73 /* First entry follows table header */
74 entry = (APTR)table + hdr->len;
75 break;
79 if (!entry)
81 /* The given table doesn't have array of entries inside */
82 return 0;
85 /* Get end of the table */
86 end = (unsigned long)table + table->length;
88 /* Parse all entries looking for a match. */
89 while (((unsigned long)entry) < end)
91 if ((type == ACPI_ENTRY_TYPE_ALL) || (type == entry->type))
93 if (hook)
95 BOOL res = CALLHOOKPKT((struct Hook *)hook, entry, userdata);
97 if (res)
98 count++;
100 else
101 count++;
103 entry = (struct ACPI_TABLE_DEF_ENTRY_HEADER *)((unsigned long)entry + entry->length);
106 return count;
108 AROS_LIBFUNC_EXIT