Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/pci_lpc.c
Show All 28 Lines | |||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <machine/vmm.h> | #include <machine/vmm.h> | ||||
#include <vmmapi.h> | |||||
#include <machine/vmm_snapshot.h> | #include <machine/vmm_snapshot.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <vmmapi.h> | |||||
#include "acpi.h" | #include "acpi.h" | ||||
#include "debug.h" | #include "debug.h" | ||||
#include "bootrom.h" | #include "bootrom.h" | ||||
#include "inout.h" | #include "inout.h" | ||||
#include "pci_emul.h" | #include "pci_emul.h" | ||||
#include "pci_irq.h" | #include "pci_irq.h" | ||||
#include "pci_lpc.h" | #include "pci_lpc.h" | ||||
#include "pctestdev.h" | |||||
#include "uart_emul.h" | #include "uart_emul.h" | ||||
#define IO_ICU1 0x20 | #define IO_ICU1 0x20 | ||||
#define IO_ICU2 0xA0 | #define IO_ICU2 0xA0 | ||||
SET_DECLARE(lpc_dsdt_set, struct lpc_dsdt); | SET_DECLARE(lpc_dsdt_set, struct lpc_dsdt); | ||||
SET_DECLARE(lpc_sysres_set, struct lpc_sysres); | SET_DECLARE(lpc_sysres_set, struct lpc_sysres); | ||||
Show All 15 Lines | static struct lpc_uart_softc { | ||||
const char *opts; | const char *opts; | ||||
int iobase; | int iobase; | ||||
int irq; | int irq; | ||||
int enabled; | int enabled; | ||||
} lpc_uart_softc[LPC_UART_NUM]; | } lpc_uart_softc[LPC_UART_NUM]; | ||||
static const char *lpc_uart_names[LPC_UART_NUM] = { "COM1", "COM2", "COM3", "COM4" }; | static const char *lpc_uart_names[LPC_UART_NUM] = { "COM1", "COM2", "COM3", "COM4" }; | ||||
static bool pctestdev_present; | |||||
/* | /* | ||||
* LPC device configuration is in the following form: | * LPC device configuration is in the following form: | ||||
* <lpc_device_name>[,<options>] | * <lpc_device_name>[,<options>] | ||||
* For e.g. "com1,stdio" or "bootrom,/var/romfile" | * For e.g. "com1,stdio" or "bootrom,/var/romfile" | ||||
*/ | */ | ||||
int | int | ||||
lpc_device_parse(const char *opts) | lpc_device_parse(const char *opts) | ||||
{ | { | ||||
Show All 11 Lines | if (lpcdev != NULL) { | ||||
} | } | ||||
for (unit = 0; unit < LPC_UART_NUM; unit++) { | for (unit = 0; unit < LPC_UART_NUM; unit++) { | ||||
if (strcasecmp(lpcdev, lpc_uart_names[unit]) == 0) { | if (strcasecmp(lpcdev, lpc_uart_names[unit]) == 0) { | ||||
lpc_uart_softc[unit].opts = str; | lpc_uart_softc[unit].opts = str; | ||||
error = 0; | error = 0; | ||||
goto done; | goto done; | ||||
} | } | ||||
} | } | ||||
if (strcasecmp(lpcdev, pctestdev_getname()) == 0) { | |||||
if (pctestdev_present) { | |||||
EPRINTLN("More than one %s device conf is " | |||||
"specified; only one is allowed.", | |||||
pctestdev_getname()); | |||||
} else if (pctestdev_parse(str) == 0) { | |||||
pctestdev_present = true; | |||||
error = 0; | |||||
free(cpy); | |||||
goto done; | |||||
} | } | ||||
} | |||||
} | |||||
done: | done: | ||||
if (error) | if (error) | ||||
free(cpy); | free(cpy); | ||||
return (error); | return (error); | ||||
} | } | ||||
void | void | ||||
lpc_print_supported_devices() | lpc_print_supported_devices() | ||||
{ | { | ||||
size_t i; | size_t i; | ||||
printf("bootrom\n"); | printf("bootrom\n"); | ||||
for (i = 0; i < LPC_UART_NUM; i++) | for (i = 0; i < LPC_UART_NUM; i++) | ||||
printf("%s\n", lpc_uart_names[i]); | printf("%s\n", lpc_uart_names[i]); | ||||
printf("%s\n", pctestdev_getname()); | |||||
} | } | ||||
const char * | const char * | ||||
lpc_bootrom(void) | lpc_bootrom(void) | ||||
{ | { | ||||
return (romfile); | return (romfile); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | for (unit = 0; unit < LPC_UART_NUM; unit++) { | ||||
iop.handler = lpc_uart_io_handler; | iop.handler = lpc_uart_io_handler; | ||||
iop.arg = sc; | iop.arg = sc; | ||||
error = register_inout(&iop); | error = register_inout(&iop); | ||||
assert(error == 0); | assert(error == 0); | ||||
sc->enabled = 1; | sc->enabled = 1; | ||||
} | } | ||||
/* pc-testdev */ | |||||
if (pctestdev_present) { | |||||
error = pctestdev_init(ctx); | |||||
if (error) | |||||
return (error); | |||||
} | |||||
return (0); | return (0); | ||||
} | } | ||||
static void | static void | ||||
pci_lpc_write_dsdt(struct pci_devinst *pi) | pci_lpc_write_dsdt(struct pci_devinst *pi) | ||||
{ | { | ||||
struct lpc_dsdt **ldpp, *ldp; | struct lpc_dsdt **ldpp, *ldp; | ||||
▲ Show 20 Lines • Show All 212 Lines • ▼ Show 20 Lines | |||||
#ifdef BHYVE_SNAPSHOT | #ifdef BHYVE_SNAPSHOT | ||||
static int | static int | ||||
pci_lpc_snapshot(struct vm_snapshot_meta *meta) | pci_lpc_snapshot(struct vm_snapshot_meta *meta) | ||||
{ | { | ||||
int unit, ret; | int unit, ret; | ||||
struct uart_softc *sc; | struct uart_softc *sc; | ||||
SNAPSHOT_ADD_INTERN_ARR(uart, meta); | |||||
for (unit = 0; unit < LPC_UART_NUM; unit++) { | for (unit = 0; unit < LPC_UART_NUM; unit++) { | ||||
sc = lpc_uart_softc[unit].uart_softc; | sc = lpc_uart_softc[unit].uart_softc; | ||||
SNAPSHOT_SET_INTERN_ARR_INDEX(meta, unit); | |||||
ret = uart_snapshot(sc, meta); | ret = uart_snapshot(sc, meta); | ||||
if (ret != 0) | if (ret != 0) | ||||
goto done; | goto done; | ||||
} | } | ||||
SNAPSHOT_CLEAR_INTERN_ARR_INDEX(meta); | |||||
SNAPSHOT_REMOVE_INTERN_ARR(uart, meta); | |||||
done: | done: | ||||
return (ret); | return (ret); | ||||
} | } | ||||
#endif | #endif | ||||
struct pci_devemu pci_de_lpc = { | struct pci_devemu pci_de_lpc = { | ||||
.pe_emu = "lpc", | .pe_emu = "lpc", | ||||
Show All 10 Lines |