| 1 |
|
| 2 |
|
| 3 |
#include <acpi/acpi.h> |
| 4 |
#include <acpi/acpi_iort.h> |
| 5 |
#include <assert.h> |
| 6 |
|
| 7 |
unsigned long acpi_iort_its_entry(unsigned long current, acpi_iort_t *iort, |
| 8 |
acpi_iort_node_t **its_out, u32 its_count, u32 *identifiers) |
| 9 |
{ |
| 10 |
acpi_iort_its_group_t *its_node_data; |
| 11 |
acpi_iort_node_t *its = (acpi_iort_node_t *)current; |
| 12 |
const unsigned long its_start = current; |
| 13 |
|
| 14 |
ASSERT(its_out); |
| 15 |
current += sizeof(*its) + sizeof(*its_node_data); |
| 16 |
memset(its, 0, current - its_start); |
| 17 |
|
| 18 |
its->type = ACPI_IORT_NODE_ITS_GROUP; |
| 19 |
its->revision = 1; |
| 20 |
its->identifier = iort->node_count++; |
| 21 |
|
| 22 |
its_node_data = (acpi_iort_its_group_t *)its->node_data; |
| 23 |
its_node_data->its_count = its_count; |
| 24 |
|
| 25 |
for (int i = 0; i < its_count; i++) |
| 26 |
its_node_data->identifiers[i] = identifiers[i]; |
| 27 |
|
| 28 |
current += its_node_data->its_count * sizeof(its_node_data->identifiers[0]); |
| 29 |
its->length = current - its_start; |
| 30 |
|
| 31 |
*its_out = its; |
| 32 |
|
| 33 |
return current; |
| 34 |
} |
| 35 |
|
| 36 |
unsigned long acpi_iort_smmuv3_entry(unsigned long current, acpi_iort_t *iort, |
| 37 |
acpi_iort_node_t **smmu_v3_out, u64 base, u32 flags) |
| 38 |
{ |
| 39 |
acpi_iort_smmu_v3_t *smmu_v3_node_data; |
| 40 |
acpi_iort_node_t *smmu_v3 = (acpi_iort_node_t *)current; |
| 41 |
const unsigned long smmu_v3_start = current; |
| 42 |
|
| 43 |
ASSERT(smmu_v3_out); |
| 44 |
current += sizeof(*smmu_v3) + sizeof(*smmu_v3_node_data); |
| 45 |
memset(smmu_v3, 0, current - smmu_v3_start); |
| 46 |
|
| 47 |
smmu_v3->type = ACPI_IORT_NODE_SMMU_V3; |
| 48 |
smmu_v3->revision = 0x5; |
| 49 |
smmu_v3->identifier = iort->node_count++; |
| 50 |
smmu_v3->mapping_offset = current - smmu_v3_start; |
| 51 |
|
| 52 |
|
| 53 |
smmu_v3->length = smmu_v3->mapping_offset; |
| 54 |
|
| 55 |
smmu_v3_node_data = (acpi_iort_smmu_v3_t *)smmu_v3->node_data; |
| 56 |
smmu_v3_node_data->base_address = base; |
| 57 |
smmu_v3_node_data->flags = flags; |
| 58 |
|
| 59 |
*smmu_v3_out = smmu_v3; |
| 60 |
|
| 61 |
return current; |
| 62 |
} |
| 63 |
|
| 64 |
unsigned long acpi_iort_nc_entry(unsigned long current, acpi_iort_t *iort, |
| 65 |
acpi_iort_node_t **nc_out, u32 node_flags, u64 memory_properties, |
| 66 |
u32 memory_address_limit, char *device_name) |
| 67 |
{ |
| 68 |
acpi_iort_named_component_t *nc_node_data; |
| 69 |
acpi_iort_node_t *nc = (acpi_iort_node_t *)current; |
| 70 |
const unsigned long nc_start = current; |
| 71 |
const u16 device_name_len = strlen(device_name); |
| 72 |
|
| 73 |
ASSERT(nc_out); |
| 74 |
current += sizeof(*nc) + sizeof(*nc_node_data); |
| 75 |
memset(nc, 0, current - nc_start); |
| 76 |
|
| 77 |
nc->type = ACPI_IORT_NODE_NAMED_COMPONENT; |
| 78 |
nc->revision = 0x4; |
| 79 |
nc->identifier = iort->node_count++; |
| 80 |
|
| 81 |
nc_node_data = (acpi_iort_named_component_t *)nc->node_data; |
| 82 |
nc_node_data->node_flags = node_flags; |
| 83 |
nc_node_data->memory_properties = memory_properties; |
| 84 |
nc_node_data->memory_address_limit = memory_address_limit; |
| 85 |
|
| 86 |
|
| 87 |
memset(nc_node_data->device_name, 0, device_name_len + 5); |
| 88 |
strncpy(nc_node_data->device_name, device_name, device_name_len + 1); |
| 89 |
|
| 90 |
current += device_name_len + 2; |
| 91 |
current = ALIGN_UP(current, 4); |
| 92 |
|
| 93 |
nc->mapping_offset = current - nc_start; |
| 94 |
|
| 95 |
|
| 96 |
nc->length = nc->mapping_offset; |
| 97 |
|
| 98 |
*nc_out = nc; |
| 99 |
|
| 100 |
return current; |
| 101 |
} |
| 102 |
|
| 103 |
unsigned long acpi_iort_rc_entry(unsigned long current, acpi_iort_t *node, |
| 104 |
acpi_iort_node_t **rc_out, u64 memory_properties, |
| 105 |
u32 ats_attribute, u32 pci_segment_number, |
| 106 |
u8 memory_address_limit, u16 pasid_capabilities) |
| 107 |
{ |
| 108 |
acpi_iort_root_complex_t *rc_node_data; |
| 109 |
acpi_iort_node_t *rc = (acpi_iort_node_t *)current; |
| 110 |
const unsigned long rc_start = current; |
| 111 |
|
| 112 |
ASSERT(rc_out); |
| 113 |
current += sizeof(*rc) + sizeof(*rc_node_data); |
| 114 |
memset(rc, 0, current - rc_start); |
| 115 |
|
| 116 |
rc->type = ACPI_IORT_NODE_PCI_ROOT_COMPLEX; |
| 117 |
rc->revision = 0x4; |
| 118 |
rc->identifier = node->node_count++; |
| 119 |
rc->mapping_offset = current - rc_start; |
| 120 |
|
| 121 |
|
| 122 |
rc->length = rc->mapping_offset; |
| 123 |
|
| 124 |
rc_node_data = (acpi_iort_root_complex_t *)rc->node_data; |
| 125 |
rc_node_data->memory_properties = memory_properties; |
| 126 |
rc_node_data->ats_attribute = ats_attribute; |
| 127 |
rc_node_data->pci_segment_number = pci_segment_number; |
| 128 |
rc_node_data->memory_address_limit = memory_address_limit; |
| 129 |
rc_node_data->pasid_capabilities = pasid_capabilities; |
| 130 |
|
| 131 |
*rc_out = rc; |
| 132 |
|
| 133 |
return current; |
| 134 |
} |
| 135 |
|
| 136 |
unsigned long acpi_iort_id_map_entry(unsigned long current, acpi_iort_node_t *node, u32 input_base, |
| 137 |
u32 id_count, u32 output_base, u32 output_reference, u32 flags) |
| 138 |
{ |
| 139 |
acpi_iort_id_mapping_t *id_map = (acpi_iort_id_mapping_t *)current; |
| 140 |
|
| 141 |
ASSERT(node); |
| 142 |
memset(id_map, 0, sizeof(acpi_iort_id_mapping_t)); |
| 143 |
|
| 144 |
current += sizeof(acpi_iort_id_mapping_t); |
| 145 |
|
| 146 |
node->mapping_count++; |
| 147 |
node->length += current - (unsigned long)id_map; |
| 148 |
|
| 149 |
id_map->input_base = input_base; |
| 150 |
id_map->id_count = id_count - 1; |
| 151 |
id_map->output_base = output_base; |
| 152 |
id_map->output_reference = output_reference; |
| 153 |
id_map->flags = flags; |
| 154 |
|
| 155 |
return current; |
| 156 |
} |