private static void LoadDeviceInfo(AcpiNamespace acpiNamespace, AcpiObject.IOperationRegionAccessor operationRegionAccessor) { AmlInterpreter interpreter = new AmlInterpreter(acpiNamespace, operationRegionAccessor); foreach (AcpiNamespace.Node crsNode in acpiNamespace.GetAllNodes()) { if (crsNode.Name != "_CRS") { continue; } Console.Write("Loading resource descriptors for ACPI device "); Console.WriteLine(crsNode.Path.RemoveSegment().ToString()); AcpiNamespace.Node hidNode = acpiNamespace.LookupNode(crsNode.Path.RemoveSegmentAbsolute().AddSegmentAbsolute("_HID")); if (hidNode == null) { throw new Exception("Found device with _CRS property but no matching _HID property"); } AcpiObject.AcpiObject hidObject = hidNode.Value; if (hidObject is AcpiObject.BytecodeMethod) { AmlInterpreterThread thread = interpreter.InvokeMethodOnNewThread(null, hidNode.Path, new AcpiObject.AcpiObject[] { }); interpreter.Run(); hidObject = thread.ExitValue; } string deviceId = HidObjectToDeviceId(hidObject); AcpiObject.AcpiObject crsObject = crsNode.Value; if (crsObject is AcpiObject.BytecodeMethod) { AmlInterpreterThread thread = interpreter.InvokeMethodOnNewThread(null, crsNode.Path, new AcpiObject.AcpiObject[] { }); interpreter.Run(); crsObject = thread.ExitValue; } if (crsObject is AcpiObject.Buffer) { byte[] crsBuffer = crsObject.GetAsBuffer().Contents; ResourceDescriptor[] resourceDescriptors = ResourceDescriptorParser.Parse(crsBuffer); Console.WriteLine("Loaded resource descriptor for device " + deviceId); } else { Console.WriteLine("No resource descriptor for device " + deviceId); } } }
private static string HidObjectToDeviceId(AcpiObject.AcpiObject obj) { AcpiObject.AcpiObjectType type = (AcpiObject.AcpiObjectType)((AcpiObject.Integer)(obj.ObjectType())).Value; string hid; if (obj is AcpiObject.Integer) { // Swap byte order so that all fields are contiguous ulong eisaId = ByteOrderSwap((uint)(((AcpiObject.Integer)obj).Value)); hid = String.Format("{0}{1}{2}{3:X}{4:X}{5:X}{6:X}", (char)(((eisaId >> 26) & 0x1F) + '@'), (char)(((eisaId >> 21) & 0x1F) + '@'), (char)(((eisaId >> 16) & 0x1F) + '@'), (eisaId >> 12) & 0xF, (eisaId >> 8) & 0xF, (eisaId >> 4) & 0xF, (eisaId >> 0) & 0xF); } else if (obj is AcpiObject.String) { hid = ((AcpiObject.String)obj).Value; } else { throw new ArgumentException("_HID object was not an integer or string as expected"); } if (hid.StartsWith("PNP")) { return("/pnp/" + hid); } else { return("/acpi/" + hid); } }
private static void PrintResult(AcpiObject.AcpiObject result) { Console.WriteLine(result.ToString()); }