您的位置:首页 > 其它

[虚拟化/云][全栈demo] 为qemu增加一个PCI的watchdog外设(四)

2014-07-06 21:57 806 查看
通过前面的操作,我们已经可以创建一个带有我们自己的PCI的watchdog外设qemu 虚拟机了。

目的:

1. 了解我们的外设情况。

2. 为在guest中开发我们自己的linux PCI驱动程序做准备。

查看我们的watchdog设备

考虑到ubuntu对于 spice的支持不好。我们采用VNC显示。

-vnc 127.0.0.1:21 -vga cirrus -chardev stdio,id=mon0 -mon chardev=mon0,mode=readline

启动qemu

$ sudo x86_64-softmmu/qemu-system-x86_64 -enable-kvm -m 1024 -smp 1,sockets=1,cores=1,threads=1 -device cstl-watchdog -device virtio-blk-pci,scsi=off,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -drive file=/home/shhfeng/iso/image/ubuntu.12.04.img,if=none,id=drive-virtio-disk0,format=qcow2,cache=none -net bridge,br=virbr2,helper=/home/shhfeng/qemu/debug/qemu-bridge-helper -net nic,model=virtio -vnc 127.0.0.1:21 -vga cirrus -chardev stdio,id=mon0 -mon chardev=mon0,mode=readline

在qemu的monitor中查看watchdog的信息:

(qemu) info qtree

