Commit Graph

737 Commits

Author SHA1 Message Date
Rong Liu df64877c50 dm: PTM: Check PTM root has more than one child
Add one more sanity check: If the root port has more than
	one child, we won't enable PTM on the guest.
	This is not necessarily an error.  We flag it as
	error just because we don't have this type of hw
	configuration at development time thus this configuration
	is not tested.

Tracked-On: #5915
Signed-off-by: Rong Liu <rong.l.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2021-05-19 13:54:24 +08:00
Rong Liu 721c866d63 dm: PTM: Enable ptm on passthru device
If user sets enable_ptm option on passthru device, passthru device
	calls ptm_probe() to check and enable ptm on passthru device.  If error
	is found during sanity check, ptm will not be enabled in the guest
	and an error will be reported to user.  However, this doesn't
	prevent user from launching guest and passing through the device to the guest.
	If no error is found, PTM is enabled in the guest and the
	passthru device will connect to virtual root port (which acts as PTM
	root) instead of virtual host bridge.

Tracked-On: #5915
Signed-off-by: Rong Liu <rong.l.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2021-05-19 13:54:24 +08:00
Rong Liu 7e93f31e2c dm: PTM: Add virtual root port to vm
If PTM can be enabled on passthru device, a virtual root port
	is added to vm to act as ptm root.  And the passthru device is
	connected to the virtual root port instead of the virtual host bridge.

Tracked-On: #5915
Signed-off-by: Rong Liu <rong.l.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2021-05-19 13:54:24 +08:00
Rong Liu d5d792aa96 dm: PTM: Check if hw supports ptm
This patch probes whether hw supports ptm.  It is used to check whether ptm
	can be enabled on the passthru pci device.  It checks whether passthru
	device support PTM requestor capability, then check whether its upstream
	root port support PTM root role.  Errors are reported to user if sanity
	check fails.

Tracked-On: #5915
Signed-off-by: Rong Liu <rong.l.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2021-05-19 13:54:24 +08:00
Rong Liu a7b0d9848f dm: PTM: Get # of children of a pci bridge or pci bus
Add functionality to build and cache pci hierarchy, which are mainly
    used to retrieve # of children of pci bridge or pci bus.

    get_device_count_on_bus(): get # of child devices on a pci bus
    get_device_count_on_bridge(): recursively get # of child devices on a pci bridge
    scan_pci(): build and cache pci hierarchy
    pci_find_root_port(): find root port of a pci device
    clean_pci_cache(): free pci cache
    scan_pci_test(): test of scan pci hierarchy (disabled)

Tracked-On: #5915
Signed-off-by: Rong Liu <rong.l.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2021-05-19 13:54:24 +08:00
Rong Liu d3185f8a0c dm: PTM: Add a few pci utility functions
Add a few pci utility functions to help easy access of pci
    functionalities.
    1. pci_find_capability(): find position of specified pci capability register
    2. pci_find_ext_cap(): find extend capability register position from cap_id
    3. pci_pcie_type(): find pci-e device type
    4. is_root_port(): check whether pdev is a pci root port
    5. is_bridge(): check whether pdev is a bridge

Tracked-On: #5915
Signed-off-by: Rong Liu <rong.l.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2021-05-19 13:54:24 +08:00
Tao Yuhong c2df3f7940 DM: mmio dev: remove hard code device index
mmio_devs[0] is hard code for acpidev_pt, and mmio_devs[1] for
mmiodev_pt. Use mmio_dev_idx as index of mmio_devs[], to remove hard
code.
Remove hpa, gpa, size information from mmio_dev_ops, add acrn_mmiodev into
mmio_dev, to record hpa, gpa and size information for each passthough
mmio device.

Tracked-On: #5913
Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2021-05-18 15:49:30 +08:00
Tao Yuhong 12f5a78800 DM: mmio dev: allocate GPA resource for mmio device
The mmio devices use hard code GPA base, allocating GPA base resource
for them instead.

Tracked-On: #5913
Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2021-05-18 15:49:30 +08:00
Tao Yuhong 63dd23bc9e DM: TPM: Do not set VTPM and passthough TPM simultaneously
The TPM information in ACPI table is for both VPTM and passthough TPM,
so only one TPM device is allowed.

Tracked-On: #5913
Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2021-05-18 15:49:30 +08:00
Tao Yuhong cb8a6a7514 DM: tpm: remove fixed value TPM_CRB_MMIO_ADDR
The GPA of TPM device has fixed value TPM_CRB_MMIO_ADDR, remove
TPM_CRB_MMIO_ADDR and allocate GPA base for TPM device

Tracked-On: #5913
Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2021-05-18 15:49:30 +08:00
Tao Yuhong f1c2eca1dc DM: support mmio dev gpa resource allocation
The ACPI MMIO devices, like TPM, has a fixed base GPA. Sould support
GPA resource allocating for MMIO devices. GPA region
0xF0000000~0xFE000000 is not used, can allocate GPA from it.

Tracked-On: #5913
Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2021-05-18 15:49:30 +08:00
Yonghua Huang 9c79e2ebdc dm: clean legacy software SRAM names
Remove below legacy SSRAM names:

  psram -> ssram
  ptct -> rtct

Tracked-On: #6015
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
2021-05-16 10:08:48 +08:00
Yonghua Huang 8ec150e314 dm: bugfix in create_and_inject_vrtct
GPA of software SRAM is available only after
 build_vrtct() function is called and the return
 value of it is valid(Not NULL).

 This patch fix bug in create_and_inject_vrtct()
 function which violates above pre-condition when
 calling get_software_sram_base_gpa().

Tracked-On: #5973
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
2021-04-28 09:32:19 +08:00
ppsun 2a96c567b8 DM: gvt: Identical mapping for GPU DSM refine to support EHL/TGL
Windows graphic driver obtains DSM address from in-BAR mmio register
which has passthroughed. Not like the other platforms obtained from
pci configure space register which has virtualized. GPU GuC must use
WOPCM in DSM, besides, Windows OS wants to manage DSM also. These two
reason force acrn has to keep identical mapping to avoid trap mmio
BAR to do the emulation.

Tracked-On: #5880
Signed-off-by: Peng Sun <peng.p.sun@intel.com>
2021-04-07 13:50:48 +08:00
Liu Long cba7caf71f DM: xHCI: Implement the USB PLS Machine flow spec.
From the Figure 11-10. Downstream Facing Hub Port State Machine the
device connect status should be disabled and the PLS should be polling
for USB2.0, when the device be connected, then the xHCD send the port
reset, for acrn we use libusb_reset_device to emulate the bus reset
action.

Tracked-On: #5795
Signed-off-by: Liu Long <long.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2021-03-04 11:30:24 +08:00
Victor Sun 3310412148 dm: remove _ADR object for PCI Device
Per ACPI 6.x chapter 6.1, "A device object must contain either an _HID object
or an _ADR object, but should not contain both."

Remove this object otherwise iasl would complain
"Warning  3073 -   Multiple types ^  (Device object requires either a _HID
or _ADR, but not both)"
when launch post-launched VM in devicemodel.

Tracked-On: #5719

Signed-off-by: Victor Sun <victor.sun@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2021-02-09 08:59:49 +08:00
Victor Sun 6b3f1d2315 dm: declare Processors using the Device operator
Per ACPI 6.x chapter 19.6.109, the Processor Operator is deprecated.
Replace it with Device Operator, otherwise the iasl would complain
"Warning  3168 -
	 Legacy Processor() keyword detected. Use Device() keyword instead."
when launch post-launched VM in devicemodel.

Tracked-On: #5719

Signed-off-by: Victor Sun <victor.sun@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2021-02-09 08:59:49 +08:00
Jian Jun Chen fad6a94030 dm: align bar base addr to PAGE_SIZE at least
PCI spec said that BAR base should be naturally aligned. But on
ACRN if the bar size < PAGE_SIZE, BAR base should be aligned with
PAGE_SIZE. This is because the minimal size that EPT can map/unmap
is PAGE_SIZE.

Tracked-On: #5717
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Reviewed-by: Fei Li <fei1.li@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2021-02-09 08:57:50 +08:00
Liu Long 1b255b7f51 DM: xHCI: Fix the USB3.2 device recognition problem.
The device descriptor describes general information about a device,
the bcdUSB field contains a BCD version number. The version 3.2 is
represented with value of 0x320H. Add the missed BCD version in the
bcdUSB case statement. And modify the return value of address device
command in case create device failed.

Tracked-On: #5712
Signed-off-by: Liu Long <long.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2021-02-07 09:13:58 +08:00
Yonghua Huang 154a446c5c dm: build vRTCT of Software SRAM for Post-launch RTVM
This patch prepares vRTCT for post-RTVM instead of
  pass-thru native RTCT:
   - Configurations are based on Service VM native RTCT.
   - Remap vLAPIC IDs in vRTCT.
   - Remap base address of SW SRAM memory regions
     from HPA to GPA.
   - HPA base of Software SRAM shall be parsed from PTCT
     instead of hardcoding.

Tracked-On: #5649
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
Reviewed-by: Fei Li <fei1.li@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2021-01-28 11:29:25 +08:00
Yonghua Huang 4ac1205b29 dm: cleanup legacy terminologies in RTCM module
Update below terminologies according to latest TCC Spec:
  PTCM -> RTCM
  PTCT -> RTCT
  PTCM binary -> CRL
  pSRAM -> Software SRAM

Tracked-On: #5649
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
2021-01-28 11:29:25 +08:00
Jie Deng d0aa8f9102 dm: virtio-gpio: avoid flood messages in virtio_irq_evt_notify
To avoid flood messages in virtio_irq_evt_notify.

Tracked-On: #5635
Signed-off-by: Jie Deng <jie.deng@intel.com>
2021-01-08 17:21:33 +08:00
Yonghua Huang 06e9220794 dm: rename ioctl command for hv-emulated management
Use add/remove device instead of create/destroy.

Tracked-On: #5586
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
2020-12-07 16:25:17 +08:00
Jie Deng 74203e39d9 dm: virtio_console: read only when the virtqueue is ready.
The read should not continue if the virtqueue is not ready.

Tracked-On: #5544
Signed-off-by: Jie Deng <jie.deng@intel.com>
2020-11-27 15:01:14 +08:00
Liu Long b37442564b DM: Add the return value check in case cause Null pointer exception
paddr_guest2host may return NULL, this patch checks the return value
to avoid null pointer dereference.

Tracked-On: #5514
Signed-off-by: Liu Long <long.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-11-18 09:51:42 +08:00
Tomas Winkler 9ab1110f80 dm: mei: vmei_proc_tx check buffer length before accessing the memory
Prevent memory and information leaks by checking boundaries of
the incoming buffers from the hypervisor.

1. We check that the buffer is sufficent to hold a valid header.
2. We that each hbm message has valid size
   vmei_hbm_handler() now returns -EINVAL if the size too small.
3. hdr->length < data_length.

Tracked-On: #5451
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-11-17 10:01:36 +08:00
Tomas Winkler 188ab4f85b dm: virtio: check for paddr_guest2host return value
paddr_guest2host can return NULL, but code paths in virtio
are not checking the return value.
_vq_record() initializes iov_base pointer using paddr_guest2host()
but there is nothing in the flow that checks for NULL.
Chane _vq_record to return -1 in case the address translation
has failed.

Tracked-On: #5452
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-11-06 15:08:30 +08:00
Sun Peng 73f21a41ad DM: gvt: Identical mapping for GPU DSM
Windows graphic driver obtains DSM address from in-BAR mmio register
which has passthroughed. Not like the other platforms obtained from
pci configure space register which has virtualized. So TGL has to
keep identical mapping to avoid trap mmio BAR to do the emulation.

To keep simple, this patch hardcode the TGL DSM region in vE820
table, this will cause memory waste here. In the near future, we
need refine the entire vE820 logic as it is hard to maintained
due to many reserved regions have introduced in recently.

Signed-off-by: Sun Peng <peng.p.sun@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
Tracked-On: #5461
2020-11-04 11:24:49 +08:00
Liu Long 853a50a2da ACRN:DM:xHCI Fix the unsigned integer conversion bug
When libusb_control_transfer function return a negative number, because
 the function clear_uas_desc's argument is unsigned int this will cause
 unsigned integer conversion.

Tracked-On: #5463
Signed-off-by: Liu Long <long.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-11-04 10:35:38 +08:00
Qian Wang 2fdd1374a9 DM: add vPTCT for post-launched RTVM
dm: vptct: add vPTCT for post-launched RTVM

We added vPTCT support for post-launched RTVM:
1. Added a function create_and_inject_vptct. Currently, we
pass-through the whole pSRAM to one RTVM, so we will also pass-
through the PTCT to the very same RTVM. This function will
read the native PTCT from SOS and inject it into post-
launched VM's vACPI.
2. Added some definitions for vPTCT.

Tracked-On: #5330
Signed-off-by: Qian Wang <qian1.wang@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-11-02 15:56:30 +08:00
Tao Yuhong a371815462 dm: pci uart support create vuart-pci at HV land
If acrn-dm create pci vuart with
'-s,<slot>,uart,vuart_idx:<value>', then acrn-dm will not
create pci uart at DM land, but create an vuart-pci virtual device
at HV land.
When create a HV land vuart-pci vdev, user must specify its vuart id.
Which is defined in vm_config, is the acrn_vm_pci_dev_config.vuart_idx

Tracked-On: #5394
Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-10-30 20:41:34 +08:00
Li Fei1 460124f984 dm: e820: refine e820 layout
We don't reserve PCI MMIO in e820 Table, it's included in DSDT ACPI Table.
About 0xA0000 - 0x100000 entry, we don't have any ACPI Table touch this region.
So we could remove it too.

After this change, we could only pass the reserved e820 table which we must
reserve to OVMF. In this case, the OVMF could trust ACRN-DM and pass the
reserved e820 table to guest instead of dropping it.

This patch needs the corresponding modify in OVMF. Otherwise, the guest could
not boot.

Tracked-On: #4550
Signed-off-by: Li Fei1 <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-10-30 15:45:31 +08:00
Yonghua Huang 30bbfa0d26 dm: confiure msix bar for hv-land ivshmem devices
This patch configures MSIX entry table bar for hv-land ivhsmem devices.

Tracked-On: #5407
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
Reviewed-by: Li, Fei <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2020-10-26 08:44:13 +08:00
Liu Long d85d66141c dm: fix fault Injection into VirtIO console backend
Add Null pointer check in init vq ring and add vq ring descriptor
check in case cause Nullpointer exception.

Tracked-On: #5355
Signed-off-by: Liu Long <long.liu@intel.com>
2020-10-19 11:08:32 +08:00
Liu Long 2c75f3606c dm: fix fault Injection into VirtIO console backend
Add Null pointer check in init vq ring and add vq ring descriptor
 check in case cause Nullpointer exception.

Tracked-On: #5355
Signed-off-by: Liu Long <long.liu@intel.com>
Reviewed-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-27 20:17:23 +08:00
Jie Deng 51d1d6fb12 virtio: add virtio callbacks check
We can only call these callbacks when they are not NULL.

Tracked-On: #5342

Signed-off-by: Jie Deng <jie.deng@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-24 11:41:48 +08:00
Yuan Liu fe722ba085 dm: refine ivshmem usage interface
Change shared memory name prefix from sos to dm
Change shared memory size unit from byte to megabyte

Tracked-On: #4853

Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-15 09:41:43 +08:00
Sun Peng 60df242643 dm: uart: Convert print output to acrn-dm logger
Unifies the logs to pr_* interfaces instead of printf for better log management.

Tracked-On: #5267
Signed-off-by: Sun Peng <peng.p.sun@intel.com>
Reviewed-by: Chi Mingqiang <mingqiang.chi@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-10 09:33:25 +08:00
Sun Peng fd671047ed dm: blockif: Convert print output to acrn-dm logger
Unifies the logs to pr_* interfaces instead of printf for better log management.

Tracked-On: #5267
Signed-off-by: Sun Peng <peng.p.sun@intel.com>
Reviewed-by: Chi Mingqiang <mingqiang.chi@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-10 09:33:25 +08:00
Sun Peng 31a9525fa8 dm: ioc: Convert print output to acrn-dm logger
Unifies the logs to pr_* interfaces instead of printf for better log management.

Tracked-On: #5267
Signed-off-by: Sun Peng <peng.p.sun@intel.com>
Reviewed-by: Chi Mingqiang <mingqiang.chi@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-10 09:33:25 +08:00
Sun Peng c655313abd dm: timer: Convert print output to acrn-dm logger
Unifies the logs to pr_* interfaces instead of printf for better log management.

Tracked-On: #5267
Signed-off-by: Sun Peng <peng.p.sun@intel.com>
Reviewed-by: Chi Mingqiang <mingqiang.chi@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-10 09:33:25 +08:00
Sun Peng 7beed5ca8a dm: tpm: Convert print output to acrn-dm logger
Refine the DPRINTF/WPRINTF to pr_* based log interface for better log management.

Tracked-On: #5267
Signed-off-by: Sun Peng <peng.p.sun@intel.com>
Reviewed-by: Chi Mingqiang <mingqiang.chi@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-10 09:33:25 +08:00
Sun Peng db53212132 dm: rbmp: Convert print output to acrn-dm logger
Refine the DPRINTF/WPRINTF to pr_* based log interface for better log management.

Tracked-On: #5267
Signed-off-by: Sun Peng <peng.p.sun@intel.com>
Reviewed-by: Chi Mingqiang <mingqiang.chi@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-10 09:33:25 +08:00
Sun Peng 3f37fabc2e dm: pci_passthrough: Convert print output to acrn-dm logger
Unifies the logs to pr_* interfaces instead of printf for better log management.

Tracked-On: #5267
Signed-off-by: Sun Peng <peng.p.sun@intel.com>
Reviewed-by: Chi Mingqiang <mingqiang.chi@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-10 09:33:25 +08:00
Sun Peng ac6111080c dm: npk: Convert print output to acrn-dm logger
Unifies the logs to pr_* interfaces instead of printf for better log management.

Tracked-On: #5267
Signed-off-by: Sun Peng <peng.p.sun@intel.com>
Reviewed-by: Chi Mingqiang <mingqiang.chi@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-10 09:33:25 +08:00
Sun Peng 6a3816c289 dm: gvt: Convert print output to acrn-dm logger
Unifies the logs to pr_* interfaces instead of printf for better log management.

Tracked-On: #5267
Signed-off-by: Sun Peng <peng.p.sun@intel.com>
Reviewed-by: Chi Mingqiang <mingqiang.chi@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-10 09:33:25 +08:00
Sun Peng 2a81061aae dm: gsi: Convert print output to acrn-dm logger
Unifies the logs to pr_* interfaces instead of printf for better log management.

Tracked-On: #5267
Signed-off-by: Sun Peng <peng.p.sun@intel.com>
Reviewed-by: Chi Mingqiang <mingqiang.chi@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-10 09:33:25 +08:00
Sun Peng 62c9745765 dm: pci_core: Convert print output to acrn-dm logger
Unifies the logs to pr_* interfaces instead of printf for better log management.

Tracked-On: #5267
Signed-off-by: Sun Peng <peng.p.sun@intel.com>
Reviewed-by: Chi Mingqiang <mingqiang.chi@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-10 09:33:25 +08:00
Sun Peng 72dbac0448 dm: ahci: Convert print output to acrn-dm logger
Unifies the logs to pr_* interfaces instead of printf for better log management.

Tracked-On: #5267
Signed-off-by: Sun Peng <peng.p.sun@intel.com>
Reviewed-by: Chi Mingqiang <mingqiang.chi@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-10 09:33:25 +08:00
Sun Peng 00a739cf32 dm: virtio: Convert console print output to acrn-dm logger
Refine the DPRINTF/WPRINTF to pr_* based log interface instead of printf directly.

Tracked-On: #5267
Signed-off-by: Sun Peng <peng.p.sun@intel.com>
Reviewed-by: Chi Mingqiang <mingqiang.chi@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-10 09:33:25 +08:00
Sun Peng 7414a237b4 dm: mmio: Convert print output to acrn-dm logger
Unifies the logs to pr_* interfaces instead of printf for better log management.

Tracked-On: #5267
Signed-off-by: Sun Peng <peng.p.sun@intel.com>
Reviewed-by: Chi Mingqiang <mingqiang.chi@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-09-10 09:33:25 +08:00
Liu Long c2d85b13d6 DM: xHCI: Add Null pointer check in Set TR Dequeue command
Add Null pointer check in Set TR Dequeue command handle function
 to avoid Null pointer exception. Fllow xHCI spec 4.6.10, for Set
 TR Dequeue pointer command, when the slot is not enabled the
 completion code should be Slot Not Enabled Error.

Tracked-On: #5263
Signed-off-by: Long Liu <long.liu@intel.com>
Acked-by: Yu Wang yu1.wang@intel.com
2020-09-03 13:50:34 +08:00
Liu Long b66e8797fa ACRN: xHCI: Fix Transfer TRBs error transfer handler
According to xHCI Spec 4.10.1 Transfer TRBS chapter, there have three
scenarios shall generate a Transfer Event TRB when transfer TRBS:
1. If upon transfer completion of a TRB the Interrupt On Completion(IOC)
flag is set, the xHC shall generate a Transfer Event TRB.
2. A Short Packet will trigger the generation of a Transfer Event TRB on
the Event Ring if the Interrupt-on-Short (ISP) or Interrupt On Completion
(IOC) flags are set in the TRB that the Short Packet was detected on.
3. The detection of an error during a transfer shall always generate a Transfer
Event, irrespective of whether the Interrupt-on-Short or Interrupt On Completion
(IOC) flags are set in the Transfer TRB.
When an error condition is encountered which requires an endpoint to halt; the xHC
shall stop on the TRB in error, the endpoint shall be halted, and
software shall use a Set TR Dequeue Pointer Command to advance
the Transfer Ring to the next TD.

Tracked-On: #5263
Signed-off-by: Long Liu <long.liu@intel.com>
Acked-by: Yu Wang yu1.wang@intel.com
2020-09-03 13:50:34 +08:00
Yonghua Huang 07ed6841f5 dm:Remove deprecated terms
- remove usages of maste/slave:

Tracked-On: #5249
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
2020-09-01 09:30:08 +08:00
Yuan Liu 91e2fcfecf dm: implement ivshmem inter-vm communication for hv-land
This patch is used to create and destroy an ivshmem device which
is emulated in hypervisor.

Tracked-On: #4853

Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-08-28 16:53:12 +08:00
Yuan Liu 1d084073d6 dm: refine ivshmem creation and destruction
add create_ivshmem_from_dm and destroy_ivshmem_from_dm for
ivshmem device creation and destruction in dm-land

Tracked-On: #4853

Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-08-28 16:53:12 +08:00
Long Liu 03fdb297d6 DM: xHCI: Implement reset/stop endpiont error handler
Add Null pointer check in reset and stop endpoint command handle
function to avoid Null pointer exception. Fllow xHCI spec 4.6.8 and
4.6.9, for stop and reset endpoint command, when the slot state is
Disabled the error code should be Slot Not Enabled Error, when the
slot have been enabled by an Enable Slot Command the error code should
be Context State Error.

Tracked-On: #5066
Signed-off-by: Long Liu <long.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>

Signed-off-by: Long Liu <long.liu@intel.com>
2020-07-23 21:55:21 +08:00
Li Fei1 f13d5c25b6 dm: mmio_dev: add mmio device pass through support
We could add MMIO device pass through by two ways:
a) If the MMIO device only has MMIO regions and no ACPI Table touched, using
"--mmiodev_pt MMIO_regions",
b) If the MMIO device touches ACPI Table, using "--acpidev_pt HID"

Now only support TPM2 MSFT0101 MMIO device pass through through launch script
using "--acpidev_pt MSFT0101". When we want to pass through the TPM2 deivce,
we would not allow to emulate the vTPM2 at the same time. This is becuase
the ACRN-DM emulate the TPM2 as MSFT0101 too. Otherwise, the VM can't boot.

Besides, we could only support one TPM2 device PT and one MMIO device PT.
For TPM2 device PT, the MMIO resources are hard-coded. For the MMIO device PT,
we could pass through the MMIO resources on the cmdline.

ToDo:
1. We may use HID to discover the MMIO regions and ACPI Table instaed of
hard-coded.
2. To identify a MMIO device only by MMIO regions.
3. To allocate virtual MMIO regions in a reserved guest MMIO regions.

Tracked-On: #5053
Signed-off-by: Li Fei1 <fei1.li@intel.com>
2020-07-23 20:13:20 +08:00
Long Liu 4b03f3002e DM: PT: Add "d3hot_reset" sub-parameter for passthrough device
Some passthrough devices have no reset mechanisms which cause the device stay
in unknown status during boot/reboot flow. And such unknown status cause
unexpected behaviors in the guest. Except the ordinary reset mechanisms
like FLR, we can utilize enter/exit D3cold as the reset that D3cold will
power gate the entire hardware. But the D3cold is implemented as ACPI
method which has no user interface in the SOS side. But the D3cold is
implemented as ACPI method which has no user interface in the SOS side.
But base on our experience, some devices can utilize D3hot instead of
D3cold. But it is not useful for all PCI devices as the power status
of D3hot is implementation defined.
Provide one new API to program PowerState(D0/D1/D2/D3hot) in PMCSR
register.
Add "d3hot_reset" sub-parameter for passthrough device to enable utilize
enter/exit D3hot flow to implement reset mechanisms.

Tracked-On: #5067

Signed-off-by: Long Liu <long.liu@intel.com>
Reviewed-by: Yuan Liu <yuan1.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2020-07-23 10:10:27 +08:00
Long Liu 312ea0b374 DM: xHCI: Release all device resource when received HCRST.
There has one bug that the pci_xhci_dev_emu objects recorded in
xdev->devices haven't destroy when OVMF transfer to guest OS.
This will cause the the fds of usbfs can't be freed in libusb.
The OVMF xHCI driver needs to disable all enabled slots during
graceful existing flow, but it doesn't.
The USBCMD.HCRST bit is used for xHC reset that will be triggered
in xHCI driver initialization. We can use this chance to clear
all pci_xhci_dev_emu objects

Tracked-On: #4897
Signed-off-by: Long Liu <long.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2020-07-22 12:54:37 +08:00
Sun Peng e677f9413b dm: Increase OpRegion size for bigger VBT
OpRegion: 8KB(0x2000)
[ OpRegion Header      ] Offset: 0x0
[ Mailbox #1: ACPI     ] Offset: 0x100
[ Mailbox #2: SWSCI    ] Offset: 0x200
[ Mailbox #3: ASLE     ] Offset: 0x300
[ Mailbox #4: VBT      ] Offset: 0x400
[ Mailbox #5: ASLE EXT ] Offset: 0x1C00
Extended OpRegion: 8KB(0x2000)
[ Raw VBT              ] Offset: 0x0

Generally VBT stores in MailBox4 in OpRegion which max size is 6KB.
If VBT larger than 6KB, it will be stored in extended OpRegion which
is neighborhood with legacy OpRegion. In this case, we need to
passthrough extended OpRegion also to support GVT-d feature. The
OpRegion size that we passthrough should be (OpRegion+Extended)=16KB
ASLE.rvda stores the location of VBT.
For OpRegion 2.1+: ASLE.rvda = offset to OpRegion base address
For OpRegion 2.0:  ASLE.rvda = physical address

To-do: Add support for OpRegion on some platforms(eg. APL)

Tracked-On: #5029
Signed-off-by: Sun Peng <peng.p.sun@intel.com>
2020-07-15 16:13:03 +08:00
Long Liu f9c44369a0 DM USB: xHCI: Fix XHCI_GET_SLOT value check issue
Fix XHCI_GET_SLOT macro check slot valid function, when the
slot value is bigger than XHCI_MAX_SLOT set the slot value
to zero.

Tracked-On: #4711

Signed-off-by: Long Liu <long.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2020-07-15 10:34:53 +08:00
Vijay Dhanraj 3c9469d98a DM: Add macvtap support to virtio-net
This patch does the following,
1. Fix an explicit interface name check for tapX preventing
any other interface name like kata_tap to be setup.
2. Add support for macvtap interface.
3. Identify macvtap vs tap interface and
if it is macvtap, identify character device (/dev/tapXX)
to be used.

Tracked-On: #4945
Signed-off-by: Vijay Dhanraj <vijay.dhanraj@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2020-07-14 13:02:21 +08:00
Li Fei1 80c7da8f1c hv: vioapic: expose ioapic to guest unconditionally
Some OSes assume the platform must have the IOAPIC. For example:
Linux Kernel allocates IRQ force from GSI (0 if there's no PIC and IOAPIC) on x86.
And it thinks IRQ 0 is an architecture special IRQ, not for device driver. As a
result, the device driver may goes wrong if the allocated IRQ is 0 for RTVM.

This patch expose vIOAPIC to RTVM with LAPIC passthru even though the RTVM can't
use IOAPIC, it servers as a place holder to fullfil the guest assumption.

After vIOAPIC has exposed to guest unconditionally, the 'ready' field could be
removed since we do vIOAPIC initialization for each guest.

Tracked-On: #4691
Signed-off-by: Li Fei1 <fei1.li@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2020-07-10 19:33:46 +08:00
Sun Peng 6edd21c1dc dm: Data Stolen Memory (DSM) passthrough support for GVT-d on TGL
The way of passing DSM address on TGL is the same with on EHL.
Adding these code to support GVT-d on TGL.

Tracked-On: #5020
Signed-off-by: Sun Peng <peng.p.sun@intel.com>
Acked-by: Yu Wang yu1.wang@intel.com
2020-07-08 13:19:05 +08:00
Yuan Liu c8891cb670 dm: fixed an issue that VM can't communicate with peer after rebooting/shutdown
Due to there is no inter-vm communication shared memory management
module, so each acrn-dm will call shm_unlink when VM rebooting/shutdown.
It causes one issue that if one of the two VMs is rebooting/shutdown,
the VM can't communicate with the peer again.

Currently, we don't release the shared memory to fix this issue.

Tracked-On: #4853
Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-06-18 14:07:34 +08:00
Binbin Wu 417ce1b32d dm: passthru: add support to allocate a bar for vmsix on msi emulation
New option "vmsix_on_msi,<bar_id>" is added to specify the passthrough
device needs vMSI-X emulation based on MSI capability.
If vMSI-X on MSI emulation is needed, a virtual BAR will be allocated.

Also, fix a logic error on when to setup INTx.

Tracked-On: #4831
Signed-off-by: Binbin Wu <binbin.wu@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2020-06-16 08:52:56 +08:00
Binbin Wu 68b5616a52 dm: passthru: add acpi support for tsn devices
Add needed ACPI tables for TSN device.

Tracked-On: #4831
Signed-off-by: Binbin Wu <binbin.wu@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2020-06-16 08:52:56 +08:00
Long Liu 1672eca2b9 DM USB: xHCI: Drop commands if slot is disabled
From xHCI spec 4.5.3.2, the only command that software is
allowed to issue for the slot in disabled state is the Enable
Slot Command. Drop other commands in command handle function.

Tracked-On: #4711
Signed-off-by: Long Liu <long.liu@intel.com>
Reviewed-by: Yuan Liu <yuan1.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2020-06-05 15:31:05 +08:00
Yuan Liu aeae464980 Implement creation and removal of inter-vm shared memory
The shared memory will be created when a post-launched VM which
specified ivshmem v1 device starts, the same shared memory name
will only create a shared memory region.

The shared memory will be removed when all post-launched VMs
that opened it close the shared memory object.

v2: Support one post-launched VM can configure multiple ivshmem
    devices

Tracked-On: #4853
Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2020-05-29 09:28:24 +08:00
Yuan Liu cb816f7f65 Introduce ACRN Inter-VM Virtualization
Support shared memory based inter-vm communication for ACRN
post-launched VMs. The ivshmem mediator emulates one standard
PCI device which expose the shared memory region through its BAR2.
The shared memory region is allocated through Linux shm mechanism and
post-launched VM needs to specify the shm name and size as the acrn-dm
parameter, the VMs have same shm name parameter can communicate over
the shared memory.

For first stage, only support shared memory. Consider to support
notification(interrupt) in future.

To add a ivshmem device in device model, the usage as below
-s N,ivshmem,shm_name,shm_size

v2: Implement the ivshmem MMIO registers emulation

v3: Refine code style
    Add ivshmem device usage
    Refine MMIO register return value

v4: Refine comments
    Use logger interfaces to print logs

Tracked-On: #4853
Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2020-05-29 09:28:24 +08:00
Helmut Buchsbaum 884e9fc911 Revert "dm: acpi: add PSDS table in ACPI table"
This reverts commit 59e2de4805.

Since PSDS table format does not meet the expectations on all boards
providing a PSDS, such as e.g. Kontron COMe-mAL10 based boards, remove
exposure of PSDS table for now.

Tracked-On: #4846
Signed-off-by: Helmut Buchsbaum <helmut.buchsbaum@opensource.tttech-industrial.com>
2020-05-29 09:03:52 +08:00
Zhao Yakui 6c02a8d5ed ACRN/DM: Initialize the igd_lpc bridge to ISA_BRIDGE to make Linux guest happy
Currently the class type of igd_lpc bridge PCI device is not initialized.
In such case the guest driver doesn't detect the platform correctly when it
is in GVT-d mode. Then the linux i915 driver can't work.

Tracked-On: #4745
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Binbin Wu <binbin.wu@intel.com>
2020-05-25 11:08:25 +08:00
Zhao Yakui bca83efee8 ACRN/DM: Reset the passthrough device to fix garbage display issue
Currently the DM will return the passthrough device to SOS when the DM
needs to be terminated. But the device is not reset. In such case it
will cause the garbage display issue when the GPU passthrough device
is returned.

Tracked-On: #4719
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Binbin Wu <binbin.wu@intel.com>
2020-05-25 11:08:25 +08:00
Mingqiang Chi 4d3221a7f3 acrn-dm: add some logs for vm state transition
add logs for vm state transition to help
analyze some problems.

Tracked-On: #4098
Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
2020-05-15 10:06:23 +08:00
Junming Liu 1da7e4145f dm:refine graphics data stolen memory passthru for EHL platform
EHL graphics data stolen memory(DSM) info has diff with KBL/WHL,
which includes two parts:
(1) DSM register location in pci config: on KBL/WHL, the register
locates on 0X5C, while on EHL, the register locates on 0xC0.
(2) DSM address length: On KBL/WHL,
DSM addr has 32 bits, while on EHL,DSM addr has 64 bits.

Here, refine graphics data stolen memory passthru to enable GVT-d on EHL platforms.

v3 -> v4:
        * add MICRO INTEL_ELKHARTLAKE
v2 -> v3:
	* refine discription,MICRO name
	* refine code style
v1 -> v2:
	* add callback functions for scalability

Tracked-On: projectacrn#4700

Signed-off-by: Junming Liu <junming.liu@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Liu XinYun <xinyun.liu@intel.com>
Reviewed-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2020-04-24 12:54:50 +08:00
Junming Liu 795225d55e dm:add function passthru_gpu_dsm_opregion for passthru_init
Pack GPU DSM(Data Stolen Memory) and Opregion related operations
into function passthru_gpu_dsm_opregion to avoid passthru_init too mess.

Tracked-On: #4700

Signed-off-by: Junming Liu <junming.liu@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Liu XinYun <xinyun.liu@intel.com>
Reviewed-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2020-04-24 12:54:50 +08:00
Junming Liu b45c24b062 dm:refine comments and variables name about data stolen memory
"gsm" term is not precise to describe GPU stolen memory,
It should be "dsm", which acronyms for data stolen memory.

Tracked-On: #4700

Signed-off-by: Junming Liu <junming.liu@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Liu XinYun <xinyun.liu@intel.com>
Reviewed-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2020-04-24 12:54:50 +08:00
Junming Liu 86aa338a5f dm: correct PCI configures of igd-lpc
previous patch fails to align SUBVID, SUBDID of igd-lpc with physical one.
this patch corrects the errors and refine the code.

Tracked-On: #4405

Signed-off-by: Junming Liu <junming.liu@intel.com>
Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-03-30 10:06:20 +08:00
Li Fei1 e99ddf28c3 hv: vpci: handle the quirk part for pass through pci device cfg access in dm
There're some PCI devices need special handler for vendor-specical feature or
capability CFG access. The Intel GPU is one of them. In order to keep the ACRN-HV
clean, we want to throw the qurik part of PCI CFG asccess to DM to handle.

To achieve this, we implement per-device policy base on whether it needs quirk handler
for a VM: each device could configure as "quirk pass through device" or not. For a
"quirk pass through device", we will handle the general part in HV and the quirk part
in DM. For a non "quirk pass through device",  we will handle all the part in HV.

Tracked-On: #4371
Signed-off-by: Li Fei1 <fei1.li@intel.com>
2020-03-20 10:08:43 +08:00
Li Fei1 fa74bf401d hv: vpci: pass through stolen memory and opregion memory for GVT-D
In order to add GVT-D support, we need pass through stolen memory and opregion memroy
to the post-launched VM. To implement this, we first reserve the GPA for stolen memory
and opregion memory through post-launched VM e820 table. Then we would build EPT mapping
between the GPA and the stolen memory and opregion memory real HPA. The last, we need to
return the GPA to post-launched VM if it wants to read the stolen memory and opregion
memory address and prevent post-launched VM to write the stolen memory and opregion memory
address register for now.
We do the GPA reserve and GPA to HPA EPT mapping in ACRN-DM and the stolen memory and
opregion memory CFG space register access emulation in ACRN-HV.

Tracked-On: #4371
Signed-off-by: Li Fei1 <fei1.li@intel.com>
2020-03-11 10:59:23 +08:00
Li Fei1 64bf4fb8f4 dm: don't deassign pass through PCIe device in DM
Let the ACRN HV to do this in shutdown sequence. In this case, the RTVM could be
still alive if something wrong happened to cause the DM died.

Tracked-On: #4428
Signed-off-by: Li Fei1 <fei1.li@intel.com>
2020-03-06 08:30:59 +08:00
Li Fei1 be1e3acb01 dm: remove vdev_update_bar_map callback for PCIe device
Since this callback is only useful for pass through PCIe device and now pass through
PCIe device emulation has splited from DM to HV. we could remove this callback now.

Tracked-On: #4371
Signed-off-by: Li Fei1 <fei1.li@intel.com>
2020-03-02 16:42:17 +08:00
Li Fei1 9d3d9c3d1e dm: vpci: restrict SOS access assigned PCI device
SOS should not access the physical PCI device which is assigned to other guest.

Tracked-On: #4371
Signed-off-by: Li Fei1 <fei1.li@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2020-02-24 16:17:38 +08:00
Li Fei1 9fa6eff3c5 dm: vPCI: remove passthrough PCI device unused code
Now we split passthrough PCI device from DM to HV, we could remove all the passthrough
PCI device unused code.

Tracked-On: #4371
Signed-off-by: Li Fei1 <fei1.li@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2020-02-24 16:17:38 +08:00
Li Fei1 dafa3da693 vPCI: split passthrough PCI device from DM to HV
In this case, we could handle all the passthrough PCI devices in ACRN hypervisor.
But we still need DM to initialize BAR resources and Intx for passthrough PCI
device for post-launched VM since these informations should been filled into
ACPI tables. So
1. we add a HC vm_assign_pcidev to pass the extra informations to replace the old
vm_assign_ptdev.
2. we saso remove HC vm_set_ptdev_msix_info since it could been setted by the post-launched
VM now same as SOS.
3. remove vm_map_ptdev_mmio call for PTDev in DM since ACRN hypervisor will handle these
BAR access.
4. the most important thing is to trap PCI configure space access for PTDev in HV for
post-launched VM and bypass the virtual PCI device configure space access to DM.

This patch doesn't do the clean work. Will do it in the next patch.

Tracked-On: #4371
Signed-off-by: Li Fei1 <fei1.li@intel.com>
2020-02-24 16:17:38 +08:00
Junming Liu 0829edee4c dm:add an extra lpc bridge when enabling gvt-d
Intel Graphics Device(IGD) passthrough on Windows guest
has the restriction that it need a lpc bridge device
located in 00:1f.0 PCI slot.

This patch add a 'gpu' option for 'passthrou' type device,
which will create the dedicated "igd-lpc" for IGD passthrough.

Tracked-On: #4405

v2 -> v3:
        * refine the commit message and comments.

Signed-off-by: Junming Liu <junming.liu@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Reviewed-by: Wu Binbin <binbin.wu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-02-24 11:47:10 +08:00
Junming Liu da2ed57ac4 dm:add igd-lpc class for Windows guest when enabling gvt-d
Intel Graphics Device(IGD) passthrough on Windows guest
has the restriction that it need a lpc bridge device
located in 00:1f.0 PCI slot.
This patch add an extra lpc class for this restriction,
the lpc class will be used to create a dummy lpc bridge.

To enable gvt-d GOP driver work,
the VID, DID, REVID, SUBVID, SUBDID of igd-lpc
need aligned with physical one.

Tracked-On: #4405

v2 -> v3:
        * refine the comment message and comments.

Signed-off-by: Junming Liu <junming.liu@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Reviewed-by: Wu Binbin <binbin.wu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2020-02-24 11:47:10 +08:00
Junming Liu 1b3754aaee dm:passthrough opregion to uos gpu
uos IGD driver need opregion when enable GVT-d.

This patch pass-thru opregion to uos gpu.
Here is the steps:
(1) set opregion gpa(guest physical addrress) 0xDFFFD000;
(2) get opregion hpa(host physical addrress);
(3) build EPT mapping for opregion.

v1 -> v2:
        * initialize the EPT mapping for passthrough GPU opregion region
        in passthru_init instead of reading the ASLS config space

v2 -> v3:
        * add EPT unmap when deinit
        * change some micro name

Tracked-On: #4360

Signed-off-by: Junming Liu <junming.liu@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Liu XinYun <xinyun.liu@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Reviewed-by: Wu Binbin <binbin.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2020-01-17 09:23:13 +08:00
Junming Liu 4d882731ce dm:passthrough graphics stolen memory to uos gpu
gop driver and uos IGD driver will use
graphics stolen memory(gsm) when enable GVT-d.

This patch pass-thru gsm to uos gpu.

After set physical GPU gsm size 64MB in host BIOS:
Here is the steps:
(1) set gsm gpa(guest physical addrress) 0xDB000000;
(2) get gsm hpa(host physical addrress);
(3) build EPT mapping for gsm.

v1 -> v2:
        * initialize the EPT mapping for passthrough GPU gsm region
        in passthru_init instead of reading the BDSM config space

v2 -> v3:
        * add EPT unmap when deinit
	* change some micro name

Tracked-On: #4360

Signed-off-by: Junming Liu <junming.liu@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Liu XinYun <xinyun.liu@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Reviewed-by: Wu Binbin <binbin.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2020-01-17 09:23:13 +08:00
Junming Liu 03f5c639a0 dm:derive the prefetch property of PCI bar for pass-through device
Now the PCI bar uses the hardcoded prefetch property
for the pass-through device.
This doesn't work when trying to load windows GPU driver
for the pass-through GPU device.

For pass-through devices,
set the bar prefetchable property the same as physical bar.

Tracked-On: #4282

Signed-off-by: Junming Liu <junming.liu@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2020-01-13 16:47:25 +08:00
Junming Liu ceb197c993 dm:keep pci bar property unchanged when updating pci bar address
When update pci bar addr,
DM may change the bar property by func pci_cfgrw.
PCI spec chapter 'Base Addresses' shows
bits 0~3 are readonly of memeory space BAR,
so this change won't happen.

This patch ensures pci bar property unchanged
when update pci bar addr.

Tracked-On: #4282

Signed-off-by: Junming Liu <junming.liu@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2020-01-13 16:47:25 +08:00
Mingqiang Chi 5267a9775c dm:replace perror with pr_err
use acrn-dm logger function instread of perror,
this helps the stability testing log capture.

Tracked-On: #4098
Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
2020-01-08 13:37:57 +08:00
Li Fei1 933e2178d0 dm: pci: reset passthrough device by default
Do reset for passthrough PCI device by default when assigning it to post-launched
VM:
1. modify opt "reset" to "no_reset" -- could enable no_reset for debug only
2. remove "ptdev_no_reset" opt. It could be replaced by setting "no_reset" for
each passthrough device.

Tracked-On: #3465
Signed-off-by: Li Fei1 <fei1.li@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-12-30 13:43:07 +08:00
Junming Liu f2bf3d3ed1 dm:gvt:update bus0 memlimit32 value
Now the GVT already tries to reserve the region.
the problem is that the region should be
reflected in PCI BUS0 memlimit32 and updated to DSDT table.

As the GVT PCI bar0/2 is in reserved region
and not updated to memlimit32 in DSDT table,
the problem is triggered.

Tracked-On: projectacrn#4227

Signed-off-by: Junming Liu <junming.liu@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
2019-12-12 09:04:30 +08:00
Junming Liu 2f642002fc dm:gvt:enable gvt bar registration
Need to enable gvt bar registration, so remove the previous workaround patch.

Tracked-On: projectacrn#4005

Signed-off-by: Junming Liu <junming.liu@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Liu XinYun <xinyun.liu@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-12-05 11:20:11 +08:00
Junming Liu 89908bf510 dm:gvt:update gvt bars before other pci devices write bar address
The current design has the following problem:
uos kernel may update gvt bars' regions,
but ACRN-DM doesn't know this update.
ACRN-DM only know out-of-date gvt bar regions,
For simplicity, mark these bar regions as OOD bar regions.
uos kernel may allocate OOD bar regions for
other pci devices, which will result in ACRN-DM
bar regions inconsistency with uos kernel.

The new design is the following:
When other pci device update bar regions
(1) ACRN-DM updates gvt bars' regions
provided by a system file.
(2) ACRN-DM updates this pci device bar regions

v5 -> v6:
	* add more comments

v4 -> v5:
	* remove & for callback func assignment

v3 -> v4:
	* compare gpu bar address to avoid unnecessary
	* unregistered/registered operation

v2 -> v3:
	* call unregister_bar and register_bar when update gvt bars
	* update gvt reserved regions when update gvt bars

Tracked-On: projectacrn#4005

Signed-off-by: Junming Liu <junming.liu@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Liu XinYun <xinyun.liu@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-12-05 11:20:11 +08:00
Junming Liu f27d47542a dm:gvt:adjust pci bar region with reserved bar regions
ACRN-DM has reserved gvt bar regions.

This patch ensures other pci devices' bar regions
won't overlap with reserved bar regions.

v6 -> v7:
	* rename some struct and func

v5 -> v6:
	* remove outdated comment
	* add comments for code reading
	* code cleaning about gvt bar0 and bar2 size

v4 -> v5:
	* rename adjust_bar_region and adjust_bar_region_by_gvt_bars
	* change adjust_bar_region_by_gvt_bars interface for code cleaning

v3 -> v4:
	* add static struct gvt_region  instead of definition or pointer array.

v2 -> v3:
	* repalce pci_emul_alloc_bar with gvt_reserve_resource when allocate gvt bars
	* use register_bar to detect if gvt bars confilts with pci devices

v1 -> v2:
	* don't limit the gvt bar type is MEM32 when deal with pci bar
	* add is_two_region_overlap func to detect if two regions overlap
	* add region array to store gvt bar0 and bar2 regions

Tracked-On: projectacrn#4005

Signed-off-by: Junming Liu <junming.liu@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Liu XinYun <xinyun.liu@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-12-05 11:20:11 +08:00
Junming Liu 1ac0b57c6a dm:gvt:reserve gvt bar regions in ACRN-DM
The current design has the following problem:
gvt uses some pci bar regions,
but ACRN-DM isn't aware of these regions.
So ACRN-DM may allocate these regions for other pci devices,
which will result in other pci devices bar regions
overlap with gvt bar regions.

The new design is the following:
(1) ACRN-DM reads gvt bar regions
which are provided by physical gpu;
(2) ACRN-DM reserves gvt bar regions

v6 -> v7:
	* use array to store reserved bar regions
	* rename some struct and func

v5 -> v6:
	* rename enable_gvt to gvt_enabled
	* add a interface to reserve bar regions
	* reserve gvt bar regions

Tracked-On: projectacrn#4005

Signed-off-by: Junming Liu <junming.liu@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Liu XinYun <xinyun.liu@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-12-05 11:20:11 +08:00
Junhao Gao 058b03c3a7 dm: fix memory free issue for xhci
remove uninitialized variable "dir", then make sure
"xfer->data","xfer->data[i].hcb","xfer->reqs" free correctly.

Tracked-On: #4154
Signed-off-by: Junhao Gao <junhao.gao@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-11-27 10:22:27 +08:00
Mingqiang Chi a59205f6a2 dm:use acrn-dm logger function instread of fprintf
use acrn-dm logger function instread of fprintf,
this helps the stability testing log capture.

Tracked-On: #4098
Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
Reviewed-by: Cao Minggui <minggui.cao@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
2019-11-14 15:34:04 +08:00
Mingqiang Chi 5375a1613b dm:use acrn-dm logger function instread of printf
Use acrn-dm logger function instread of printf,
this helps the stability testing log capture.

Tracked-On: #4098
Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
Reviewed-by: Cao Minggui <minggui.cao@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
2019-11-14 15:34:04 +08:00
Binbin Wu dea2e25f41 dm: hw: fix the license of cmos_io.c
Fix the license of cmos_io.c to BSD-3-Clause

Tracked-On: #4032
Signed-off-by: Binbin Wu <binbin.wu@intel.com>
2019-11-08 16:42:54 +08:00
Gao Junhao 90cf27aa5f dm: remove cfc/cf8 pio handler
The acrn vhm driver will convert all PCI configure space access to
PCI_CFG type, so the pci_emul_cfgaddr and pci_emul_cfgdata will nerver
be invoked. Remove these useless functions.

Tracked-On: #3999
Signed-off-by: Gao Junhao <junhao.gao@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-11-05 16:07:38 +08:00
Gao Junhao 9143e56336 dm: update ACPI with latest ASL standard
The device model generating ACPI table use the old ASL
standard(version:20190816), then the iasl in clearlinux(version:31360)
is 20191018, it can't disassemble the ACPI table compiled by old
standard.

Tracked-On: #3933
Signed-off-by: Gao Junhao <junhao.gao@intel.com>
Reviewed-by: Fengwei Yin <fengwei.yin@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-10-25 15:12:00 +08:00
Yonghua Huang e7ef57a9f1 dm: fix mutex lock issue in tpm_rbc.c
In function crb_reg_write() in tpm_rbc.c
 'tpm_vdev->request_mutex' will potentially kept
 in locked state after crb_reg_write() returns.

Tracked-On: #3825
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
Reviewed-by: Yadong Qi <yadong.qi@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-10-18 15:36:18 +08:00
Gao Junhao 43b2327eb8 dm: validation for input to public functions
slot value should be checked in range before used to access
bi->slotinfo[].

Tracked-On: #3822
Signed-off-by: Gao Junhao <junhao.gao@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-10-16 10:26:50 +08:00
Gao Junhao 477f8331eb dm: modify DIR handler reference postion
DIR handler is referenced after release, need to be adjusted before
released.

Tracked-On: #3821
Signed-off-by: Gao Junhao <junhao.gao@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-10-16 10:26:23 +08:00
Junhao Gao 72232daafe dm: reduce potential crash caused by LIST_FOREACH
When removing node in list, list_foreach_safe will be safer than
LIST_FOREACH.

Tracked-On: #3778
Signed-off-by: Junhao Gao <junhao.gao@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-10-15 14:37:39 +08:00
Gao Junhao e6e0e27788 dm: refine the check of return value of snprintf
int snprintf(char *str, size_t size, const char *format, ...)
The functions snprintf() write at most size bytes (including the
terminating null byte('\0')) to str.
only when returned value of snprintf is non-negative and less than size,
the string has been completely written.

Tracked-On: #3789
Signed-off-by: Junhao Gao <junhao.gao@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-10-15 13:53:58 +08:00
Yuan Liu a4d562daa0 dm: Add Oracle subsystem vendor ID
After Windows 10, version 1607, the cross-signed drivers are forbiden
to load when secure boot is enabled.

Details please refer to
https://docs.microsoft.com/en-us/windows-hardware/drivers/install/kernel-mode-code-signing-policy--windows-vista-and-later-

That means the kvm-guest-drivers-windows can't work when secure boot enabled.
So we found another windows virtio FE drivers from Oracle to resolve this issue
but have to change another subsystem vendor ID for the virtio BE services.

This patch introduces a new DM CMD line "--windows" to launch WaaG with Oracle virtio devices including
virtio-blk, virtio-net, virtio-input instead Redhat. It can make virtio-blk, virtio-net and virtio-input
devices work when WaaG enabling secure boot.

Tracked-On: #3583
Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Reviewed-by: Eddie Dong <eddie.dong@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2019-10-11 13:20:19 +08:00
Xiaoguang Wu 11f4a7267b DM USB: xHCI: support multiple ERST
This patch is used to support multiple Event Ring Segment Table (ERST).

Tracked-On: #3628
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-09-26 11:29:22 +08:00
Xiaoguang Wu 52c17d634a DM USB: xHCI: rename some variables about ERST
This patch only changes some names of varaibles about Event Ring Segement
Table (ERST), and doesn't modify any code logic.

Tracked-On: #3628
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-09-26 11:29:22 +08:00
Xiaoguang Wu e9211514e7 DM USB: modify disconnecting logic to support Windows 10
The Windows 10 feeds back quicker than Linux OS when error occured
due to device disconnecting, it will quickly reset the xHCI controller
before the DM starts to emulate disconnect event and it may cause some
unexpected errors such as crash.

This patch will do one more check when error happens, if the error
is induced by device disconnecting, the DM will not report error and
just wait until the disconnect event is reported to the guest. This
change could produce the correct hehavior as we expected.

Tracked-On: #3628
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-09-26 11:29:22 +08:00
Xiaoguang Wu 06781b37e9 DM USB: dynamically allocate block count for struct usb_xfer
The block count of the struct usb_xfer is hard coded by the macro
USB_MAX_XFER_BLOCKS (1024), it wastes memory if 1024 blocks are
allocated for low speed transfer such as control transfer or interrupt
transfer. This patch introduces a new method to allocate different
number of blocks according to different endpoint type.

Tracked-On: #3628
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-09-26 11:29:22 +08:00
Xiaoguang Wu f1b142e6e0 DM USB: xHCI: implement the emulation for overrun and underrun event
The overrun and underrun event are used in the timing control machanism,
this patch is used to implement this feature.

Tracked-On: #3628
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-09-26 11:29:22 +08:00
Xiaoguang Wu 7cb45bc968 DM USB: xHCI: refine the emulation logic for BEI bit in the TRB
The Block Event Interrupt (BEI) bit in the TRB descriptor could
delay the triggering of interrupt. For most OSes, the native
driver for xHCI will use this bit to optimize the IO performence,
due to reduction of number of interrupts.

But in Linux, the native xHCI driver for Intel brand controller
doesn't use this bit. It is fine for the native scenario due to
most work is completed by hardware. But in virtualization scenario,
it is almost impossible to support heavy data IO such as high
resolution video recording (ISOC transfer).

Hence, this issue is solved by a 'quirk' when the intel hardware is
emulated (when vendor id is set as 0x8086). For other cases, a
virtal hardware called 'ACRN xHCI' is emulated, and both Linux and
Windows will use BEI bit by default.

Tracked-On: #3628
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-09-26 11:29:22 +08:00
Xiaoguang Wu 685b1a7b66 DM USB: xHCI: fix emulation code for MFINDEX register
The old logic to emulate MFINDEX register is not right, this patch
is used to fix it.

Tracked-On: #3628
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-09-26 11:29:22 +08:00
Xiaoguang Wu bda43ee352 DM USB: xHCI: rename the variable mf_prev_time
Just changed the name of the variable and didn't change any emulation
code logic.

Tracked-On: #3628
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-09-26 11:29:22 +08:00
Xiaoguang Wu 8949a5802a DM USB: introduce struct xhci_block for xHCI emulation
In the struct usb_block, there are some fields such as 'ccs',
'streamid', which should not be seen in the USB layer. This
patch intruduces new struct xhci_block to include the variables
for xHCI emulation.

Tracked-On: #3628
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-09-26 11:29:22 +08:00
Xiaoguang Wu 0110465416 DM USB: code clean: remove redundent code
When control transfer is detected and an unnecessary reset of
struct usb_xfer is conducted. This behavior is not necessary
and this patch is used to remove it.

Tracked-On: #3628
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-09-26 11:29:22 +08:00
Xiaoguang Wu 1352eca224 DM USB: introduce helper functions: index_inc and index_valid
Introduce helper functions to make code shorter and cleaner.

Tracked-On: #3628
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-09-26 11:29:22 +08:00
Xiaoguang Wu d58a766556 DM USB: re-implement the data block process logic
In Windows OS, there are many non-data blocks (EVENT DATA) during the USB
data transfer process, which is very different from the Linux conterpart.
To support both OS, the data processing logic is changed with the help of
newly introduced enum usb_block_type.

Tracked-On: #3628
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-09-26 11:29:22 +08:00
Xiaoguang Wu 236c23e418 DM USB: introduce enum type usb_block_type
In the process of USB data transfer, there three kinds of data blocks:
a. Non data block, which contains some control information;
b. Partial data block, which contains part of a large data chunk;
c. Full data block, which contains a complete data chunk.

In previous implementation, the differences mentioned above are described
by the usb_block::chained. But the 'chained' is concept in the xHCI area
and should not appear in the USB layer. This patch introduces enum type
usb_block_type to replace the 'chained' field in struct usb_block.

Tracked-On: #3628
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-09-26 11:29:22 +08:00
Xiaoguang Wu 7445e404a8 DM USB: code clean: change some names of functions and variables
Some names of functions and variables are long and not exact, this
patch is used to change them, no logic code are affected. The
changing included:

usb_data_xfer -> usb_xfer
usb_data_xfer_block -> usb_block
usb_xfer_blk_stat -> usb_block_stat
usb_data_xfer_append -> usb_block_append
USB_XFER_BLK_* -> USB_BLOCK_*

Tracked-On: #3628
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-09-26 11:29:22 +08:00
Minggui Cao 00401a1e78 DM: separate pty vuart operation from IOC
for pty vuart operation will be commonly used by other module,
like pm-vuart: control UOS power off through vuart.

Tracked-On: #3564
Signed-off-by: Minggui Cao <minggui.cao@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2019-09-11 16:43:22 +08:00
Xiaoguang Wu be0a4b692b DM USB: fix enumeration related issues
The patch fixes enumeration related issues introduced by commit 'fc3d19'.

Tracked-On: #3612
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-09-03 12:22:46 +08:00
Conghui Chen 2d57c5feb7 dm: virtio-console: add subclass
Add subclass for virtio-console pci device. Without the subclass, the
device may be probed by 8250_pci serial driver,  and lead to segment
fault in acrn-dm. This issue appears when running debian as Guest OS.

But there is a potential issue, if a new serial driver, which use class
and subclass same as virtio-console, the problem may still trigger. Need
to fix it case by case.

Tracked-On: #3615
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2019-08-27 09:47:00 +08:00
Xiaoguang Wu fc3d19bee4 DM USB: fix potential crash risk due to null pointer
Fix potential risk to crash due to null pointer.

Tracked-On: #3612
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-08-26 14:17:49 +08:00
Junming Liu 4dfd5d6ae6 dm:gvt:keep LaaG aperture size consistent with the host
Keep LaaG aperture size consistent with the host bios setting,
if we statically set LaaG aperture 256MB,
it may not have memory space for LaaG aperture.
We get host aperture size from cfg port 0x62.

Tracked-On: #3537
Signed-off-by: Junming Liu <junming.liu@intel.com>
Reviewed-by: Xinyun Liu <xinyun.liu@intel.com>
2019-08-09 10:29:42 +08:00
Yifan Luo 50e0a932a2 dm: virtio-i2c: fix native_adapter memory leak
If failed to create native_adapter, free allocated native_adapter memory before return.

Tracked-On: #3543
Signed-off-by: Yifan Luo <luoyifan@cmss.chinamobile.com>
2019-08-08 10:36:46 +08:00
Xiaoguang Wu e188e1f245 DM USB: xHCI: fix an error in PORTSC emulation
When DM receives the Disable Slot command, according to xHCI spec,
the PP bit in PORTSC register should not be cleared.

Tracked-On: #3486
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-08-01 09:28:01 +08:00
Xiaoguang Wu 55a5876eba DM USB: xHCI: workaround for USB SSD which supports UAS protocol
The USB mediator doesn't support USB Attached SCSI (UAS) protocol
due to no proper implementation for USB Stream. This patch will
use USB Bulk transfer to workaround until formal implentation for
UAS is ready.

Tracked-On: #3486
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-08-01 09:28:01 +08:00
Xiaoguang Wu 0e2cfd2dee DM USB: add native info in control transfer logging code
Add native bus and port information in the control transfer logging code.

Tracked-On: #3486
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-08-01 09:28:01 +08:00
Tianhua Sun 107c406baa dm: array bound checking to avoid buffer overflow
The array index of "epid" may be out of bounds if
"epid >= XHCI_MAX_ENDPOINTS", so bound check is
necessary before it is used.

Tracked-On: #3434
Signed-off-by: Tianhua Sun <tianhuax.s.sun@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
Reviewed-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
2019-07-30 16:36:13 +08:00
Tianhua Sun 493ddefd47 dm: fix pointer not checked for null before use
this patch fix null pointer access issues.

Tracked-On: #3434
Signed-off-by: Tianhua Sun <tianhuax.s.sun@intel.com>
Reviewed-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
2019-07-30 16:36:13 +08:00
Gao Junhao c175141c77 dm: bugfix for remote launch guest issue
when stdio is set as a virtio-console, guest run in backend, the open
file descriptor is not referring to a terminal.

Tracked-On: #3473
Signed-off-by: Gao Junhao <junhao.gao@intel.com>
Reviewed-by: Jian Jun Chen <jian.jun.chen@intel.com>
2019-07-29 09:53:35 +08:00
Conghui Chen 3945bc4c40 dm: array bound and NULL pointer issue fix
Remove the possible NULL pointer access code for virtio-console.c
Add '\0' to end of native_patch[], to avoid the potential issue when
using %s to print the array for virtio-i2c.c

Tracked-On: #3467
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Reviewed-by: Yonghua Huang <Yonghua.huang@intel.com>
2019-07-26 08:55:11 +08:00
Gao Junhao ff299d5c50 dm: support VMs communication with virtio-console
Add feature that client uos can still connect to server uos after
rebooting.

Tracked-On: #3459
Signed-off-by: Gao Junhao <junhao.gao@intel.com>
Reviewed-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-07-24 16:26:36 +08:00
Conghui Chen c1b4121e3b dm: virtio-i2c: minor fix
Change the condition of checking native adapter number.
Change sprintf to snprintf.

Tracked-On: #3437
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
2019-07-19 09:12:34 +08:00
Xiaoguang Wu 7a3ea2ad89 DM USB: xHCI: fix corner case of short packet logic
The old logic identify the short packet complete status (CS) by
comparing the transfered bytes (TB) and the expected transfered
bytes (ETB), it is right only when no error happend. If error
appears, the TB may be less than the ETB, but DM should report
error CS instead of short packet CS.

Tracked-On: #3401
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-07-12 17:04:44 +08:00
Xiaoguang Wu 32d186ba68 DM USB: xHCI: add the resume state for PLS bits
Add resume state for the Port Link Status (PLS) bits.

Tracked-On: #3401
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-07-12 17:04:44 +08:00
Xiaoguang Wu c3d4cc36e1 DM USB: xHCI: refine the logic of Stop Endpoint cmd
When the Stop Endpoint command is trapped, should not clear all
the data structure. Instead, only reset the ring buffer.

The reason is the xHCI may continue queue TRB without doing whole
initializing process again.

Tracked-On: #3401
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-07-12 17:04:44 +08:00
Xiaoguang Wu 5686898291 DM USB: xHCI: change log for convenience of debugging
Not change code logic, just modify some logging code.

Tracked-On: #3401
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-07-12 17:04:44 +08:00
Tianhua Sun d8b752c4ee dm: fix variable argument list read without ending with va_end
va_end() was not getting called under certain condition
after the va_start() function call taking the va_list.

Tracked-On: #3396
Signed-off-by: Tianhua Sun <tianhuax.s.sun@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
2019-07-12 09:41:15 +08:00
Tianhua Sun b96a3555bc dm: fix some possible memory leak
free memory allocated by strdup()

Tracked-On: #3395
Signed-off-by: Tianhua Sun <tianhuax.s.sun@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
2019-07-12 09:41:15 +08:00
Conghui Chen e720dda5b0 DM: virtio-i2c: add dsdt info
Add dsdt information for i2c adapter and i2c slave devices. Currently,
only support 'cam1', 'cam2' and 'hdac' for MRB board. To add other
specific i2c device, please extend acpi_node_table[].

Usage:
	virtio-i2c,<bus>[:<slave_addr>[@<node>]][:<slave_addr>[@<node>]]
	        [,<bus>[:<slave_addr>[@<node>]][:<slave_addr>][@<node>]]

e.g.
	virtio-i2c,0:70@cam1:2F

	This will add slave devices 0x70, 0x74 to virtio i2c adapter.
	And for 0x70, it has '@cam1', so, will also add acpi info for
	it. For 0x74, it has no '@<node>', will not add any acpi info
	for it.

Note, there is slave address in acpi node info, please use '@<node>'
according to real hardware.

Tracked-On: #3357
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Reviewed-by: Yuan Liu <yuan1.liu@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Wang Yu <yu1.wang@intel.com>
2019-07-05 10:20:21 +08:00
Conghui Chen b6f9ed39fc DM: virtio-i2c: add msg process logic
Create a new thread for virtio-i2c to process i2c msg from FE. After
receive the msg, BE will dispatch it to corresponding native adapter,
after the process done, it will kick the FE.

Tracked-On: #3357
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Reviewed-by: Yuan Liu <yuan1.liu@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Wang Yu <yu1.wang@intel.com>
2019-07-05 10:20:21 +08:00
Conghui Chen 859af9e03d DM: virtio-i2c: add backend interface
Add backend interface for virtio-i2c, it will parse the parameters,
maintain the info for native i2c device, remap the slave address and
dispatch the requirement from FE. When there is only one native adapter,
will not remap the slave address.

Usage for virtio-i2c:

virtio-i2c,<bus>[:<slave_addr>][:<slave_addr>]
	[,<bus>[:<slave_addr>][:<slave_addr>]]

e.g.
1.  virtio-i2c,4:1C
    SOS:
        mount /dev/i2c-4, slave addr is 0x1C.
    Guest OS:
        /dev/i2c-x
           |- 0x1C

2. virtio-i2c,4:1C:2F,6:70
    SOS:
        /dev/i2c-4, slave addr 0x1C and 0x2F
        /dev/i2c-6, slave addr 0x70
    Guest OS:
        /dev/i2c-x
           |- 0x1C
           |- 0x2F
           |- 0x70

Tracked-On: #3357
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Reviewed-by: Yuan Liu <yuan1.liu@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Wang Yu <yu1.wang@intel.com>
2019-07-05 10:20:21 +08:00
Conghui Chen a450add672 DM: virtio-i2c: add support for virtio i2c adapter
Add virtio i2c adapter BE driver.

Tracked-On: #3357
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Reviewed-by: Yuan Liu <yuan1.liu@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Wang Yu <yu1.wang@intel.com>
2019-07-05 10:20:21 +08:00