Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/pci_ahci.c
Show All 36 Lines | |||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <sys/uio.h> | #include <sys/uio.h> | ||||
#include <sys/ioctl.h> | #include <sys/ioctl.h> | ||||
#include <sys/disk.h> | #include <sys/disk.h> | ||||
#include <sys/ata.h> | #include <sys/ata.h> | ||||
#include <sys/endian.h> | #include <sys/endian.h> | ||||
#include <machine/vmm_snapshot.h> | #include <machine/vmm_snapshot.h> | ||||
#ifdef BHYVE_SNAPSHOT | |||||
#include "snapshot.h" | |||||
#endif | |||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <strings.h> | #include <strings.h> | ||||
▲ Show 20 Lines • Show All 2,271 Lines • ▼ Show 20 Lines | pci_ahci_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts, int atapi) | ||||
MD5_CTX mdctx; | MD5_CTX mdctx; | ||||
u_char digest[16]; | u_char digest[16]; | ||||
char *next, *next2; | char *next, *next2; | ||||
char *bopt, *uopt, *xopts, *config; | char *bopt, *uopt, *xopts, *config; | ||||
FILE* fp; | FILE* fp; | ||||
size_t block_len; | size_t block_len; | ||||
int comma, optpos; | int comma, optpos; | ||||
#ifdef BHYVE_SNAPSHOT | |||||
struct vm_snapshot_dev_info *dev_info; | |||||
#endif | |||||
ret = 0; | ret = 0; | ||||
#ifdef AHCI_DEBUG | #ifdef AHCI_DEBUG | ||||
dbg = fopen("/tmp/log", "w+"); | dbg = fopen("/tmp/log", "w+"); | ||||
#endif | #endif | ||||
sc = calloc(1, sizeof(struct pci_ahci_softc)); | sc = calloc(1, sizeof(struct pci_ahci_softc)); | ||||
pi->pi_arg = sc; | pi->pi_arg = sc; | ||||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | #endif | ||||
p = MIN(sc->ports, 16); | p = MIN(sc->ports, 16); | ||||
p = flsl(p) - ((p & (p - 1)) ? 0 : 1); | p = flsl(p) - ((p & (p - 1)) ? 0 : 1); | ||||
pci_emul_add_msicap(pi, 1 << p); | pci_emul_add_msicap(pi, 1 << p); | ||||
pci_emul_alloc_bar(pi, 5, PCIBAR_MEM32, | pci_emul_alloc_bar(pi, 5, PCIBAR_MEM32, | ||||
AHCI_OFFSET + sc->ports * AHCI_STEP); | AHCI_OFFSET + sc->ports * AHCI_STEP); | ||||
pci_lintr_request(pi); | pci_lintr_request(pi); | ||||
#ifdef BHYVE_SNAPSHOT | |||||
dev_info = calloc(1, sizeof(*dev_info)); | |||||
gusev.vitaliy_gmail.com: Instead allocating dev_info, I would like to suggest to use one of the following:
1. Use "sc"… | |||||
darius.mihaim_gmail.comUnsubmitted Not Done Inline ActionsSome of the information will need to be used outside the context of the device itself - the static array of user devices has been removed, so the snapshot component must keep track of the functions that need to be called when performing a snapshot or restore. Also, for devices like atkbdc, the snapshot_pci_device_register will likely not be compatible. Before having support for atkbdc, the static userspace device array was also not required, since you could discover most devices through the PCI bus; however, if other device types are to be supported, a more generic approach is required. However, I agree that some of the logic, like allocating the structure and performing a part of the initialization could be done separately. darius.mihaim_gmail.com: Some of the information will need to be used outside the context of the device itself - the… | |||||
if (!dev_info) { | |||||
fprintf(stderr, "Error allocating space for snapshot struct"); | |||||
goto open_fail; | |||||
} | |||||
dev_info->dev_name = pi->pi_d->pe_emu; | |||||
dev_info->was_restored = 0; | |||||
dev_info->meta_data = pi; | |||||
dev_info->snapshot_cb = pci_snapshot; | |||||
dev_info->pause_cb = pci_pause; | |||||
dev_info->resume_cb = pci_resume; | |||||
insert_registered_devs(dev_info); | |||||
#endif | |||||
open_fail: | open_fail: | ||||
if (ret) { | if (ret) { | ||||
for (p = 0; p < sc->ports; p++) { | for (p = 0; p < sc->ports; p++) { | ||||
if (sc->port[p].bctx != NULL) | if (sc->port[p].bctx != NULL) | ||||
blockif_close(sc->port[p].bctx); | blockif_close(sc->port[p].bctx); | ||||
} | } | ||||
free(sc); | free(sc); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | if (port->port != i) { | ||||
goto done; | goto done; | ||||
} | } | ||||
SNAPSHOT_GUEST2HOST_ADDR_OR_LEAVE(port->cmd_lst, | SNAPSHOT_GUEST2HOST_ADDR_OR_LEAVE(port->cmd_lst, | ||||
AHCI_CL_SIZE * AHCI_MAX_SLOTS, false, meta, ret, done); | AHCI_CL_SIZE * AHCI_MAX_SLOTS, false, meta, ret, done); | ||||
SNAPSHOT_GUEST2HOST_ADDR_OR_LEAVE(port->rfis, 256, false, meta, | SNAPSHOT_GUEST2HOST_ADDR_OR_LEAVE(port->rfis, 256, false, meta, | ||||
ret, done); | ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(port->ident, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(port->ata_ident, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(port->atapi, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(port->atapi, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(port->reset, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(port->reset, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(port->waitforclear, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(port->waitforclear, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(port->mult_sectors, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(port->mult_sectors, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(port->xfermode, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(port->xfermode, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(port->err_cfis, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(port->err_cfis, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(port->sense_key, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(port->sense_key, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(port->asc, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(port->asc, meta, ret, done); | ||||
▲ Show 20 Lines • Show All 146 Lines • Show Last 20 Lines |
Instead allocating dev_info, I would like to suggest to use one of the following:
snapshot_pci_device_register(pi)"; for pci devices snapshot_device_register(cb, data, name); for non-pci devices
And replace all init code for all devices with those functions.
This make code simpler and incapsulate all allocations, etc. Thus each decl "struct vm_snapshot_dev_info *dev_info" and code below will be removed in xxx_init() functions.