(qemu) info qtree
bus: main-system-bus
type System
dev: hpet, id ""
gpio-in 2
gpio-out 1
timers = 3 (0x3)
msi = false
hpet-intcap = 4 (0x4)
irq 32
mmio 00000000fed00000/0000000000000400
dev: kvm-ioapic, id ""
gpio-in 24
gsi_base = 0 (0)
irq 0
mmio 00000000fec00000/0000000000001000
dev: i440FX-pcihost, id ""
pci-hole64-size = 18446744073709551615 (16 EiB)
short_root_bus = 0 (0)
irq 0
bus: pci.0
type PCI
dev: cstl-watchdog, id ""
expiration-ticks = 10 (0xa)
addr = 05.0
romfile = ""
rombar = 1 (0x1)
multifunction = false
command_serr_enable = true
class Class 0880, addr 00:05.0, pci id 1af4:0101 (sub 1af4:1100)
bar 0: i/o at 0xc070 [0xc07f]
dev: virtio-blk-pci, id "virtio-disk0"
class = 0 (0)
ioeventfd = true
vectors = 2 (0x2)
indirect_desc = true
event_idx = true
drive = "drive-virtio-disk0"
logical_block_size = 512 (0x200)
physical_block_size = 512 (0x200)
min_io_size = 0 (0)
opt_io_size = 0 (0)
bootindex = 2 (0x2)
discard_granularity = 4294967295 (0xffffffff)
cyls = 0 (0)
heads = 0 (0)
secs = 0 (0)
serial = ""
config-wce = true
scsi = false
x-iothread = ""
addr = 04.0
romfile = ""
rombar = 1 (0x1)
multifunction = false
command_serr_enable = true
class SCSI controller, addr 00:04.0, pci id 1af4:1001 (sub 1af4:0002)
bar 0: i/o at 0xc000 [0xc03f]
bar 1: mem at 0xfebd2000 [0xfebd2fff]
bus: virtio-bus
type virtio-pci-bus
dev: virtio-blk-device, id ""
drive = "drive-virtio-disk0"
logical_block_size = 512 (0x200)
physical_block_size = 512 (0x200)
min_io_size = 0 (0)
opt_io_size = 0 (0)
bootindex = 2 (0x2)
discard_granularity = 4294967295 (0xffffffff)
cyls = 16383 (0x3fff)
heads = 16 (0x10)
secs = 63 (0x3f)
serial = ""
config-wce = true
scsi = false
x-iothread = ""
dev: PIIX4_PM, id ""
smb_io_base = 45312 (0xb100)
disable_s3 = 0 (0)
disable_s4 = 0 (0)
s4_val = 2 (0x2)
acpi-pci-hotplug-with-bridge-support = true
addr = 01.3
romfile = ""
rombar = 1 (0x1)
multifunction = false
command_serr_enable = true
class Bridge, addr 00:01.3, pci id 8086:7113 (sub 1af4:1100)
bus: i2c
type i2c-bus
dev: smbus-eeprom, id ""
address = 87 (0x57)
dev: smbus-eeprom, id ""
address = 86 (0x56)
dev: smbus-eeprom, id ""
address = 85 (0x55)
dev: smbus-eeprom, id ""
address = 84 (0x54)
dev: smbus-eeprom, id ""
address = 83 (0x53)
dev: smbus-eeprom, id ""
address = 82 (0x52)
dev: smbus-eeprom, id ""
address = 81 (0x51)
dev: smbus-eeprom, id ""
address = 80 (0x50)
dev: piix3-ide, id ""
addr = 01.1
romfile = ""
rombar = 1 (0x1)
multifunction = false
command_serr_enable = true
class IDE controller, addr 00:01.1, pci id 8086:7010 (sub 1af4:1100)
bar 4: i/o at 0xc060 [0xc06f]
bus: ide.1
type IDE
dev: ide-cd, id "ide0-1-0"
drive = "drive-ide0-1-0"
logical_block_size = 512 (0x200)
physical_block_size = 512 (0x200)
min_io_size = 0 (0)
opt_io_size = 0 (0)
bootindex = 1 (0x1)
discard_granularity = 512 (0x200)
ver = "1.7.90"
wwn = 0 (0)
serial = "QM00003"
model = ""
unit = 0 (0)
bus: ide.0
type IDE
dev: virtio-net-pci, id ""
ioeventfd = false
vectors = 3 (0x3)
indirect_desc = true
event_idx = true
any_layout = true
csum = false
guest_csum = false
gso = true
guest_tso4 = false
guest_tso6 = false
guest_ecn = false
guest_ufo = false
host_tso4 = false
host_tso6 = false
host_ecn = false
host_ufo = false
mrg_rxbuf = true
status = true
ctrl_vq = true
ctrl_rx = true
ctrl_vlan = true
ctrl_rx_extra = true
ctrl_mac_addr = true
ctrl_guest_offloads = true
mq = false
mac = "52:54:00:12:34:56"
vlan = 0
netdev = "hub0port1"
bootindex = -1 (0xffffffffffffffff)
x-txtimer = 150000 (0x249f0)
x-txburst = 256 (0x100)
tx = ""
addr = 03.0
romfile = "efi-virtio.rom"
rombar = 1 (0x1)
multifunction = false
command_serr_enable = true
class Ethernet controller, addr 00:03.0, pci id 1af4:1000 (sub 1af4:0001)
bar 0: i/o at 0xc040 [0xc05f]
bar 1: mem at 0xfebd1000 [0xfebd1fff]
bar 6: mem at 0xffffffffffffffff [0x3fffe]
bus: virtio-bus
type virtio-pci-bus
dev: virtio-net-device, id ""
mac = "52:54:00:12:34:56"
vlan = 0
netdev = "hub0port1"
bootindex = -1 (0xffffffffffffffff)
x-txtimer = 150000 (0x249f0)
x-txburst = 256 (0x100)
tx = ""
dev: cirrus-vga, id ""
vgamem_mb = 8 (0x8)
addr = 02.0
romfile = "vgabios-cirrus.bin"
rombar = 1 (0x1)
multifunction = false
command_serr_enable = true
class VGA controller, addr 00:02.0, pci id 1013:00b8 (sub 1af4:1100)
bar 0: mem at 0xfc000000 [0xfdffffff]
bar 1: mem at 0xfebd0000 [0xfebd0fff]
bar 6: mem at 0xffffffffffffffff [0xfffe]
dev: PIIX3, id ""
addr = 01.0
romfile = ""
rombar = 1 (0x1)
multifunction = true
command_serr_enable = true
class ISA bridge, addr 00:01.0, pci id 8086:7000 (sub 1af4:1100)
bus: isa.0
type ISA
dev: isa-fdc, id ""
iobase = 1008 (0x3f0)
irq = 6 (0x6)
dma = 2 (0x2)
driveA = "floppy0"
driveB = ""
bootindexA = -1 (0xffffffffffffffff)
bootindexB = -1 (0xffffffffffffffff)
check_media_rate = true
isa irq 6
dev: port92, id ""
dev: vmmouse, id ""
dev: vmport, id ""
dev: i8042, id ""
isa irqs 1,12
dev: isa-parallel, id ""
index = 0 (0)
iobase = 888 (0x378)
irq = 7 (0x7)
chardev = "parallel0"
isa irq 7
dev: isa-serial, id ""
index = 0 (0)
iobase = 1016 (0x3f8)
irq = 4 (0x4)
chardev = "serial0"
wakeup = 0 (0)
isa irq 4
dev: isa-pcspk, id ""
iobase = 97 (0x61)
dev: kvm-pit, id ""
gpio-in 1
iobase = 64 (0x40)
lost_tick_policy = "delay"
dev: mc146818rtc, id ""
base_year = 0 (0)
lost_tick_policy = "discard"
dev: kvm-i8259, id ""
iobase = 160 (0xa0)
elcr_addr = 1233 (0x4d1)
elcr_mask = 222 (0xde)
master = false
dev: kvm-i8259, id ""
iobase = 32 (0x20)
elcr_addr = 1232 (0x4d0)
elcr_mask = 248 (0xf8)
master = true
dev: i440FX, id ""
addr = 00.0
romfile = ""
rombar = 1 (0x1)
multifunction = false
command_serr_enable = true
class Host bridge, addr 00:00.0, pci id 8086:1237 (sub 1af4:1100)
dev: fw_cfg, id ""
ctl_iobase = 1296 (0x510)
data_iobase = 1297 (0x511)
irq 0
mmio ffffffffffffffff/0000000000000002
mmio ffffffffffffffff/0000000000000001
dev: kvmclock, id ""
irq 0
dev: kvmvapic, id ""
irq 0
dev: icc-bridge, id ""
irq 0
mmio 00000000fee00000/0000000000100000
bus: icc
type icc-bus
dev: kvm-apic, id ""
id = 0 (0)
vapic = true
dev: qemu64-x86_64-cpu, id ""
pmu = false
hv-spinlocks = -1 (0xffffffffffffffff)
hv-relaxed = false
hv-vapic = false
hv-time = false
check = false
enforce = false


