Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/pci_lpc.c
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
#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" }; | static const char *lpc_uart_names[LPC_UART_NUM] = { "COM1", "COM2" }; | ||||
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; | |||||
markj: I think this could be simplified a bit:
```
if (pctestdev_present) {
...
} else if… | |||||
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 90 Lines • ▼ Show 20 Lines | for (unit = 0; unit < LPC_UART_NUM; unit++) { | ||||
iop.size = UART_IO_BAR_SIZE; | iop.size = UART_IO_BAR_SIZE; | ||||
iop.flags = IOPORT_F_INOUT; | iop.flags = IOPORT_F_INOUT; | ||||
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) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 247 Lines • Show Last 20 Lines |
I think this could be simplified a bit: