History

kvm: add device control API

Currently, devices that are emulated inside KVM are configured in a hardcoded manner based on an assumption that any given architecture only has one way to do it. If there's any need to access device state, it is done through inflexible one-purpose-only IOCTLs (e.g. KVM_GET/SET_LAPIC). Defining new IOCTLs for every little thing is cumbersome and depletes a limited numberspace. This API provides a mechanism to instantiate a device of a certain type, returning an ID that can be used to set/get attributes of the device. Attributes may include configuration parameters (e.g. register base address), device state, operational commands, etc. It is similar to the ONE_REG API, except that it acts on devices rather than vcpus. Both device types and individual attributes can be tested without having to create the device or get/set the attribute, without the need for separately managing enumerated capabilities.

Scott Wood committed 13 years ago

Commit 852b6d51 parent 7df35f55 files · +262 −0Browse files

Showing the changes to include/uapi/linux (1 of 5 files). Show all

Unified · Split

include/uapi/linux/kvm.h+27−0
@@ -666,6 +666,7 @@ struct kvm_ppc_smmu_info { · 665 unmodified lines
666#define KVM_CAP_PPC_EPR 86666#define KVM_CAP_PPC_EPR 86
667#define KVM_CAP_ARM_PSCI 87667#define KVM_CAP_ARM_PSCI 87
668#define KVM_CAP_ARM_SET_DEVICE_ADDR 88668#define KVM_CAP_ARM_SET_DEVICE_ADDR 88
669#define KVM_CAP_DEVICE_CTRL 89
669 670
670#ifdef KVM_CAP_IRQ_ROUTING671#ifdef KVM_CAP_IRQ_ROUTING
671 672
@@ -818,6 +819,24 @@ struct kvm_arm_device_addr { · 146 unmodified lines
818 __u64 addr;819 __u64 addr;
819};820};
820 821
822/*
823 * Device control API, available with KVM_CAP_DEVICE_CTRL
824 */
825#define KVM_CREATE_DEVICE_TEST 1
826
827struct kvm_create_device {
828 __u32 type; /* in: KVM_DEV_TYPE_xxx */
829 __u32 fd; /* out: device handle */
830 __u32 flags; /* in: KVM_CREATE_DEVICE_xxx */
831};
832
833struct kvm_device_attr {
834 __u32 flags; /* no flags currently defined */
835 __u32 group; /* device-defined */
836 __u64 attr; /* group-defined */
837 __u64 addr; /* userspace address of attr data */
838};
839
821/*840/*
822 * ioctls for VM fds841 * ioctls for VM fds
823 */842 */
@@ -906,6 +925,14 @@ struct kvm_s390_ucas_mapping { · 82 unmodified lines
906/* Available with KVM_CAP_ARM_SET_DEVICE_ADDR */925/* Available with KVM_CAP_ARM_SET_DEVICE_ADDR */
907#define KVM_ARM_SET_DEVICE_ADDR _IOW(KVMIO, 0xab, struct kvm_arm_device_addr)926#define KVM_ARM_SET_DEVICE_ADDR _IOW(KVMIO, 0xab, struct kvm_arm_device_addr)
908 927
928/* ioctl for vm fd */
929#define KVM_CREATE_DEVICE _IOWR(KVMIO, 0xe0, struct kvm_create_device)
930
931/* ioctls for fds returned by KVM_CREATE_DEVICE */
932#define KVM_SET_DEVICE_ATTR _IOW(KVMIO, 0xe1, struct kvm_device_attr)
933#define KVM_GET_DEVICE_ATTR _IOW(KVMIO, 0xe2, struct kvm_device_attr)
934#define KVM_HAS_DEVICE_ATTR _IOW(KVMIO, 0xe3, struct kvm_device_attr)
935
909/*936/*
910 * ioctls for vcpu fds937 * ioctls for vcpu fds
911 */938 */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t