Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/kernel/core/acpi_dev.h # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / kernel / core / acpi_dev.h` 85 lines ยท 4299 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* acpi_dev.h -- bounded static scan of ACPI definition blocks (DSDT, SSDT) 18 * for Device objects: name path, _HID / _CID and the first memory range of 19 * a constant _CRS resource template. Pure functions over memory (identity 20 * mapped in the kernel, host buffers in the tests and the host tool). 21 * 22 * This is a scanner, not an AML interpreter: nothing is executed. It reads 23 * Device (NAME) { Name (_HID, "STRING" | EisaId) Name (_CID, ...) 24 * Name (_CRS, Buffer) | Method (_CRS) { ... Buffer ... } } 25 * where the _CRS buffer is a constant resource template (the first buffer 26 * inside a _CRS method is taken; the DGX Spark USB controllers and the QEMU 27 * virt UART use exactly these forms, see native/kernel/README.md). _STA is 28 * never evaluated: a device the firmware would report absent is still 29 * listed, and the caller must cope with a controller that does not answer. 30 * Every read is bounds checked against the table length; the table itself 31 * must pass signature, length and checksum checks first. 32 * Spec: ACPI 6.5 sections 5.2.11 (DSDT/SSDT), 6.1.5 (_HID), 6.4 (resource 33 * descriptors), 20.2 (AML grammar: DefDevice, PkgLength, NameString). */ 34 #ifndef AIENOS_CK_ACPI_DEV_H 35 #define AIENOS_CK_ACPI_DEV_H 36 #include 37 #include 38 39 #define CK_AML_PATH_MAX 48u /* "\\" + up to 9 segments "XXXX." + NUL */ 40 #define CK_AML_ID_MAX 16u /* _HID / _CID string, NUL terminated */ 41 42 struct ck_acpi_device { 43 char path[CK_AML_PATH_MAX]; /* name as written at the DeviceOp, usually relative ("USB0", "COM0") */ 44 char hid[CK_AML_ID_MAX]; /* "" when the device has no _HID */ 45 char cid[CK_AML_ID_MAX]; /* "" when no _CID */ 46 uint64_t mmio_base; /* first memory range of _CRS, 0 when none */ 47 uint64_t mmio_len; 48 uint32_t offset; /* DeviceOp offset in the table */ 49 }; 50 51 enum { 52 CK_AML_OK = 0, 53 CK_AML_E_SIG = -1, /* signature is not DSDT or SSDT */ 54 CK_AML_E_LEN = -2, /* header length shorter than 36 or longer than the buffer */ 55 CK_AML_E_SUM = -3, /* checksum does not sum to zero */ 56 }; 57 58 /* Checks a definition block: signature DSDT or SSDT, 36 <= length <= avail, 59 * byte sum zero. CK_AML_OK or a CK_AML_E_*. */ 60 int ck_aml_table_ok(const void *table, size_t avail); 61 62 /* Scans one checked definition block. For every Device object whose _HID or 63 * _CID equals one of ids[0..nids) (nids == 0: every device), fills out[n] 64 * while n < max. Returns the number of matching devices (it may exceed max; 65 * only max are stored), or a CK_AML_E_* for a table that fails 66 * ck_aml_table_ok. *seen (may be NULL) gets the number of Device objects 67 * parsed, matching or not. A malformed device (package past the end, bad 68 * name) is skipped, never followed past the table. */ 69 int ck_aml_scan(const void *table, size_t avail, const char *const *ids, unsigned nids, 70 struct ck_acpi_device *out, unsigned max, unsigned *seen); 71 72 /* Decodes a compressed EISA id (the DWORD form of EisaId("PNP0D15")) into 7 73 * characters + NUL. */ 74 void ck_aml_eisaid(uint32_t v, char out[8]); 75 76 /* Final name segments equal (each padded to 4 with '_'): "USB0" matches "\\_SB_.USB0". 77 * The scan reports each device by the name written at its DeviceOp, which is 78 * usually relative to an enclosing Scope; callers match IORT names this way 79 * and must refuse a name that more than one device carries. */ 80 int ck_aml_last_seg_eq(const char *a, const char *b); 81 82 /* Same name, ignoring a leading "\\" and padding each dot-separated segment 83 * to 4 characters with '_' ("\\_SB.USB0" equals "_SB_.USB0"). */ 84 int ck_aml_path_eq(const char *a, const char *b); 85 #endif