Commit Graph

383 Commits

Author SHA1 Message Date
Jian Jun Chen cb31381561 dm: vhost: remove support for non-msix devices
irqfd only supports msix devices. In the current code a mevent is
added to poll the callfd from userspace to support intx devices.
This patch removes the support for non-msix devices since they are
not used in the current device model.

Tracked-On: #1877
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-14 19:49:55 +08:00
Jian Jun Chen b29fc619af dm: virtio-net: apply new mevent API to avoid race issue
Teardown callback is provided when mevent_add is called and it is
used to free the virtio-net resources.

Tracked-On: #1877
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-12-14 19:49:55 +08:00
Jian Jun Chen 4f36244fef dm: virtio-console: apply new mevent API to avoid race issue
Teardown callback is provided when mevent_add is called. A ref_count
is added to virtio_console data structure. Teardown callback needs to
free the resources of the backend and when the ref_count of the
virtio_console is zero the whole virtio-console is freed.

Tracked-On: #1877
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-12-14 19:49:55 +08:00
Jian Jun Chen baf8f8bdbf dm: virtio-input: apply new mevent API to avoid race issue
Teardown callback is provided when mevent_add is called and it is
used to free the virtio-input resources.

Tracked-On: #1877
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-12-14 19:49:55 +08:00
Xiaoguang Wu c2df4a8557 DM USB: xHCI: no wait logic implementation for S3
On Intel Apllo Lake platform, the VBus will drop after the SOC suspended,
hence during the SOS resuming process, there will be a disconnecting event
and a connecting event sent to each native USB device in order.

This patch will use new strategy for S3 resuming emultion.
  1. The DM set PORTSC register to 'no device attached' state when S3
     suspending started,
  2. SOS resuming starts and do nothing for device disconnecting event,
  3. 'Cache' device connecting event and don't report it to UOS,
  4. UOS believe no device attached due to PORTSC register state and
     begin to clear the resource allocated for the device before S3
     suspending,
  5. DM receives the Disable Slot command from UOS and report the 'cached'
     device connecting event to UOS, hence trigger the emulation behavior
     for the device.

The purpose of this strategy is to let UOS resuming proceed as quickly as
possible, which means the UI will be turned on quickly to user.

Tracked-On: #1893
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-14 19:40:44 +08:00
Xiaoguang Wu 82659831f0 DM USB: xHCI: refine emulation for command XHCI_CMD_RS
According to xHCI spec 5.4.1.1, this command hasn't ask to clear
PORTSC for R/S handling. So the PORTSC should always present the
physical usb bus status.

The old implementation changes the PORTSC according whether the
pci_xhci_dev_emu struct is allocated, it is not consistent with
spec and this patch is used to fix it.

Tracked-On: #1893
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-14 19:40:44 +08:00
Xiaoguang Wu e5c98e6d9a DM USB: add usb_dev_path_cmp function for convenience
Comparing two USB devices' path is frequently used operation, abstract
it as an seperated function for convenience.

Tracked-On: #1893
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-14 19:40:44 +08:00
Xiaoguang Wu 6c1ca13767 DM USB: xHCI: remove the waiting 5 seconds wa for s3
This workaround will delay the UOS resuming for 5 seconds, this
behavior is not right and should be replaced by dynamic style.

Tracked-On: #1893
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-14 19:40:44 +08:00
yingbinx 6b998580d6 Fix KW issues for tpm_emulator
There are several KW issues which uninitialized variables
are used. This patch will fix those KW issues.

Signed-off-by: weideng <wei.a.deng@intel.com>
Signed-off-by: yingbinx <yingbinx.zeng@intel.com>
2018-12-14 09:05:28 +08:00
Yang Liang fbaecde6bb DM USB: xHCI: Fix banned API issue.
In USB mediator, sscanf, strtok and atoi API is banned, so replace them
with permitted API function.

Tracked-On: #1254
Signed-off-by: Yang Liang <liang3.yang@intel.com>
Reviewed-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Shuo Liu <shuo.a.liu@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-13 13:24:55 +08:00
Peter Fang e835f5f5d2 dm: enforce data size when accessing PCI BARs
Always enforce data size when using BAR access functions.

Currently, the size serves as a hint to the BAR access functions and
these functions are expected to behave accordingly. Some of the access
functions, e.g. virtio ones, don't always truncate the data but expect
the caller to take care of the data size. This causes problems with
OVMF's virtio drivers during I/O instruction emulation because RAX can
contain junk bits that shouldn't be written to the device.

v1 -> v2:
- improve readability

Tracked-On: #1935
Signed-off-by: Peter Fang <peter.fang@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2018-12-13 13:22:44 +08:00
Jie Deng ed1c576d08 dm: pass mac seed not to use vm name
Physical NIC mac address is used for generate UOS mac address.
This patch uses a new parameters to pass this information
instead of vm name.

Tracked-On: #1987

Signed-off-by: Jie Deng <jie.deng@intel.com>
Acked-by: Yan, Like <like.yan@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2018-12-12 13:22:18 +08:00
Jian Jun Chen 2ef06450dc dm: virtio-input: ignore all MSC events from FE
EV_MSC is configured as INPUT_PASS_TO_ALL in input driver. There is
a loop in the use case of virtio-input. They should not be forwarded
back to BE since they have already been sent to native driver before
sending to FE.

Tracked-On: #2006
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-12 09:31:57 +08:00
Yang Liang da0cf3af71 DM: xHCI: unbind slot id and ndevices relationship.
After mutiple usb devices send enable slot commnad and get slot id each
other, address device setup flow is not sorted by slot id. According to
current design, it will casue assert failure. This patch takes off this
restriction.

Tracked-On: #2017
Signed-off-by: Yang Liang <liang3.yang@intel.com>
Reviewed-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-12 09:11:29 +08:00
Yin Fengwei 7fce2462a0 dm: apply new mevent API to avoid race issue in mei
Pass teardown callback when add mevent in mei mediator code.
Which could avoid run_callback calling after the related data
structure is freed.

Tracked-On: #1877
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-07 20:21:33 +08:00
Yin Fengwei 64d9c59aa1 dm: enhence the mevent API
There is one race issue between mevent callback (which is called
in mevent_dispatch thread) and mevent_delete (which could be called
in dev thread). And the callback is called after mevent_delete.

libevent have the exactly same issue. The issue is decripted here:
https://github.com/libevent/libevent/blob/master/whatsnew-2.1.txt

The fixing is:
We introduce a teardown callback to mevent and make sure there is
no race issue between callback and teardown call.

This patch updates the mevent API and the caller as well.

Tracked-On: #1877
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-07 20:21:33 +08:00
Xiaoguang Wu 9d4b5d7e1b DM USB: add some preparing time for xHCI emulation before resuming.
If the USB kernel drives and devices of SOS are not available and
functional ready after UOS is resumed from frozen state, the comming
USB command from UOS will cause a disaster because the DM has no
resourse to to emulation.

This patch add a dynamic time span (could change according to number
of native USB devices attached) to give USB drivers and devices of
SOS an opportunity to be ready.

Tracked-On: #1893
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-04 19:59:00 +08:00
Xiaoguang Wu b159d66fb3 DM USB: refine the polling thread for libusb events
The thread function usb_dev_sys_thread is the source of libusb events,
which is also the basis of USB/xHCI emulation. During S3 process,
function libusb_handle_events_timeout may fail and return -1, which
could result of exit of the thread (BTW, this failure is resulted from
USB native reseting behavior during S3). Under this situation, the emulation
of USB/xHCI could never continue.

This patch fix this issue by continuing to call libusb_handle_events_timeout
even it reture -1. The return value will be finally ok after S3 process is
completed.

This patch will continue poll after failure and hence fix this issue.

Tracked-On: #1893
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-04 19:59:00 +08:00
Xiaoguang Wu 966c587260 DM USB: xHCI: fix potential NULL pointer issue.
During S3 process, the dev in the function pci_xhci_device_doorbell
may be set to NULL when disconnection is detected by DM. This patch
is used to remove this risk.

Tracked-On: #1893
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-04 19:59:00 +08:00
Xiaoguang Wu 5b39fd0ed3 DM USB: xHCI: fix error logic of allocating xHCI slot
The 'slot_allocated[]' field of pci_xhci_vdev is used as flag of
slot allocation. In current design, this variable is not set to
false in disconnection callback 'pci_xhci_native_usb_dev_disconn_cb'.
This patch is used to fix it.

Tracked-On: #1894
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-04 19:59:00 +08:00
Xiaoguang Wu 32c4ce9b9a DM USB: xHCI: refine the xHCI S3 process
In the old implementation, function vm_get_suspend_mode is used
as the interface to check whether the UOS is in the S3, That is
not saft way.

This patch use Port Link State (PLS) to substitute the old logic.
According to xHCI spec 5.4.8, the PLS should be U3 during the
UOS is in the S3 state.

Tracked-On: #1893
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-04 19:59:00 +08:00
Xiaoguang Wu 9e471d7258 DM USB: xHCI: refine the PLC bit emulation logic during S3
According to xHCI 5.4.8, the Port Link State Change (PLC) bit
should not be set to 1 during suspend process. This patch is used
to fix it.

Tracked-On: #1893
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-04 19:59:00 +08:00
Xiaoguang Wu 29e81501c5 DM USB: xHCI: refine error handling logic for ctrl transfer
Under current implementation, when USB control transfer failed
with Endpoint Stall error, there is no response reporting to UOS.
This logic will result of timeout in UOS kernel and hence a longer
enumeration process.

This patch reports the Stall Error to UOS by xHCI Completion Event,
which will fix this issue.

Tracked-On: #1895
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-04 19:59:00 +08:00
Jie Deng b261e74dd5 dm: virtio poll mode support for RT
Device trap has great impact on latency of real time (RT) tasks.
This patch provide a virtio poll mode to avoid trap.

According to the virtio spec, backend devices can declare the
notification is not needed so that frontend will never trap.
This means the backends make commitment to the frontends they have a
poll mechanism which don’t need any frontends notification.

This patch uses a periodic timer to give backends pseudo notifications
so that drive them processing data in their virtqueues. People should
choose a appropriate notification peroid interval to use this poll
mode. Too big interval may cause virtqueue processing latency while
too small interval may cause high SOS CPU usage. The suggested interval
is between 100us to 1ms.

The poll mode is not enabled by default and traditional trap
notification mode will be used. To use poll mode for RT with interval
1ms. You can add following acrn-dm parameter.

	--virtio_poll 1000000

Tracked-On: #1956
Signed-off-by: Jie Deng <jie.deng@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-04 18:27:53 +08:00
Libin Yang 7f08ad8375 use 4 vqs
Signed-off-by: Libin Yang <libin.yang@intel.com>
Tracked-On: #1915
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-03 10:35:38 +08:00
Zhu Yingjiang 333629682a change the vq count and vendor id
Signed-off-by: Zhu Yingjiang <yingjiang.zhu@linux.intel.com>
Tracked-On: #1915
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-12-03 10:35:38 +08:00
Junjie Mao 97eb72a4a0 doc: always use 'None' for functions not returning a value
It is preferred to state the absence of a return value explicitly in the
doxygen-stile comments. Currently there are different styles of doing this,
including:

  @return None
  @return NULL
  @return void
  @return N/A

This patch unifies the above with `@return None`.

Tracked-On: #1595
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2018-11-30 14:55:17 +08:00
Zheng, Kankan cbe1b74eee HDCP virtio back-end driver
Initial HDCP back-end driver.

Signed-off-by: Romli, Khairul Anuar <khairul.anuar.romli@intel.com>
2018-11-30 14:45:24 +08:00
Yu Shiqiang fa012e6987 CoreU virtio back-end driver
v4 -> v5
    Replace strcpy with strncpy
    Refine resource free if error happens
    Remove meaningless *in_progress* label for pthread wait/signal
    Rename the coreu thread routine name (virtio_coreu_thread)

v3 -> v4
    Move setsocketopt to connect_to_daemon
    Cleanup coreu file descriptor after close
    Reconnect CoreU daemon if the socket descriptor is invalid

v2 -> v3
    Move the daemon connection to vdev_init
    Diagram the CoreU virtualization architecture
    Create a seperate thread for sending and receving the CoreU message
    Change the socket name

v1 -> v2
    No change

v1
    Initial CoreU back-end driver

Signed-off-by: Yu Shiqiang <shiqiang.yu@intel.com>
2018-11-30 14:45:24 +08:00
Qi Yadong 839680f09b DM: build TPM2 ACPI table when TPM device enabled
Add TPM2 ACPI table build function.

If virtual tpm device is initialized successfully, then create
corresponding TPM2 ACPI table.

Tracked-On: #1924
Signed-off-by: Qi Yadong <yadong.qi@intel.com>
Reviewed-by: Zhu Bing <bing.zhu@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-11-29 09:19:16 +08:00
Qi Yadong aae70db6b9 DM: Add support for virtual TPM enabling
Support TPM enable option when launch UOS.

New option: "--vtpm sock_path=$PATH_OF_SWTPM_SOCKET".
If valid option parsed, then init virtual tpm device.

Tracked-On: #1924
Signed-off-by: Qi Yadong <yadong.qi@intel.com>
Reviewed-by: Zhu Bing <bing.zhu@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-11-29 09:19:16 +08:00
Qi Yadong 7df90a2527 DM: Support TPM2 CRB device virtualization
Full virtualized TPM CRB device.

The TPM CRB module will handle TPM2 MMIO access. It will forward
the command/data to TPM emulator for command processing if there
is a valid TPM command.

Tracked-On: #1924
Signed-off-by: Qi Yadong <yadong.qi@intel.com>
Reviewed-by: Zhu Bing <bing.zhu@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-11-29 09:19:16 +08:00
Qi Yadong 4b83e37c7a DM: tpm emulator to communicate with swtpm
This patch will create control channel and command channel
so as to communicate with swtpm. Based on the 2 channels,
a set of APIs will be implemented and exposed.

Tracked-On: #1924
Signed-off-by: Deng Wei <wei.a.deng@intel.com>
Signed-off-by: Qi Yadong <yadong.qi@intel.com>
Signed-off-by: yingbinx <yingbinx.zeng@intel.com>
Reviewed-by: Zhu Bing <bing.zhu@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-11-29 09:19:16 +08:00
Yuan Liu d043171de5 IOC mediator: Add VehicalSteeringWheelAngle signal to the whitelist
The signal is used to get camera right and left values.

Tracked-On: #1886
Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-11-23 14:59:07 +08:00
Tomas Winkler 580579a392 dm: mei: Use compare and swap primitive for refcnt.
Simple atomic add/dec do no guarantee reference count full
synchronization without a lock. Compare and swap operations
are required for correct implementation.

Tracked-On: #1875
Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-11-23 14:13:14 +08:00
Alexander Usyskin 378afc5093 dm: mei: fix clients scan in sysfs
Fix the prefix comparison, we need to compare on prefix length, not
on devpath len, otherwise we always fail.

Tracked-On: #1848
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Acked-by: Yu Wang <yu1.wang@intel.com>
2018-11-21 15:17:05 +08:00
Alexander Usyskin 7bd2976f9c dm: mei: add zero termination to devpath
Reset directory name to receive clean prints.

Tracked-On: #1847
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Acked-by: Yu Wang <yu1.wang@intel.com>
2018-11-21 15:17:05 +08:00
Tomas Winkler 87fbb7003d dm: mei: fix double fw_reset on uos reboot
Edge triggered mevent on sysfs file is triggered
immediately after mevent_add(), hence this has to be ignored.
The issue that is resolved that the 'first' flag was
global and wasn't reset on each mevent_add().

Tracked-On: #1846
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Acked-by: Yu Wang <yu1.wang@intel.com>
2018-11-21 15:17:05 +08:00
Alexander Usyskin 844553ef23 dm: mei: check for state before link reset callback
Prevent intercepting reset callback if reset state
transition is already in progress.

Tracked-On: #1846
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Acked-by: Yu Wang <yu1.wang@intel.com>
2018-11-21 15:17:05 +08:00
yuhong.tao@intel.com c4161c8784 dm: uart: fix UOS console output to stdin
At devicemodel/hw/uart_core.c, struct ttyfd has only one file
descriptor for uart backend device, that is OK if DM uart open
a tty characteor device under /dev/ for reading, writing and
terminal operating.

When use stdio as backend tty device, there are 2 fds, stdin/stdout.
DM should read from 'stdin' and output to 'stdout'. But ttyfd just
has one fd, and is only for 'stdin', so dm has to output to stdin,
too, not to stdout.

That cause a problem: if use stdio for uart backend, you can't
redirect UOS console to any other files. Because stdout is not used.

We hope to store information from VM console to system journal,
when UOS is launched by Acrnd automatically. The systemd need to
redirect stdout of dm to system journal files, but it can't be done.

So we can split the 'fd' of struct ttyfd to 'fd_in' & 'fd_out'.
they are same when use tty device; And they are different when use
stdio, 'fd_in' is for stdin and 'fd_out' is for stdout.

Tracked-On: #1759
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
Reviewed-by: Like Yan <like.yan@intel.com>
Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
2018-11-08 15:14:15 +08:00
Zhi Jin 36aaaa1cfd DM NPK: unmap the MMIO in pci_npk_deinit
Otherwise, after UOS crashes, the PTE for the MMIO may be added
again.

Tracked-On: #1745
Signed-off-by: Zhi Jin <zhi.jin@intel.com>
2018-11-08 09:06:17 +08:00
Yuan Liu 65a2613ab6 IOC mediator: fix wakeup reason issue when UOS resuming
IOC mediator should keep sending acnrd boot reason until received
UOS heartbeat init message, then turn to send SOS wakeup reason
through read native cbc lifecycle cdev.

Tracked-On: #1727
Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-11-06 16:18:35 +08:00
Shuo Liu d261b4bce2 doc: update virtio related functions doc comments
Update some virtio, VBS-K, vhost APIs documents.

Tracked-On: #1595
Signed-off-by: Shuo Liu <shuo.a.liu@intel.com>
2018-11-04 20:32:50 -08:00
Jian Jun Chen 94dadc1d14 dm: virtio-input: ignore MSC_TIMESTAMP from guest
(EV_MSC, MSC_TIMESTAMP) is added to each frame just before the
SYN event since kernel 4.15. EV_MSC is configured as
INPUT_PASS_TO_ALL. In the use case of virtio-input, there is
a loop as follows:
- A mt frame with (EV_MSC, MSC_TIMESTAMP) is passed to FE.
- FE will call virtinput_status to pass (EV_MSC, MSC_TIMESTAMP)
  back to BE.
- BE writes this event to evdev. Because (EV_MSC, MSC_TIMESTAMP)
  is configured as INPUT_PASS_TO_ALL, it will be written into
  the event buffer of evdev then be read out by BE without
  SYN followed.
- Each mt frame will introduce one (EV_MSC, MSC_TIMESTAMP).
  Later the frame becomes larger and larger...

This patch fixed above issue by ignoring MSC_TIMESTAMP from guest.
Besides that timestamp is added for every status event from guest
before writing to evdev.

Tracked-On: #1670
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-11-02 13:42:43 +08:00
Aviad Nissel 9ba75c55a7 dm: mei: fix firmware reset race.
The FW reset is currently detected from two points upon
a read failure from native read and from the reset
handler.
The fix removes the detection from the mevent rx callback,
leaving a single detection point.
To prevent reset hiccup, hw_ready is not set if a full rescan is
performed, it will be set only when virtio FW will request the FW reset.

Tracked-On: #1632
Signed-off-by: Aviad Nissel <aviad.nissel@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
2018-10-31 09:43:45 +08:00
Alexander Usyskin 5f41d4a8d3 dm: mei: check return value of vmei_host_client_to_vmei()
vmei_host_client_to_vmei() may return NULL we need to check
for the return value.

Tracked-On: #1630
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
2018-10-31 09:43:45 +08:00
Tomas Winkler b4fbef4659 dm: mei: destroy mutex attribute on error path
Simplify the flow by adding mutex_type variable
and call pthread_mutexattr_destroy() on the error path.

Tracked-On: #1630
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
2018-10-31 09:43:45 +08:00
Alexander Usyskin 8abc931791 dm: mei: set addresses in the hbm disconnect reply
MEI HBM the disconnect replay doesn't have the address set,
breaking the protocol, fix the issue.

Tracked-On: #1570
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2018-10-31 09:43:45 +08:00
Xiaoguang Wu a0ace7254d DM USB: xHCI: fix process logic of TRB which has zero data length
Accoring to xHCI spec, there are some TRBs with zero data length
which used to pass command to xHCI. In the DM, those TRBs should
not be sent to native device through libusb. The logic in the
current implentation fails to process some corner cases, this
patch is used to fix it.

Tracked-On: #1639
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-31 09:08:53 +08:00
Yonghua Huang b686b562f4 DM: wrap ASSERT/DEASSERT IRQ line with Set/Clear IRQ line
- remove ASSERT & DEASSET IRQ line IOCTLs
 - remove PULSE IRQ line IOCTLs, use set/clear
   IRQ line instead.
 - Use IC_SET_IRQLINE to set or clear IRQ line

Tracked-On: #861
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
Reviewed-by: Eddie Dong <eddie.dong@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2018-10-29 09:26:23 +08:00
Jian Jun Chen e12f88b8c7 dm: virtio-console: remove unused virtio_console_cfgwrite
Virtio-console device specific configuration is readonly, callback
for the cfgwrite is not required. This patch removed the unused
virtio_console_cfgwrite.

Tracked-On: #1364
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-27 22:28:04 +08:00
Conghui Chen 3010718d4a dm: cmdline: remove unused parameters
Remove unused parameters for acrn-dm

Tracked-On: #1616
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-10-26 13:37:47 +08:00
Xiaoguang Wu 4261ca223e DM USB: xHCI: refine logic of Disable Slot Command
Remove the changing operation for 'xdev->native_ports[].state' in
pci_xhci_cmd_disable_slot. The operation should not be done in this
funciton.

Tracked-On: #1589
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-26 13:36:50 +08:00
Xiaoguang Wu e1e0d3047e DM USB: xHCI: refine the USB disconnect logic in DM
On certain SOC, during the system suspend and resume process, connecting
and disconnecting events may happen. In previous implementation, DM didn't
clear PED bit in the xHCI PORTSC register, this will induce many invalid
polling operations in UOS and fail to enumerate one or more USB devices.

Tracked-On: #1589
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-26 13:36:50 +08:00
Xiaoguang Wu f799e8fa1c DM USB: xHCI: fix process logic of LINK type TRB
When the LINK type TRB are received, it should not be counted as
valid date block to give libusb. This patch is used to fix it.

Tracked-On: #1567
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-26 13:36:50 +08:00
Xiaoguang Wu 08a7227fe6 DM USB: xHCI: fix bug in port unassigning function
The function for port unassigning: pci_xhci_clr_native_port_assigned
should reset the 'info' member to all zero when it is called.

Tracked-On: #1434
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-26 13:36:50 +08:00
Xiaoguang Wu d7008408d0 DM USB: xHCI: fix issue: crash when plug device during UOS booting
This issue is result from reporting interrupt when the interrupt ability
of virtual xHCI is disabled.

As Event Ring State Machine showed in Figure 20 of xHCI spec, following
rules should be followed:
1 when RS bit of USBCMD register is zero, Event Ring should not be accessed;
2 when INTE bit of USBCMD register is zero, Interrupt should not be sent.

Tracked-On: #1566
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-26 13:36:50 +08:00
Jian Jun Chen 655132fc8e dm: virtio: remove unused vbs_kernel_init
Tracked-On: #1364
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-25 15:39:57 +08:00
Liang Yang 80e02c9708 DM USB: xHCI: Fix an potential array out of range issue.
When usb device numbers reach up to XHCI_MAX_SLOTS. The slot_allocated
array will get out of range. This patch is used to fix this issue.

Tracked-On: #1479
Signed-off-by: Liang Yang <liang3.yang@intel.com>
Reviewed-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-25 13:46:05 +08:00
Liang Yang 84c0c87842 DM USB: xHCI: Fix a potential NULL pointer issue.
After excap pointer is assigned, it should be checked whether it's
possible to get assignment for NULL pointer or not. This patch
fixes this issue.

Tracked-On: #1479
Signed-off-by: Liang Yang <liang3.yang@intel.com>
Reviewed-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liu Shuo <shuo.a.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-25 13:46:05 +08:00
Jie Deng 7195537a6b dm: virtio-net: replace banned functions
sscanf and strcpy are banned according to the security requirements.
So replace them with their safe alternative.

Tracked-on: #1496
Signed-off-by: Jie Deng <jie.deng@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-24 18:16:37 +08:00
Huang, Yang bd97e5cbe2 dm: rpmb: Support RPMB mode config from launch.sh
physical RPMB is accessed if "phisycal_rpmb" is specified
in launch.sh.
Also it reserves some RPMB area with a fixed size(32KB) for
AttKB and future usage, which is RO for UOS.

Tracked-On: #1544
Signed-off-by: Huang, Yang <yang.huang@intel.com>
Acked-by: Zhu Bing <bing.zhu@intel.com>
2018-10-24 18:15:14 +08:00
Tomas Winkler d4b9bd599d dm: mei: add module initialization
Register virtio device virtio-mei.

Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>

Tracked-On: #1536
Signed-off-by: Liu Shuo <shuo.a.liu@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2018-10-23 11:40:15 +08:00
Tomas Winkler f6e6e8584e dm: mei: implement vmei_start/stop()
In vmei_start() the HBM host client is created,
it handles HBM protocol.
The HBM client is a management object and
is not exposed by the mei native driver.
The communication between TX and RX threads
is handed via internal pipe(2).
Second, we connect all fixed address clients as the mei
protocol doesn't provide connection mechanism for them,
they appear always connected.
Last, the hw_ready is set.

Define virtio_mei_ops, ass all the handlers are now available.

Tracked-On: #1536
Signed-off-by: Liu Shuo <shuo.a.liu@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2018-10-23 11:40:15 +08:00
Tomas Winkler 6a1f824229 dm: mei: implement rx flow.
Rx is triggered from epoll event (mevent), a host client
is retrieved from associated event data. P proper mei message header is
attached to the packet and sent to the virtio FE device.

Tracked-On: #1536
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2018-10-23 11:40:15 +08:00
Tomas Winkler 50ecd93b24 dm: mei: implement tx flow
TX from virtio driver is handled firt via
virio tx notify handler vmei_notify_tx(),
placed into host clinet tx circular buffer.
TX thread will then write the data to the device.

Tracked-On: #1536
Signed-off-by: Vitaly Lubart <vitaly.lubart@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2018-10-23 11:40:15 +08:00
Tomas Winkler 483a893e57 dm: mei: implement HBM protocol handler
Implement the FW part of the HBM protocol.
Currently the support version is 2.0.
The HBM protocol handles client management, such
initialization handshake, connection, power management,
and the flow control.

Tracked-On: #1536
Signed-off-by: Vitaly Lubart <vitaly.lubart@intel.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2018-10-23 11:40:15 +08:00
Tomas Winkler 98c6b7a692 dm: mei: add native io handlers
Add read write and connect handler,
that perform io peration on SOS /dev/meiX
device.

Tracked-On: #1536
Signed-off-by: Vitaly Lubart <vitaly.lubart@intel.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2018-10-23 11:40:15 +08:00
Tomas Winkler 3abbf10e55 dm: mei: add me clients enumeration
ME client enumeration is received from sysfs attributes
of the native device.

V3: Use bounded functions.

Tracked-On: #1536
Signed-off-by: Vitaly Lubart <vitaly.lubart@intel.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2018-10-23 11:40:15 +08:00
Tomas Winkler 7cbb3872a2 dm: mei: add virtio cfgread/cfgwrite handlers.
mei mediator perform reset handshake via
the cfgread/write handlers and provide access
to fw status registers.

Tracked-On: #1536
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2018-10-23 11:40:15 +08:00
Signed-off-by: Aviad Nissel f462601b0a dm: mei: add reset handlers
There are multiple types of resets that need to be handled
by the mei device.
The reset may be initiated from both sides host or fw.
The host requests reset on probe and remove,
power state transaction, and errors,
while ME FW may request reset upon error.
If the native device undergo reset the host application
has to be notified.

Tracked-On: #1536
Signed-off-by: Aviad Nissel <aviad.nissel@intel.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2018-10-23 11:40:15 +08:00
Tomas Winkler a632ac3dae dm: mei: add client management infrastructure
1. virtio_mei structure represents an instance of mei device.
2. vmei_me_client represents an ME application in the MEI FW.
3. vmei_host_client represent a host application talking to the
ME application, ME application can support multiple connections.
4. Add debug helpers

Tracked-On: #1536
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2018-10-23 11:40:15 +08:00
Tomas Winkler 445f419304 dm: mei: add virtio configuration
The virtio has two virtio queues, TX and RX.
TX have two segment buffers one for header and one for data.
The virtio_mei declares host buffer of size 128 slots, each
slot is a 4 bytes value.
For synchronization hw_ready and host_reset configuration flags
are used that emulates mei reset flow.
And last fw status registers must be also readable via virtio
mei device.

Tracked-On: #1536
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2018-10-23 11:40:15 +08:00
Tomas Winkler 0dc7adfbac dm: mei: add sysfs read functions
mei requires reading of u8, u32 and uuid
sysfs files.

Tracked-On: #1536
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Vitaly Lubart <vitaly.lubart@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2018-10-23 11:40:15 +08:00
Tomas Winkler b8d53d17d5 dm: mei: add reference counter functions
mei handles objects on the list, hence reference counting
infrastructure is required for easier multithreading.

Tracked-On: #1536
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2018-10-23 11:40:15 +08:00
Alexander Usyskin 4e057c32d2 dm: mei: add guid handling functions
libuuid sports only uuid (big endian encoding),
though mei requires guids (little endian encoding).
The base types are based on <linux/uuid.h> header.

Tracked-On: #1536
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2018-10-23 11:40:15 +08:00
Tomas Winkler 0cc50b1d43 dm: remove virtio_heci
Remove virtio_heci to be replaced with virtio_mei

Tracked-On: #1536
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2018-10-23 11:40:15 +08:00
Xiaoguang Wu 6a9a46ac47 DM USB: xHCI: workaround for Stop Endpoint Command handling
This patch is one workaround to resolve a crash issue for certain brand
touch screen (eGalaxTouch EXC7200-7368v1.01). The formal fix should
follow the xHCI spec to stop xfer and generate transfer completed event
trb prior to Stop Endpoint Command complete event trb. It should be a
big change and for short term, do nothing for the stop endpoint command
which is no other side effect be observed so far.

Tracked-On: #1413
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-19 22:39:50 +08:00
Xiaoguang Wu ecf0585bf2 DM USB: xHCI: fix incorrect device searching logic
The function pci_xhci_get_native_port_index_by_path didn't
compare the bus number during the process of native USB
device searching. This patch is used to fix it.

Tracked-On: #1434
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Reviewed-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-19 22:39:50 +08:00
Xiaoguang Wu 6b2a18a866 DM USB: add support for multi-layers hubs
This patch is used to support emulation of multiple layers of hubs
under Flat Mode.

Tracked-On: #1434
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Signed-off-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-19 22:39:50 +08:00
Liang Yang f533a07af1 DM USB: xHCI: support multiple hubs in single layer
This patch is used to enable multiple hubs in single layer under
Flat Mode.

Tracked-On: #1434
Signed-off-by: Liang Yang <liang3.yang@intel.com>
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-19 22:39:50 +08:00
Xiaoguang Wu 6886d3cdf8 DM USB: xHCI: change port mapping logic for multiple hub support
To support the multiple hubs and multiple layers of hub, the
port_map_tbl should be replaced by native_ports to record all
native devices' state, including assignment state, emulation
state etc.

Tracked-On: #1434
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Signed-off-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-19 22:39:50 +08:00
Xiaoguang Wu 540ce05f27 DM USB: introduce function usb_get_native_devinfo
There are many places in USB emulation implementation to get
native USB device infomation, and the related codes are long
and repeated many times. This patch introduces function
usb_get_native_devinfo to remove redundent codes for the
purpose mentioned above.

Tracked-On: #1434
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Signed-off-by: Liang Yang <liang3.yang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-19 22:39:50 +08:00
Liang Yang e8f7b6fa74 DM USB: introduce struct usb_devpath and releted functions
This patch introduce struct usb_devpath to indentify uniquely an USB
device, which is basic element for multiple hub support.

Tracked-On: #1434
Signed-off-by: Liang Yang <liang3.yang@intel.com>
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-19 22:39:50 +08:00
Liang Yang 14bc961f03 DM USB: xHCI: remove old hub support code.
Previous design use bus and port(root hub port) for the identification
to the native USB device. It cannot work properly under the multi-hub
situation due to external USB hub is introduced.

This patch removes old hub implementation code, and subsequent patches
will be add support for mutiple hubs.

Tracked-On: #1434
Signed-off-by: Liang Yang <liang3.yang@intel.com>
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-19 22:39:50 +08:00
Huang, Yang ffcf62982d dm: rpmb: DM customized changes for RPMB mux kernel module
As RPMB mux kernel module is going to be created,
there are two corresponding changes required for DM:
1. The name has been changed to /dev/rpmbmux.
2. DM does NOT check MAC of RPMB result returned by kernel
   module because DM doesn't own the real key.

Tracked-On: #1508
Signed-off-by: Huang, Yang <yang.huang@intel.com>
Acked-by: Zhu Bing <bing.zhu@intel.com>
2018-10-19 22:31:28 +08:00
Victor Sun de10df2693 DM: add MSI and INTR support for i6300esb watchdog
Per i6300esb spec, when WDT_INT_TYPE(bit 0 and 1 of WDT config register)
are set to 00, IRQ feature should be supported.

The WDT_INT_ACTIVE bit is set when the first stage of the 35-bit
down-counter reaches zero. An interrupt will be generated if WDT_INT_TYPE
is configured to do so (See WDT Configuration Register). This is a sticky
bit and is only cleared by writing a 1.

SMI feature(WDT_INT_TYPE are set to 0x10) is not supported.

Tracked-On: #1498
Signed-off-by: Victor Sun <victor.sun@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-10-18 09:30:01 +08:00
Conghui Chen 21458bddff dm: storage: banned functions replace
1. replace sscanf with string API.
2. replace sprintf with snprintf
3. replace strlen with strnlen

Tracked-on: #1496
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Reviewed-by: Shuo Liu <shuo.a.liu@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-10-17 16:22:00 +08:00
Yin Fengwei 75b03bef3b dm: add io port 0xF4 writing to force DM exit
This patch addes the debugexit function to DM. If it's enabled
by DM cmdline (by add --debugexit), the guest could write a
32bit value to port 0xF4 to trigger guest shutdown.

Tracked-on: #1465
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-17 14:32:33 +08:00
Victor Sun 0e897c0a6a DM: use acrn_timer api to emulate rtc
Current RTC emulation is based on sigevent mechanism, replace with
acrn_timer API which based on timerfd/epoll mechanism to avoid
potential resource accessing conflict in the async thread.

Tracked-On: #1489
Signed-off-by: Victor Sun <victor.sun@intel.com>
Reviewed-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-10-17 14:31:09 +08:00
Victor Sun 8fdea84a63 DM: use acrn_timer api to emulate wdt
In the current implementation sigev_notify is configured as
SIGEV_THREAD. When wdt expires an async thread is created and
the registered timer callback is called in the context of this
thread, then the watchdog interrupt emulation would require the
thread to assert intr on this pci dev.

There would be a race condition that when the wdt pci device is
freed in pci device deinit and then a timer expires. In this case
the wdt expired thread will access a freed buffer which would cause
problem such as heap corruption and segment fault.

In this patch we replace timer API with acrn_timer which is based
on timerfd/epoll mechanism to avoid the race condition.

Tracked-On: #1489
Signed-off-by: Victor Sun <victor.sun@intel.com>
Reviewed-by: Jian Jun Chen <jian.jun.chen@intel.com>
Reviewed-by: Minggui Cao <minggui.cao@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-10-17 14:31:09 +08:00
Yuan Liu dc05ffffaa dm: uart: fix acrn-dm crash issue
This patch resolves acrn-dm crash issue when acrnd boots up the acrn-dm.
The rootcause is mevent_enable and mevent_disable have NULL pointer as
its parameter if uart backend is not tty capable, so add check code for
the uart backend before invoking mevent_enable and mevent_disable.

The issue can be reproduced when acrnd boots up the acrn-dm.

Tracked-On: #1466
Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Reviewed-by: Tomas Winkler <tomas.winkler@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-16 10:24:01 +08:00
Peter Fang 2202b7f578 dm: virtio: reject requests that violate the virtio-block spec
VirtIO v1.0 spec 04 5.2.5:
- Protocol unit size is always 512 bytes.
- blk_size (logical block size) and physical_block_exp (physical block
  size) do not affect the units in the protocol, only performance.

VirtIO v1.0 spec 04 5.2.6.1:
- A driver MUST NOT submit a request which would cause a read or write
  beyond capacity.

Reject the requests that violate these terms.

v1 -> v2:
- add more comments for clarity

Tracked-On: #1422
Signed-off-by: Peter Fang <peter.fang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-15 22:20:04 +08:00
Peter Fang ba4e72bd0a dm: virtio: add debugging information in virtio-blk
Output debugging message when virtio-blk completes with error.

v1 -> v2:
- fix coding style
- refine debugging message

Tracked-On: #1422
Signed-off-by: Peter Fang <peter.fang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-15 22:20:04 +08:00
Peter Fang 7101ce87a7 dm: storage: remove GEOM support
There is no GEOM framework in Linux. Remove dead code.

v1 -> v2:
- complete removal of the entire GEOM logic

Tracked-On: #1422
Signed-off-by: Peter Fang <peter.fang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-15 22:20:04 +08:00
Binbin Wu f9a163954d dm: passthru: fix hardcoded nhlt table length
NHLT table contains the settings some audio drivers need.
An ACPI method is used to get NHLT table address & length.
In current DM code, the NHLT talbe length in the ACPI method
is hardcoded, which will cause troubles when the length of the
table changed.
This patch replaces the hardcoded NHLT table length according to
the table length read from SOS.

Tracked-On: #1461
Signed-off-by: Binbin Wu <binbin.wu@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-10-15 13:44:48 +08:00
Yu Wang 203016b406 dm: passthru: correct the name of xdci dsdt write function
The write_dsdt_xhci function is use for describe the xdci dsdt table.
Correct its name.

Tracked-On: #1444
Signed-off-by: Yu Wang <yu1.wang@intel.com>
Reviewed-by: Binbin Wu <binbin.wu@intel.com>
2018-10-12 16:30:57 +08:00
Jian Jun Chen b2dc13d763 dm: virtio: use the correct register size
movb is used for registers STATUS and CFGGENERATION whose size is 1
byte. Previously hv cannot report the correct MMIO trap size for
movb and virtio hard coded their size to 4 as a workaround. hv fixed
movb instruction emulation and MMIO size can be reported correctly.
This patch removes those workaround.

commit 9df8790ffc ("hv: Fix two minor issues in instruction emulation code")

Tracked-On: #1449
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-10-12 14:41:59 +08:00
Binbin Wu 3c57532598 dm: passthru: add deinit_msix_table
Add a function to do msix table deinit.
 1. call api to reset msix entry in hypervisor
 2. free virtual msix table memory
 3. unmap pba page if any
 4. unmap the pages passhtru to uos in MSIX BAR if any

Tracked-On: #1222
Signed-off-by: Binbin Wu <binbin.wu@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-10-12 13:22:32 +08:00
Binbin Wu 244bce756b dm: passthru: enable pba emulation for msix
Normally, for devices support MSI-X, PBA is passed-through to guest.
However, PBA and MSI-X table share the same bar, and part of PBA and
MSI-X table may share a same page for some devices.
If that is the case, the part of PBA within the page should be emulated
rather than passed-through.
This patch adds PBA emulation support for MSI-X.

Tracked-On: #1222
Signed-off-by: Binbin Wu <binbin.wu@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-10-12 13:22:32 +08:00