1 | /*␊ |
2 | * Copyright (c) 2005 Apple Computer, Inc. All Rights Reserved.␊ |
3 | */␊ |
4 | ␊ |
5 | #ifndef __DEVICE_TREE_H␊ |
6 | #define __DEVICE_TREE_H␊ |
7 | ␊ |
8 | #include <stdbool.h>␊ |
9 | #include <stdint.h>␊ |
10 | ␊ |
11 | typedef struct _Property {␊ |
12 | char * name;␊ |
13 | uint32_t length;␊ |
14 | void * value;␊ |
15 | ␊ |
16 | struct _Property * next;␊ |
17 | } Property;␊ |
18 | ␊ |
19 | typedef struct _Node {␊ |
20 | struct _Property * properties;␊ |
21 | struct _Property * last_prop;␊ |
22 | ␊ |
23 | struct _Node * children;␊ |
24 | ␊ |
25 | struct _Node * next;␊ |
26 | } Node;␊ |
27 | ␊ |
28 | #define MAX_PCI_DEV_PATHS 4␊ |
29 | #define MAX_STRING_NUM_ENTRIES 100␊ |
30 | ␊ |
31 | #define DEV_PATH_HEADER␉␉\␊ |
32 | uint8_t␉␉type;␉␉\␊ |
33 | uint8_t␉␉subtype;␉\␊ |
34 | uint16_t␉length;␊ |
35 | ␊ |
36 | struct ACPIDevPath {␊ |
37 | ␉//uint8_t␉␉type;␉␉// = 2 ACPI device-path␊ |
38 | ␉//uint8_t␉␉subtype;␉// = 1 ACPI Device-path␊ |
39 | ␉//uint16_t␉ length;␉␉// = 0x0c␊ |
40 | ␉DEV_PATH_HEADER␊ |
41 | ␉uint32_t␉_HID;␉␉// = 0xD041030A ?␊ |
42 | ␉uint32_t␉_UID;␉␉// = 0x00000000 PCI ROOT␊ |
43 | };␊ |
44 | ␊ |
45 | struct PCIDevPath {␊ |
46 | ␉//uint8_t␉␉type;␉␉// = 1 Hardware device-path␊ |
47 | ␉//uint8_t␉␉subtype;␉// = 1 PCI␊ |
48 | ␉//uint16_t␉ length;␉␉// = 6␊ |
49 | ␉DEV_PATH_HEADER␊ |
50 | ␉uint8_t␉␉function;␉// pci func number␊ |
51 | ␉uint8_t␉␉device;␉␉// pci dev number␊ |
52 | };␊ |
53 | ␊ |
54 | struct DevicePathEnd {␊ |
55 | ␉//uint8_t␉␉type;␉␉// = 0x7f␊ |
56 | ␉//uint8_t␉␉subtype;␉// = 0xff␊ |
57 | ␉//uint16_t␉␉length;␉␉// = 4;␊ |
58 | ␉DEV_PATH_HEADER␊ |
59 | };␊ |
60 | ␊ |
61 | struct DevPropDevice {␊ |
62 | ␉uint32_t length;␊ |
63 | ␉uint16_t numentries;␊ |
64 | ␉uint16_t WHAT2;␉␉␉␉␉␉␉␉␉␉// 0x0000 ?␊ |
65 | ␉struct ACPIDevPath acpi_dev_path;␉␉␉␉␉// = 0x02010c00 0xd041030a␊ |
66 | ␉struct PCIDevPath pci_dev_path[MAX_PCI_DEV_PATHS]; // = 0x01010600 func dev␊ |
67 | ␉struct DevicePathEnd path_end;␉␉␉␉␉␉// = 0x7fff0400␊ |
68 | ␉uint8_t *data;␊ |
69 | ␉␊ |
70 | ␉// ------------------------␊ |
71 | ␉uint8_t␉ num_pci_devpaths;␊ |
72 | ␉struct DevPropString *string;␊ |
73 | ␉// ------------------------␊ |
74 | };␊ |
75 | ␊ |
76 | struct DevPropString {␊ |
77 | ␉uint32_t length;␊ |
78 | ␉uint32_t WHAT2;␉␉␉// 0x01000000 ?␊ |
79 | ␉uint16_t numentries;␊ |
80 | ␉uint16_t WHAT3;␉␉␉// 0x0000 ?␊ |
81 | ␉struct DevPropDevice *entries;␊ |
82 | };␊ |
83 | ␊ |
84 | ␊ |
85 | extern Property *␊ |
86 | DT__AddProperty(Node *node, const char *name, uint32_t length, void *value);␊ |
87 | ␊ |
88 | extern Node *␊ |
89 | DT__AddChild(Node *parent, const char *name);␊ |
90 | ␊ |
91 | Node *␊ |
92 | DT__FindNode(const char *path, bool createIfMissing);␊ |
93 | ␊ |
94 | extern void␊ |
95 | DT__FreeProperty(Property *prop);␊ |
96 | ␊ |
97 | extern void␊ |
98 | DT__FreeNode(Node *node);␊ |
99 | ␊ |
100 | extern char *␊ |
101 | DT__GetName(Node *node);␊ |
102 | ␊ |
103 | void␊ |
104 | DT__Initialize(void);␊ |
105 | ␊ |
106 | /*␊ |
107 | * Free up memory used by in-memory representation␊ |
108 | * of device tree.␊ |
109 | */␊ |
110 | extern void␊ |
111 | DT__Finalize(void);␊ |
112 | ␊ |
113 | void␊ |
114 | DT__FlattenDeviceTree(void **result, uint32_t *length);␊ |
115 | ␊ |
116 | #endif /* __DEVICE_TREE_H */␊ |
117 | |