Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/pci_emul.h
| Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | |||||
| /* | /* | ||||
| * In case the structure is modified to hold extra information, use a define | * In case the structure is modified to hold extra information, use a define | ||||
| * for the size that should be emulated. | * for the size that should be emulated. | ||||
| */ | */ | ||||
| #define MSIX_TABLE_ENTRY_SIZE 16 | #define MSIX_TABLE_ENTRY_SIZE 16 | ||||
| #define MAX_MSIX_TABLE_ENTRIES 2048 | #define MAX_MSIX_TABLE_ENTRIES 2048 | ||||
| #define PBA_SIZE(msgnum) (roundup2((msgnum), 64) / 8) | #define PBA_SIZE(msgnum) (roundup2((msgnum), 64) / 8) | ||||
| enum lintr_stat { | |||||
| IDLE, | |||||
| ASSERTED, | |||||
| PENDING | |||||
| }; | |||||
| struct pci_devinst { | struct pci_devinst { | ||||
| struct pci_devemu *pi_d; | struct pci_devemu *pi_d; | ||||
| struct vmctx *pi_vmctx; | struct vmctx *pi_vmctx; | ||||
| uint8_t pi_bus, pi_slot, pi_func; | uint8_t pi_bus, pi_slot, pi_func; | ||||
| char pi_name[PI_NAMESZ]; | char pi_name[PI_NAMESZ]; | ||||
| int pi_bar_getsize; | int pi_bar_getsize; | ||||
| int pi_prevcap; | int pi_prevcap; | ||||
| int pi_capend; | int pi_capend; | ||||
| #ifdef __amd64__ | |||||
corvink: This ifdef isn't required. Especially, as legacy interrupts could be implemented by arm64 too. | |||||
Not Done Inline ActionsI think it's fine to #ifdef this. I would be tempted perhaps to have a helper macro that is something like 'PCI_LINTR` that is only defined on platforms that support legacy interrupts, but I don't think we are likely to support them on either arm64 or RISC-V, so making it all conditional on only amd64 is fine (unless PCI_LINTR would be more readable). jhb: I think it's fine to #ifdef this. I would be tempted perhaps to have a helper macro that is… | |||||
Done Inline ActionsA more abstract PCI_LINTR symbol would be more readable, but this code is also tied to amd64-specific interfaces (e.g., from ioapic.h), so I'm on the fence here. I think I'll just leave it as is.
Me too, at least most of the ifdefs in bhyverun.c will go away once the file is split into MD components. markj: A more abstract PCI_LINTR symbol would be more readable, but this code is also tied to amd64… | |||||
| struct { | struct { | ||||
| int8_t pin; | int8_t pin; | ||||
| enum lintr_stat state; | enum { | ||||
| IDLE, | |||||
| ASSERTED, | |||||
| PENDING, | |||||
| } state; | |||||
| int pirq_pin; | int pirq_pin; | ||||
| int ioapic_irq; | int ioapic_irq; | ||||
| pthread_mutex_t lock; | pthread_mutex_t lock; | ||||
| } pi_lintr; | } pi_lintr; | ||||
| #endif | |||||
| struct { | struct { | ||||
| int enabled; | int enabled; | ||||
| uint64_t addr; | uint64_t addr; | ||||
| uint64_t msg_data; | uint64_t msg_data; | ||||
| int maxmsgnum; | int maxmsgnum; | ||||
| } pi_msi; | } pi_msi; | ||||
| ▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | struct pciecap { | ||||
| uint16_t link_status2; | uint16_t link_status2; | ||||
| uint32_t slot_capabilities2; /* ports with slots */ | uint32_t slot_capabilities2; /* ports with slots */ | ||||
| uint16_t slot_control2; | uint16_t slot_control2; | ||||
| uint16_t slot_status2; | uint16_t slot_status2; | ||||
| } __packed; | } __packed; | ||||
| static_assert(sizeof(struct pciecap) == 60, "compile-time assertion failed"); | static_assert(sizeof(struct pciecap) == 60, "compile-time assertion failed"); | ||||
| #ifdef __amd64__ | |||||
| typedef void (*pci_lintr_cb)(int b, int s, int pin, int pirq_pin, | typedef void (*pci_lintr_cb)(int b, int s, int pin, int pirq_pin, | ||||
| int ioapic_irq, void *arg); | int ioapic_irq, void *arg); | ||||
| void pci_lintr_assert(struct pci_devinst *pi); | |||||
| void pci_lintr_deassert(struct pci_devinst *pi); | |||||
| void pci_lintr_request(struct pci_devinst *pi); | |||||
| int pci_count_lintr(int bus); | |||||
| void pci_walk_lintr(int bus, pci_lintr_cb cb, void *arg); | |||||
| #endif | |||||
| int init_pci(struct vmctx *ctx); | int init_pci(struct vmctx *ctx); | ||||
| void pci_callback(void); | void pci_callback(void); | ||||
| uint32_t pci_config_read_reg(const struct pcisel *host_sel, nvlist_t *nvl, | uint32_t pci_config_read_reg(const struct pcisel *host_sel, nvlist_t *nvl, | ||||
| uint32_t reg, uint8_t size, uint32_t def); | uint32_t reg, uint8_t size, uint32_t def); | ||||
| int pci_emul_alloc_bar(struct pci_devinst *pdi, int idx, | int pci_emul_alloc_bar(struct pci_devinst *pdi, int idx, | ||||
| enum pcibar_type type, uint64_t size); | enum pcibar_type type, uint64_t size); | ||||
| int pci_emul_alloc_rom(struct pci_devinst *const pdi, const uint64_t size, | int pci_emul_alloc_rom(struct pci_devinst *const pdi, const uint64_t size, | ||||
| void **const addr); | void **const addr); | ||||
| int pci_emul_add_boot_device(struct pci_devinst *const pi, | int pci_emul_add_boot_device(struct pci_devinst *const pi, | ||||
| const int bootindex); | const int bootindex); | ||||
| int pci_emul_add_msicap(struct pci_devinst *pi, int msgnum); | int pci_emul_add_msicap(struct pci_devinst *pi, int msgnum); | ||||
| int pci_emul_add_pciecap(struct pci_devinst *pi, int pcie_device_type); | int pci_emul_add_pciecap(struct pci_devinst *pi, int pcie_device_type); | ||||
| void pci_emul_capwrite(struct pci_devinst *pi, int offset, int bytes, | void pci_emul_capwrite(struct pci_devinst *pi, int offset, int bytes, | ||||
| uint32_t val, uint8_t capoff, int capid); | uint32_t val, uint8_t capoff, int capid); | ||||
| void pci_emul_cmd_changed(struct pci_devinst *pi, uint16_t old); | void pci_emul_cmd_changed(struct pci_devinst *pi, uint16_t old); | ||||
| void pci_generate_msi(struct pci_devinst *pi, int msgnum); | void pci_generate_msi(struct pci_devinst *pi, int msgnum); | ||||
| void pci_generate_msix(struct pci_devinst *pi, int msgnum); | void pci_generate_msix(struct pci_devinst *pi, int msgnum); | ||||
| void pci_lintr_assert(struct pci_devinst *pi); | |||||
| void pci_lintr_deassert(struct pci_devinst *pi); | |||||
| void pci_lintr_request(struct pci_devinst *pi); | |||||
| int pci_msi_enabled(struct pci_devinst *pi); | int pci_msi_enabled(struct pci_devinst *pi); | ||||
| int pci_msix_enabled(struct pci_devinst *pi); | int pci_msix_enabled(struct pci_devinst *pi); | ||||
| int pci_msix_table_bar(struct pci_devinst *pi); | int pci_msix_table_bar(struct pci_devinst *pi); | ||||
| int pci_msix_pba_bar(struct pci_devinst *pi); | int pci_msix_pba_bar(struct pci_devinst *pi); | ||||
| int pci_msi_maxmsgnum(struct pci_devinst *pi); | int pci_msi_maxmsgnum(struct pci_devinst *pi); | ||||
| int pci_parse_legacy_config(nvlist_t *nvl, const char *opt); | int pci_parse_legacy_config(nvlist_t *nvl, const char *opt); | ||||
| int pci_parse_slot(char *opt); | int pci_parse_slot(char *opt); | ||||
| void pci_print_supported_devices(void); | void pci_print_supported_devices(void); | ||||
| void pci_populate_msicap(struct msicap *cap, int msgs, int nextptr); | void pci_populate_msicap(struct msicap *cap, int msgs, int nextptr); | ||||
| int pci_emul_add_msixcap(struct pci_devinst *pi, int msgnum, int barnum); | int pci_emul_add_msixcap(struct pci_devinst *pi, int msgnum, int barnum); | ||||
| int pci_emul_msix_twrite(struct pci_devinst *pi, uint64_t offset, int size, | int pci_emul_msix_twrite(struct pci_devinst *pi, uint64_t offset, int size, | ||||
| uint64_t value); | uint64_t value); | ||||
| uint64_t pci_emul_msix_tread(struct pci_devinst *pi, uint64_t offset, int size); | uint64_t pci_emul_msix_tread(struct pci_devinst *pi, uint64_t offset, int size); | ||||
| int pci_count_lintr(int bus); | |||||
| void pci_walk_lintr(int bus, pci_lintr_cb cb, void *arg); | |||||
| void pci_write_dsdt(void); | void pci_write_dsdt(void); | ||||
| uint64_t pci_ecfg_base(void); | uint64_t pci_ecfg_base(void); | ||||
| int pci_bus_configured(int bus); | int pci_bus_configured(int bus); | ||||
| #ifdef BHYVE_SNAPSHOT | #ifdef BHYVE_SNAPSHOT | ||||
| struct pci_devinst *pci_next(const struct pci_devinst *cursor); | struct pci_devinst *pci_next(const struct pci_devinst *cursor); | ||||
| int pci_snapshot(struct vm_snapshot_meta *meta); | int pci_snapshot(struct vm_snapshot_meta *meta); | ||||
| int pci_pause(struct pci_devinst *pdi); | int pci_pause(struct pci_devinst *pdi); | ||||
| int pci_resume(struct pci_devinst *pdi); | int pci_resume(struct pci_devinst *pdi); | ||||
| #endif | #endif | ||||
| static __inline void | static __inline void | ||||
| ▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines | |||||
This ifdef isn't required. Especially, as legacy interrupts could be implemented by arm64 too.
In general, I'd like to avoid ifdefs as much as possible. However, I don't have a strong preference here.