Lines Matching +full:gpa +full:- +full:0

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
73 return ((uint8_t *)pp)[0]; in basl_le_dec()
82 return 0; in basl_le_dec()
99 const ACPI_TABLE_HEADER *const header = table->data; in basl_dump_table()
103 data = table->data; in basl_dump_table()
105 data = vm_map_gpa(table->ctx, BHYVE_ACPI_BASE + table->off, in basl_dump_table()
106 table->len); in basl_dump_table()
112 printf("%.4s @ %8x (%s)\n", header->Signature, in basl_dump_table()
113 BHYVE_ACPI_BASE + table->off, mem ? "Memory" : "FwCfg"); in basl_dump_table()
114 hexdump(data, table->len, NULL, 0); in basl_dump_table()
116 return (0); in basl_dump_table()
128 return (0); in basl_dump()
138 gas->SpaceId = space_id; in basl_fill_gas()
139 gas->BitWidth = bit_width; in basl_fill_gas()
140 gas->BitOffset = bit_offset; in basl_fill_gas()
141 gas->AccessWidth = access_width; in basl_fill_gas()
142 gas->Address = htole64(address); in basl_fill_gas()
150 table->off = roundup2(*off, table->alignment); in basl_finish_install_guest_tables()
151 *off = table->off + table->len; in basl_finish_install_guest_tables()
152 if (*off <= table->off) { in basl_finish_install_guest_tables()
153 warnx("%s: invalid table length 0x%8x @ offset 0x%8x", __func__, in basl_finish_install_guest_tables()
154 table->len, table->off); in basl_finish_install_guest_tables()
160 qemu_fwcfg_add_file(table->fwcfg_name, table->len, table->data)); in basl_finish_install_guest_tables()
161 BASL_EXEC(qemu_loader_alloc(basl_loader, table->fwcfg_name, in basl_finish_install_guest_tables()
162 table->alignment, QEMU_LOADER_ALLOC_HIGH)); in basl_finish_install_guest_tables()
165 return (0); in basl_finish_install_guest_tables()
174 gva = vm_map_gpa(table->ctx, BHYVE_ACPI_BASE + table->off, table->len); in basl_finish_install_guest_tables()
176 warnx("%s: could not map gpa [ 0x%16lx, 0x%16lx ]", __func__, in basl_finish_install_guest_tables()
177 (uint64_t)BHYVE_ACPI_BASE + table->off, in basl_finish_install_guest_tables()
178 (uint64_t)BHYVE_ACPI_BASE + table->off + table->len); in basl_finish_install_guest_tables()
181 memcpy(gva, table->data, table->len); in basl_finish_install_guest_tables()
183 return (0); in basl_finish_install_guest_tables()
191 STAILQ_FOREACH(checksum, &table->checksums, chain) { in basl_finish_patch_checksums()
193 uint64_t gpa; in basl_finish_patch_checksums() local
197 len = checksum->len; in basl_finish_patch_checksums()
199 len = table->len; in basl_finish_patch_checksums()
202 assert(checksum->off < table->len); in basl_finish_patch_checksums()
203 assert(checksum->start < table->len); in basl_finish_patch_checksums()
204 assert(checksum->start + len <= table->len); in basl_finish_patch_checksums()
208 table->fwcfg_name, checksum->off, checksum->start, len)); in basl_finish_patch_checksums()
220 gpa = BHYVE_ACPI_BASE + table->off + checksum->start; in basl_finish_patch_checksums()
221 if ((gpa < BHYVE_ACPI_BASE) || in basl_finish_patch_checksums()
222 (gpa < BHYVE_ACPI_BASE + table->off)) { in basl_finish_patch_checksums()
223 warnx("%s: invalid gpa (off 0x%8x start 0x%8x)", in basl_finish_patch_checksums()
224 __func__, table->off, checksum->start); in basl_finish_patch_checksums()
228 gva = vm_map_gpa(table->ctx, gpa, len); in basl_finish_patch_checksums()
230 warnx("%s: could not map gpa [ 0x%16lx, 0x%16lx ]", in basl_finish_patch_checksums()
231 __func__, gpa, gpa + len); in basl_finish_patch_checksums()
235 checksum_gva = gva + checksum->off; in basl_finish_patch_checksums()
237 warnx("%s: invalid checksum offset 0x%8x", __func__, in basl_finish_patch_checksums()
238 checksum->off); in basl_finish_patch_checksums()
242 sum = 0; in basl_finish_patch_checksums()
243 for (uint32_t i = 0; i < len; ++i) { in basl_finish_patch_checksums()
246 *checksum_gva = -sum; in basl_finish_patch_checksums()
249 return (0); in basl_finish_patch_checksums()
259 (const ACPI_TABLE_HEADER *)table->data; in basl_get_table_by_signature()
261 if (strncmp(header->Signature, signature, in basl_get_table_by_signature()
262 sizeof(header->Signature)) == 0) { in basl_get_table_by_signature()
276 STAILQ_FOREACH(pointer, &table->pointers, chain) { in basl_finish_patch_pointers()
279 uint64_t gpa, val; in basl_finish_patch_pointers() local
281 assert(pointer->off < table->len); in basl_finish_patch_pointers()
282 assert(pointer->off + pointer->size <= table->len); in basl_finish_patch_pointers()
284 src_table = basl_get_table_by_signature(pointer->src_signature); in basl_finish_patch_pointers()
287 pointer->src_signature); in basl_finish_patch_pointers()
293 qemu_loader_add_pointer(basl_loader, table->fwcfg_name, in basl_finish_patch_pointers()
294 src_table->fwcfg_name, pointer->off, pointer->size)); in basl_finish_patch_pointers()
306 gpa = BHYVE_ACPI_BASE + table->off; in basl_finish_patch_pointers()
307 if (gpa < BHYVE_ACPI_BASE) { in basl_finish_patch_pointers()
308 warnx("%s: table offset of 0x%8x is too large", in basl_finish_patch_pointers()
309 __func__, table->off); in basl_finish_patch_pointers()
313 gva = vm_map_gpa(table->ctx, gpa, table->len); in basl_finish_patch_pointers()
315 warnx("%s: could not map gpa [ 0x%16lx, 0x%16lx ]", in basl_finish_patch_pointers()
316 __func__, gpa, gpa + table->len); in basl_finish_patch_pointers()
320 val = basl_le_dec(gva + pointer->off, pointer->size); in basl_finish_patch_pointers()
321 val += BHYVE_ACPI_BASE + src_table->off; in basl_finish_patch_pointers()
322 basl_le_enc(gva + pointer->off, val, pointer->size); in basl_finish_patch_pointers()
325 return (0); in basl_finish_patch_pointers()
333 STAILQ_FOREACH(length, &table->lengths, chain) { in basl_finish_set_length()
334 assert(length->off < table->len); in basl_finish_set_length()
335 assert(length->off + length->size <= table->len); in basl_finish_set_length()
337 basl_le_enc((uint8_t *)table->data + length->off, table->len, in basl_finish_set_length()
338 length->size); in basl_finish_set_length()
341 return (0); in basl_finish_set_length()
348 uint32_t off = 0; in basl_finish()
383 return (0); in basl_finish()
396 return (0); in basl_init_rsdt()
409 return (0); in basl_init_xsdt()
420 return (0); in basl_init()
437 checksum->off = off; in basl_table_add_checksum()
438 checksum->start = start; in basl_table_add_checksum()
439 checksum->len = len; in basl_table_add_checksum()
441 STAILQ_INSERT_TAIL(&table->checksums, checksum, chain); in basl_table_add_checksum()
443 return (0); in basl_table_add_checksum()
461 length->off = off; in basl_table_add_length()
462 length->size = size; in basl_table_add_length()
464 STAILQ_INSERT_TAIL(&table->lengths, length, chain); in basl_table_add_length()
466 return (0); in basl_table_add_length()
485 memcpy(pointer->src_signature, src_signature, in basl_table_add_pointer()
486 sizeof(pointer->src_signature)); in basl_table_add_pointer()
487 pointer->off = off; in basl_table_add_pointer()
488 pointer->size = size; in basl_table_add_pointer()
490 STAILQ_INSERT_TAIL(&table->pointers, pointer, chain); in basl_table_add_pointer()
492 return (0); in basl_table_add_pointer()
504 if (table->len + len <= table->len) { in basl_table_append_bytes()
505 warnx("%s: table too large (table->len 0x%8x len 0x%8x)", in basl_table_append_bytes()
506 __func__, table->len, len); in basl_table_append_bytes()
510 table->data = reallocf(table->data, table->len + len); in basl_table_append_bytes()
511 if (table->data == NULL) { in basl_table_append_bytes()
512 warnx("%s: failed to realloc table to length 0x%8x", __func__, in basl_table_append_bytes()
513 table->len + len); in basl_table_append_bytes()
514 table->len = 0; in basl_table_append_bytes()
518 end = (uint8_t *)table->data + table->len; in basl_table_append_bytes()
519 table->len += len; in basl_table_append_bytes()
523 return (0); in basl_table_append_bytes()
532 BASL_EXEC(basl_table_add_checksum(table, table->len, start, len)); in basl_table_append_checksum()
533 BASL_EXEC(basl_table_append_int(table, 0, 1)); in basl_table_append_checksum()
535 return (0); in basl_table_append_checksum()
546 len - sizeof(ACPI_TABLE_HEADER))); in basl_table_append_content()
559 BASL_EXEC(qemu_loader_add_pointer(basl_loader, table->fwcfg_name, in basl_table_append_fwcfg()
560 fwcfg_name, table->len, size)); in basl_table_append_fwcfg()
561 BASL_EXEC(basl_table_append_int(table, 0, size)); in basl_table_append_fwcfg()
563 return (0); in basl_table_append_fwcfg()
592 assert(table->len == 0); in basl_table_append_header()
595 header_le.Length = 0; /* patched by basl_finish */ in basl_table_append_header()
597 header_le.Checksum = 0; /* patched by basl_finish */ in basl_table_append_header()
604 header_le.AslCompilerRevision = htole32(0x20220504); in basl_table_append_header()
612 offsetof(ACPI_TABLE_HEADER, Checksum), 0, in basl_table_append_header()
615 return (0); in basl_table_append_header()
634 assert(size <= sizeof(table->len)); in basl_table_append_length()
636 BASL_EXEC(basl_table_add_length(table, table->len, size)); in basl_table_append_length()
637 BASL_EXEC(basl_table_append_int(table, 0, size)); in basl_table_append_length()
639 return (0); in basl_table_append_length()
649 BASL_EXEC(basl_table_add_pointer(table, src_signature, table->len, size)); in basl_table_append_pointer()
650 BASL_EXEC(basl_table_append_int(table, 0, size)); in basl_table_append_pointer()
652 return (0); in basl_table_append_pointer()
669 new_table->ctx = ctx; in basl_table_create()
671 snprintf(new_table->fwcfg_name, sizeof(new_table->fwcfg_name), in basl_table_create()
674 new_table->alignment = alignment; in basl_table_create()
676 STAILQ_INIT(&new_table->checksums); in basl_table_create()
677 STAILQ_INIT(&new_table->lengths); in basl_table_create()
678 STAILQ_INIT(&new_table->pointers); in basl_table_create()
684 return (0); in basl_table_create()
694 header = (const ACPI_TABLE_HEADER *)table->data; in basl_table_register_to_rsdt()
696 BASL_EXEC(basl_table_append_pointer(rsdt, header->Signature, in basl_table_register_to_rsdt()
698 BASL_EXEC(basl_table_append_pointer(xsdt, header->Signature, in basl_table_register_to_rsdt()
701 return (0); in basl_table_register_to_rsdt()