Lines Matching +full:qemu +full:- +full:user +full:- +full:static

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
40 IOPORT_F_INOUT /* QEMU v2.4+ ignores writes */
106 static struct qemu_fwcfg_softc fwcfg_sc;
114 static STAILQ_HEAD(qemu_fwcfg_user_file_list,
118 static int
126 return (-1); in qemu_fwcfg_selector_port_handler()
140 static int
148 return (-1); in qemu_fwcfg_data_port_handler()
152 warnx("%s: Writes to qemu fwcfg data port aren't allowed", in qemu_fwcfg_data_port_handler()
154 return (-1); in qemu_fwcfg_data_port_handler()
161 if (item->data == NULL) { in qemu_fwcfg_data_port_handler()
163 "%s: qemu fwcfg item doesn't exist (architecture %s index 0x%x)", in qemu_fwcfg_data_port_handler()
169 } else if (fwcfg_sc.data_offset >= item->size) { in qemu_fwcfg_data_port_handler()
171 "%s: qemu fwcfg item read exceeds size (architecture %s index 0x%x size 0x%x offset 0x%x)", in qemu_fwcfg_data_port_handler()
174 fwcfg_sc.selector.index, item->size, fwcfg_sc.data_offset); in qemu_fwcfg_data_port_handler()
180 *eax = item->data[fwcfg_sc.data_offset]; in qemu_fwcfg_data_port_handler()
187 static int
199 if (fwcfg_item->data != NULL) { in qemu_fwcfg_add_item()
200 warnx("%s: qemu fwcfg item exists (architecture %s index 0x%x)", in qemu_fwcfg_add_item()
206 fwcfg_item->size = size; in qemu_fwcfg_add_item()
207 fwcfg_item->data = data; in qemu_fwcfg_add_item()
212 static int
229 static int
238 fwcfg_id->interface = 1; in qemu_fwcfg_add_item_id()
239 fwcfg_id->DMA = 0; in qemu_fwcfg_add_item_id()
249 static int
267 static int
281 static int
290 fwcfg_signature->signature[0] = 'Q'; in qemu_fwcfg_add_item_signature()
291 fwcfg_signature->signature[1] = 'E'; in qemu_fwcfg_add_item_signature()
292 fwcfg_signature->signature[2] = 'M'; in qemu_fwcfg_add_item_signature()
293 fwcfg_signature->signature[3] = 'U'; in qemu_fwcfg_add_item_signature()
301 static int
325 * QEMU specifies count as big endian. in qemu_fwcfg_add_file()
328 const uint32_t count = be32toh(fwcfg_sc.directory->be_count) + 1; in qemu_fwcfg_add_file()
331 const uint32_t index = QEMU_FWCFG_FIRST_FILE_INDEX + count - 1; in qemu_fwcfg_add_file()
342 for (file_index = 0; file_index < count - 1; ++file_index) { in qemu_fwcfg_add_file()
343 if (strcmp(name, fwcfg_sc.directory->files[file_index].name) < in qemu_fwcfg_add_file()
356 "%s: Unable to allocate a new qemu fwcfg files directory (count %d)", in qemu_fwcfg_add_file()
362 memcpy(new_directory->files, fwcfg_sc.directory->files, in qemu_fwcfg_add_file()
366 memcpy(&new_directory->files[file_index + 1], in qemu_fwcfg_add_file()
367 &fwcfg_sc.directory->files[file_index], in qemu_fwcfg_add_file()
368 (count - file_index - 1) * sizeof(struct qemu_fwcfg_file)); in qemu_fwcfg_add_file()
381 for (uint32_t i = QEMU_FWCFG_MIN_FILES - 1; i > file_index; in qemu_fwcfg_add_file()
382 --i) { in qemu_fwcfg_add_file()
383 memcpy(&fwcfg_sc.directory->files[i], in qemu_fwcfg_add_file()
384 &fwcfg_sc.directory->files[i - 1], in qemu_fwcfg_add_file()
390 * QEMU specifies count, size and index as big endian. in qemu_fwcfg_add_file()
394 fwcfg_sc.directory->be_count = htobe32(count); in qemu_fwcfg_add_file()
395 fwcfg_sc.directory->files[file_index].be_size = htobe32(size); in qemu_fwcfg_add_file()
396 fwcfg_sc.directory->files[file_index].be_selector = htobe16(index); in qemu_fwcfg_add_file()
397 strcpy(fwcfg_sc.directory->files[file_index].name, name); in qemu_fwcfg_add_file()
407 static int
414 error = qemu_fwcfg_add_file(fwcfg_file->name, fwcfg_file->size, in qemu_fwcfg_add_user_files()
415 fwcfg_file->data); in qemu_fwcfg_add_user_files()
423 static const struct acpi_device_emul qemu_fwcfg_acpi_device_emul = {
436 * interface and thus is amd64-specific for now. An MMIO interface is in qemu_fwcfg_init()
440 fwcfg_enabled = strcmp(lpc_fwcfg(), "qemu") == 0; in qemu_fwcfg_init()
446 * Bhyve supports fwctl (bhyve) and fwcfg (qemu) as firmware interfaces. in qemu_fwcfg_init()
455 warnx("%s: failed to create ACPI device for QEMU FwCfg", in qemu_fwcfg_init()
463 warnx("%s: failed to add fixed IO port for QEMU FwCfg", in qemu_fwcfg_init()
475 "%s: Unable to register qemu fwcfg selector port 0x%x", in qemu_fwcfg_init()
484 "%s: Unable to register qemu fwcfg data port 0x%x", in qemu_fwcfg_init()
512 /* add user defined fwcfg files */ in qemu_fwcfg_init()
514 warnx("%s: Unable to add user files", __func__); in qemu_fwcfg_init()
526 static void
530 warnx("-f [name=]<name>,(string|file)=<value>"); in qemu_fwcfg_usage()
534 * Parses the cmdline argument for user defined fw_cfg items. The cmdline
536 * "-f [name=]<name>,(string|file)=<value>"
538 * E.g.: "-f opt/com.page/example,string=Hello"
558 if (strncmp(opt_ptr, "name=", sizeof("name=") - 1) == 0) { in qemu_fwcfg_parse_cmdline_arg()
559 opt_ptr += sizeof("name=") - 1; in qemu_fwcfg_parse_cmdline_arg()
570 if (opt_end - opt_ptr >= QEMU_FWCFG_MAX_NAME) { in qemu_fwcfg_parse_cmdline_arg()
576 strncpy(fwcfg_file->name, opt_ptr, opt_end - opt_ptr); in qemu_fwcfg_parse_cmdline_arg()
577 fwcfg_file->name[opt_end - opt_ptr] = '\0'; in qemu_fwcfg_parse_cmdline_arg()
583 if (strncmp(opt_ptr, "string=", sizeof("string=") - 1) == 0) { in qemu_fwcfg_parse_cmdline_arg()
584 opt_ptr += sizeof("string=") - 1; in qemu_fwcfg_parse_cmdline_arg()
585 fwcfg_file->data = strdup(opt_ptr); in qemu_fwcfg_parse_cmdline_arg()
586 if (fwcfg_file->data == NULL) { in qemu_fwcfg_parse_cmdline_arg()
591 fwcfg_file->size = strlen(opt_ptr) + 1; in qemu_fwcfg_parse_cmdline_arg()
592 } else if (strncmp(opt_ptr, "file=", sizeof("file=") - 1) == 0) { in qemu_fwcfg_parse_cmdline_arg()
593 opt_ptr += sizeof("file=") - 1; in qemu_fwcfg_parse_cmdline_arg()
605 return (-1); in qemu_fwcfg_parse_cmdline_arg()
608 fwcfg_file->data = malloc(sb.st_size); in qemu_fwcfg_parse_cmdline_arg()
609 if (fwcfg_file->data == NULL) { in qemu_fwcfg_parse_cmdline_arg()
616 bytes_read = read(fd, fwcfg_file->data, sb.st_size); in qemu_fwcfg_parse_cmdline_arg()
619 free(fwcfg_file->data); in qemu_fwcfg_parse_cmdline_arg()
621 return (-1); in qemu_fwcfg_parse_cmdline_arg()
623 fwcfg_file->size = bytes_read; in qemu_fwcfg_parse_cmdline_arg()