View Code
可以找到我们的watchdog设备:

dev: cstl-watchdog, id ""
expiration-ticks = 10 (0xa)
addr = 05.0
romfile = ""
rombar = 1 (0x1)
multifunction = false
command_serr_enable = true
class Class 0880, addr 00:05.0, pci id 1af4:0101 (sub 1af4:1100)
bar 0: i/o at 0xc090 [0xc09f]
有些激动。

在guest中查看watchdog的信息。

$ lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:02.0 VGA compatible controller: Cirrus Logic GD 5446
00:03.0 Ethernet controller: Red Hat, Inc Virtio network device
00:04.0 Ethernet controller: Red Hat, Inc Virtio network device
00:05.0 System peripheral: Red Hat, Inc Device 0101 (rev 01)
00:06.0 SCSI storage controller: Red Hat, Inc Virtio block device

可以看到我们的device设备, Red Hat, Inc Device 0101 (rev 01),这个我们的代码中定义的是一致的。

static void cwd_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);

k->init = cwd_realize;
k->exit = cwd_unrealize;
k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
k->device_id = 0x0101;
k->revision = 0x01;
k->class_id = PCI_CLASS_SYSTEM_OTHER;
dc->reset = cwd_reset;
dc->vmsd = &vmstate_cwd;
dc->props = cwd_properties;
}

在guest中,查看watchdog的配置寄存器

$ lspci -x
00:05.0 System peripheral: Red Hat, Inc Device 0101 (rev 01)
00: f4 1a 01 01 03 01 00 00 01 00 80 08 00 00 00 00
10: 91 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 f4 1a 00 11
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: