]> xenbits.xensource.com Git - unikraft/unikraft.git/log
unikraft/unikraft.git
6 years agodriver/virtio: Host notify and ring desc debug msg
Sharan Santhanam [Tue, 4 Dec 2018 14:10:35 +0000 (15:10 +0100)]
driver/virtio: Host notify and ring desc debug msg

We provide additional debug message when notify the host of
additional buffer and the descriptor information while enqueuing
a buffer into the ring.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/virtio: Use padded buffer for tx and rx
Sharan Santhanam [Tue, 4 Dec 2018 13:55:55 +0000 (14:55 +0100)]
plat/virtio: Use padded buffer for tx and rx

We introduce buffer padding while transmitting and receiving data. We
explicitly introduce padding to make sure that each network packet
needs two descriptors (one for virtio header and another for
network packet).

According the specification 5.1.6.6, we need to explicitly use 2
descriptor for each transmit and receive network packet since we do not
negotiate for VIRTIO_F_ANY_LAYOUT.

In the previous implementation the sg list merged the two descriptor
into one as the memory region were contiguous.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agodriver/virtio: Replace malloc with calloc
Sharan Santhanam [Tue, 4 Dec 2018 13:54:28 +0000 (14:54 +0100)]
driver/virtio: Replace malloc with calloc

We replace malloc with calloc to zero out the allocated memory.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agodriver/virtio: Configure the max desc as default
Sharan Santhanam [Tue, 4 Dec 2018 13:53:13 +0000 (14:53 +0100)]
driver/virtio: Configure the max desc as default

As a part of this patch, we configure the max queue size as the
configuration for the number descriptor if the user set the number
of descriptors to zero.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agolib/uknetdev: Zero-initialize netdev data
Simon Kuenzer [Mon, 3 Dec 2018 10:23:18 +0000 (11:23 +0100)]
lib/uknetdev: Zero-initialize netdev data

Whenever a network device is registered by a driver to the uknetdev
API, libuknetdev allocates an API-internal data structure that is used
to track the state of the device state. Subsequent API calls are
assuming that this allocation was zero-initialized. Otherwise,
assertions fail unexpectedly.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agoplat/kvm: Make mxcsr_ptr in entry64.S a 32-bit value
Florian Schmidt [Mon, 17 Dec 2018 09:46:16 +0000 (10:46 +0100)]
plat/kvm: Make mxcsr_ptr in entry64.S a 32-bit value

LDMXCSR reads 32 bits into the register. If mxcsr_ptr is only a .word
(and thus 16 bits), the instruction reads adjacent bytes into the MXCSR
register, which can to produce #GP faults on LDMXCSR when those adjacent
bytes contain 1's in bit locations that are reserved in MXCSR.

Signed-off-by: Florian Schmidt <florian.schmidt@neclab.eu>
Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
6 years agoarch/x86: add -mtune for ASFLAGS
Florian Schmidt [Mon, 17 Dec 2018 09:46:15 +0000 (10:46 +0100)]
arch/x86: add -mtune for ASFLAGS

This provides the preprocessor with compiler-provided defines such as
__AVX__.

Signed-off-by: Florian Schmidt <florian.schmidt@neclab.eu>
Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
6 years agoplat/virtio: Update off-by-one device id
Cristian Banu [Fri, 7 Dec 2018 05:19:00 +0000 (07:19 +0200)]
plat/virtio: Update off-by-one device id

Extract the virtio_device_id for legacy devices from the PCI Subsystem
Device ID. The previous behaviour resulted in some devices having the
wrong ID attributed to them. For example, a virtio-9p device has a PCI
Device ID of 0x1009 (which would have resulted in virtio_device_id of
10), but a PCI Subsystem Device ID of 9 (which is the correct constant
under virtio_ids.h).

Removes now unused function virtio_device_id_add and misleading macro
VIRTIO_PCI_LEGACY_DEVICEID_START.

Signed-off-by: Cristian Banu <cristb@gmail.com>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agoplat/virtio: Fix virtio-bus init getting hanged
Cristian Banu [Wed, 5 Dec 2018 14:27:55 +0000 (16:27 +0200)]
plat/virtio: Fix virtio-bus init getting hanged

This patch fixes getting hanged in virtio-bus initialization. The inner
while loop does not iterate through all the dev_ids, and failing to find
a match against the first dev_id results in an infinite loop.

Signed-off-by: Cristian Banu <cristb@gmail.com>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agoplat/xen/xenbus: Add _GNU_SOURCE define when using asprintf
Bogdan Lascu [Sat, 24 Nov 2018 13:05:18 +0000 (15:05 +0200)]
plat/xen/xenbus: Add _GNU_SOURCE define when using asprintf

Compiling xenbus.c and xs.c gives the warning "implicit definition
of asprintf". Asprintf is not C nor POSIX, so its declaration is
conditioned by a header define that is activated by defining _GNU_SOURCE
before including stdio.h.

Signed-off-by: Bogdan Lascu <lascu.bogdan96@gmail.com>
Signed-off-by: Mihai Pogonaru <pogonarumihai@gmail.com>
Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>
6 years agoplat/kvm: Make VIRTIO_NET depend on VIRTIO_BUS
Teodora Serbanescu [Sat, 24 Nov 2018 13:08:25 +0000 (15:08 +0200)]
plat/kvm: Make VIRTIO_NET depend on VIRTIO_BUS

This is the setup to reproduce the bug:
Library Configuration -> enable uknetdev
Platform Configuration -> enable KVM guest:
-> disable Virtio bus driver
-> Virtio -> enable Virtio Net device

With this  setup, the following error occurs on build:
"undefined reference to ` _virtio_bus_register_driver'"

This fix solves the issue by enabling Virtio bus driver every time
Virtio Net device is enabled.

Signed-off-by: Teodora Serbanescu <teo.serbanescu16@gmail.com>
Signed-off-by: Andrei Gogonea <andrei.gogonea09@gmail.com>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agoplat/xen/hypervisor.c: Remove unused parameter
Radu Nicolau [Sat, 24 Nov 2018 11:23:23 +0000 (13:23 +0200)]
plat/xen/hypervisor.c: Remove unused parameter

Removed unused parameter cpu from macro active_evtchns

Signed-off-by: Radu Nicolau <radunicolau102@gmail.com>
Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>
6 years agoplat/xen/common/hypervisor: Delete unused code and comments
Radu Nicolau [Sat, 24 Nov 2018 11:23:22 +0000 (13:23 +0200)]
plat/xen/common/hypervisor: Delete unused code and comments

Delete unused code and deprecated comments

Signed-off-by: Radu Nicolau <radunicolau102@gmail.com>
Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>
6 years agoplat/xen/common: Move event channel functions in events.h
Radu Nicolau [Sat, 24 Nov 2018 11:23:21 +0000 (13:23 +0200)]
plat/xen/common: Move event channel functions in events.h

Move mask_evtchn, unmask_evtchn and clear_evtchn function
prototypes from hypervisor.h to events.h. Change parameter
type to evtchn_port_t. Remove hypervisor.h inclusion from
arm/arch_events.c and arm/arch_time.c

Signed-off-by: Radu Nicolau <radunicolau102@gmail.com>
Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>
6 years agoinclude/xen-x86: Remove os.h on x86
Radu Nicolau [Sat, 24 Nov 2018 11:23:20 +0000 (13:23 +0200)]
include/xen-x86: Remove os.h on x86

Remove os.h from the project as it was unused.
mm_pv.h included os.h but did not use anything from
it. The rest of the changes have been made in sources
which need the extern definition for the shared info
page.

Signed-off-by: Radu Nicolau <radunicolau102@gmail.com>
Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>
6 years agoplat/xen: Add flush for xen console
Birlea Costin [Thu, 8 Nov 2018 14:51:56 +0000 (16:51 +0200)]
plat/xen: Add flush for xen console

Add flush function for xen console. Shutdown can be requested
before the hypervisor gets to print everything to the console
and stops trying. This happens in ukutest and does not get to
print Passed(x/y). This patch assures everything is written
before shutting down.

Signed-off-by: Birlea Costin <costin.birlea@gmail.com>
Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
6 years agoinclude/uk/list.h: Replace non-existing panic() calls to UK_CRASH()
Vlad-Andrei BĂDOIU [Thu, 18 Oct 2018 12:14:05 +0000 (12:14 +0000)]
include/uk/list.h: Replace non-existing panic() calls to UK_CRASH()

These panic() calls are copy-paste artifacts. We do not have the
panic() function. It was working so far, because it is used only in
the lists sanity checking code. Which currently is not even possible
to enable.

Signed-off-by: Vlad-Andrei BĂDOIU <vlad_andrei.badoiu@stud.acs.upb.ro>
Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
6 years agobuild: Give CROSS_COMPILE from command line highest priority
Dafna Hirschfeld [Sat, 20 Oct 2018 12:25:42 +0000 (15:25 +0300)]
build: Give CROSS_COMPILE from command line highest priority

Assign CONFIG_CROSS_COMPILE to CROSS_COMPILE only
if CROSS_COMPILE is defined, so that CONFIG_CROSS_COMPILE
will not be erased in case it was set in `.config`

Signed-off-by: Dafna Hirschfeld <dafna3@gmail.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/drivers: Receive and Transmit operations
Sharan Santhanam [Thu, 25 Oct 2018 09:49:53 +0000 (11:49 +0200)]
plat/drivers: Receive and Transmit operations

This patch add the transmission and receive operation for the
virtio-net device. We extend the scatter gather list to operate
on the netbuf.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@gmail.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agolib/uknetdev: Add driver encapsulation for rx & tx
Sharan Santhanam [Thu, 25 Oct 2018 09:49:52 +0000 (11:49 +0200)]
lib/uknetdev: Add driver encapsulation for rx & tx

The patch provides the option for the network driver to reserve headroom
separately for transmission and reception part of a net device.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/drivers: Starting the virtio device
Sharan Santhanam [Thu, 25 Oct 2018 09:49:51 +0000 (11:49 +0200)]
plat/drivers: Starting the virtio device

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@gmail.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/drivers: Configure receive queue interrupt
Sharan Santhanam [Thu, 25 Oct 2018 09:49:50 +0000 (11:49 +0200)]
plat/drivers: Configure receive queue interrupt

The patch implements enable and disabling interrupt on the receive
queue.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@gmail.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/drivers: Configuring the transmit queue
Sharan Santhanam [Thu, 25 Oct 2018 09:49:49 +0000 (11:49 +0200)]
plat/drivers: Configuring the transmit queue

The patch introduces the virtio net device implementation for
configuring the transmit queue

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@gmail.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/drivers: Configure the receive queue
Sharan Santhanam [Thu, 25 Oct 2018 09:49:48 +0000 (11:49 +0200)]
plat/drivers: Configure the receive queue

The patch introduces the virtio implementation for setting up the
receive queue.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@gmail.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/drivers: Configure virtio-net device
Sharan Santhanam [Thu, 25 Oct 2018 09:49:47 +0000 (11:49 +0200)]
plat/drivers: Configure virtio-net device

This patch provides the implementation callbacks to configure the
virtio device from libuknet

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@gmail.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/drivers: Introduce the virtio-net device
Sharan Santhanam [Thu, 25 Oct 2018 09:49:46 +0000 (11:49 +0200)]
plat/drivers: Introduce the virtio-net device

This patch introduces the virtio net driver initialization, the API
functions callback to interact with the libuknet.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@gmail.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/drivers: Add & Remove buffer from virtio-ring
Sharan Santhanam [Wed, 24 Oct 2018 13:42:33 +0000 (15:42 +0200)]
plat/drivers: Add & Remove buffer from virtio-ring

The user buffer are enqueued and dequeued into the virtio-ring.
The user data is described to the virtio-ring using a scatter/gather
list. The enqueue and dequeue in turn uses the ring descriptor for
each segment of the scatter gather list.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/drivers: Interrupt handling for virtio-ring
Sharan Santhanam [Wed, 24 Oct 2018 13:42:32 +0000 (15:42 +0200)]
plat/drivers: Interrupt handling for virtio-ring

This patch introduces the API for handling the interrupt on the virtio PCI
device. It provides handler for the virtqueue rings. The handler identifies
the virtio device owning the virtqueue and invokes the callback handler
configured by the virtio device.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/drivers: Reintroduce the virtio ring
Sharan Santhanam [Wed, 24 Oct 2018 13:42:31 +0000 (15:42 +0200)]
plat/drivers: Reintroduce the virtio ring

This patch introduces the API to create destroy the virtio ring. The
configuration API for find the number of queues and setting up
individual queues for a device.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/drivers: Introduce virtio PCI device
Sharan Santhanam [Wed, 24 Oct 2018 13:42:30 +0000 (15:42 +0200)]
plat/drivers: Introduce virtio PCI device

We introduces support for virtio PCI legacy device support in this
patch. The driver register on the PCI bus to probe for device with
QUMRANET vendor id. The virtio PCI bus adds the virtio dev. The
virtio bus is responsible for bridging the virtio device with the
driver. The virtio PCI device provides configuration callback for
the PCI bus operation performed on the virtio device. Currently we
add support to the KVM platform

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/drivers: Introduce the virtio bus
Sharan Santhanam [Wed, 24 Oct 2018 13:42:29 +0000 (15:42 +0200)]
plat/drivers: Introduce the virtio bus

This patch introduces the virtio bus to bridge the virtio device with
the bus. We introduce the functions to add driver to control the virtio
device.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/common: Introduce virtio standard header
Sharan Santhanam [Wed, 24 Oct 2018 13:42:28 +0000 (15:42 +0200)]
plat/common: Introduce virtio standard header

We introduce the standard virtio header files.
* virtio_ids: List the ids of the virtio devices
* virtio_ring.h: Describes the virtio ring descriptor, used and
 available descriptors.
* virtio_pci.h: Describes the virtio PCI device register map.
* virtio_types.h:  Describes the type of the data structure.
* virtio_config.h: Provides helper function to perform IO
operation on the device.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/driver: Remove the virtio-ring implementation
Sharan Santhanam [Wed, 24 Oct 2018 13:42:27 +0000 (15:42 +0200)]
plat/driver: Remove the virtio-ring implementation

As a part of revamping the virtio layer, we are removing the existing
implementation of virtio ring driver. The virtio ring driver adapted to
the new virtio API will reintroduced later in this patch series

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/common: arm: Include correct inline function __uk_test_and_clear_bit
Wei Chen [Fri, 19 Oct 2018 07:47:56 +0000 (07:47 +0000)]
plat/common: arm: Include correct inline function __uk_test_and_clear_bit

As __uk_test_and_clear_bit has been moved to uk/bitops.h, the time.c could
not find this function from atomic.h. This will cause Arm64 build failed:

  LD      unikraft_kvm-arm64
/root/UF/unikraft/build/unikraft_kvm-arm64.o: In function `time_block_until':
:(.text+0x400): undefined reference to `__uk_test_and_clear_bit'
:(.text+0x400): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `__uk_test_and_clear_bit'
collect2: error: ld returned 1 exit status
/root/UF/unikraft/plat/kvm/Linker.uk:17: recipe for target '/root/UF/unikraft/build/unikraft_kvm-arm64' failed
make: *** [/root/UF/unikraft/build/unikraft_kvm-arm64] Error 1

Change atomic.h to bitops.h to solve this problem.

Signed-off-by: Wei Chen <wei.chen@arm.com>
Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
6 years agolib/uknetdev: Packet reception and transmission interfaces
Razvan Cojocaru [Fri, 19 Oct 2018 09:43:45 +0000 (11:43 +0200)]
lib/uknetdev: Packet reception and transmission interfaces

Introduce interfaces for single packet transmission and
reception. Both interfaces are designed to support asynchronous
zero-copy operation with netbufs. Receiving can be done with
interrupts or with polling. Transmission supports only polling mode
for now.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@gmail.com>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agolib/uknetdev: MTU interfaces
Razvan Cojocaru [Fri, 19 Oct 2018 09:43:44 +0000 (11:43 +0200)]
lib/uknetdev: MTU interfaces

Add interfaces to query and set the maximum transmission unit (MTU)
for a netdev. The getter is a mandatory interface to implement by
drivers.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@gmail.com>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agolib/uknetdev: Promiscuous mode interfaces
Razvan Cojocaru [Fri, 19 Oct 2018 09:43:43 +0000 (11:43 +0200)]
lib/uknetdev: Promiscuous mode interfaces

Add interfaces to query, enable, and disable promiscuous mode for a
netdev. The getter is a mandatory interface to implement by drivers.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@gmail.com>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agolib/uknetdev: Hardware address interfaces
Razvan Cojocaru [Fri, 19 Oct 2018 09:43:42 +0000 (11:43 +0200)]
lib/uknetdev: Hardware address interfaces

Add a getter and a setter for a netdev's hardware address (MAC). This
API interface is optional for a driver to implement. By making this
optional we could support network devices that operate on L3 in the
future.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@gmail.com>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agolib/uknetdev: Netdev initialization
Razvan Cojocaru [Fri, 19 Oct 2018 09:43:41 +0000 (11:43 +0200)]
lib/uknetdev: Netdev initialization

Introduce a 'DPDK RTE Ethernet' inspired API for initializing a
Unikraft network device. The initialization is done in the following
order: (1) Configure main aspects of device (e.g., number of
queues), (2) configure each transmit and receive queue, and (3) start
the device. We also introduce an interface for querying the underlying
device capabilities for each configuration step.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@gmail.com>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agolib/uknetdev: Netdev registration
Razvan Cojocaru [Fri, 19 Oct 2018 09:43:40 +0000 (11:43 +0200)]
lib/uknetdev: Netdev registration

Introduce initial netdev API supporting device registration. We
introduce three header files are introduced for describing Unikraft's
netdev API:
  uk/netdev_core.h - Core data type definitions
  uk/netdev_driver.h - API for drivers
  uk/netdev.h - API for network applications and stacks

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@gmail.com>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agolib/uknetdev: Netbuf headroom and tailroom helpers
Simon Kuenzer [Fri, 19 Oct 2018 09:43:39 +0000 (11:43 +0200)]
lib/uknetdev: Netbuf headroom and tailroom helpers

Introduce helpers for calculating available headroom and tailroom on a
Netbuf's data buffer. A header manipulation function is added to
simplify prepending bytes to the packet data or claiming bytes back to
the headroom.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agolib/uknetdev: Netbuf refcounting and releasing
Simon Kuenzer [Fri, 19 Oct 2018 09:43:38 +0000 (11:43 +0200)]
lib/uknetdev: Netbuf refcounting and releasing

Introduce reference counting and buffer releasing with Netbufs.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agolib/uknetdev: Netbuf chaining
Simon Kuenzer [Fri, 19 Oct 2018 09:43:37 +0000 (11:43 +0200)]
lib/uknetdev: Netbuf chaining

Introduce functions for creating and operating netbuf chains. With
this, network packet data that is scattered in memory can be
described.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agolib/uknetdev: Introduce Netbufs
Simon Kuenzer [Fri, 19 Oct 2018 09:43:36 +0000 (11:43 +0200)]
lib/uknetdev: Introduce Netbufs

Adds `struct uk_netbuf`, a structure for describing network
packets. It is designed to support zero-copy operation and simple
embedding to existing network stacks. Netbufs can be (1) initialized
on user-supplied memory regions, intended for network stacks that come
with a packet buffer allocator, or (2) uk_alloc-based allocation.

This commit introduces the netbuf struct and intialization and
allocation functions.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agolib/uknetdev: Library skeleton
Razvan Cojocaru [Fri, 19 Oct 2018 09:43:35 +0000 (11:43 +0200)]
lib/uknetdev: Library skeleton

Add and register libuknetdev library skeleton.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@gmail.com>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agobuild: Support for static libraries
Simon Kuenzer [Thu, 18 Oct 2018 09:29:09 +0000 (11:29 +0200)]
build: Support for static libraries

Introduce support for linking (externally built) static libraries.

A static library can be registered at three different places:
 * [LIBNAME]_ALIBS and [LIBNAME]_ALIBS-y
   static libraries used when (pre-)linking a library object
 * [PLATNAME]_ALIBS and [PLATNAME]_ALIBS-y
   static libraries that are linked at the final linking step but only
   for a specific platform
 * UK_ALIBS and UK_ALIBS-y
   static libraries that are linked at the final linking step

While the link order of object files is irrelevant to the linker,
static libraries are handled differently. During linking, static
libraries are only visited once. The only objects taken are those
that resolve at least one yet unresolved symbol. Because of this,
we populate the list of static libraries right after populating all
relevant object files.

Any order or circular dependency within a group of static libraries
is resolved by instructing the linker to scan the archives multiple
times. This is done by the --start-group and --end-group linker flags.

With this change, we also remove the UK_LINK and UK_LINK-y variables
that were used to simplify the platform's linker scripts. Because of
the link order and additional linker flags, we directly assemble the
linker command by taken the items from the corresponding OLIBS and
ALIBS lists.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
6 years agoinclude/uk: merge two bitops functions
Yuri Volchkov [Wed, 10 Oct 2018 12:43:57 +0000 (14:43 +0200)]
include/uk: merge two bitops functions

Unikraft currently has two sets of bit operations. This patch merges
them together.

Signed-off-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
Reviewed-by: Florian Schmidt <florian.schmidt@neclab.eu>
6 years agouse one api for bit operation
Yuri Volchkov [Wed, 10 Oct 2018 12:43:56 +0000 (14:43 +0200)]
use one api for bit operation

Currently we have 2 different APIs for bit operations. Let's use only
one - the one which is richer.

Signed-off-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
Reviewed-by: Florian Schmidt <florian.schmidt@neclab.eu>
6 years agoinclude/uk: fix test_bit atomicity
Yuri Volchkov [Wed, 10 Oct 2018 12:43:55 +0000 (14:43 +0200)]
include/uk: fix test_bit atomicity

ukarch_test_bit_sync does not make sense. A barrier() call is not a
memory barrier as was said in the comment. Even if it it was, it would
not make ukarch_test_bit_sync atomic.

This commit merges these two function together, and adds a missing
uk_test_bit into bitops.h.

Signed-off-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
Reviewed-by: Florian Schmidt <florian.schmidt@neclab.eu>
6 years agoinclude/uk: do not cast away volatile in atomic.h
Yuri Volchkov [Wed, 10 Oct 2018 12:43:54 +0000 (14:43 +0200)]
include/uk: do not cast away volatile in atomic.h

Many functions in include/uk/arch/atomic.h accept a volatile argument
and then cast it to something like "__u8 *". In many cases it is ok,
__atomic_*() is called inside the function. But in other cases, this
memory access is a subject to compiler optimization, and may lead to
an unexpected behavior.

Signed-off-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
Reviewed-by: Florian Schmidt <florian.schmidt@neclab.eu>
6 years agoplat/common: PCI bus probes the device identifier
Sharan Santhanam [Mon, 1 Oct 2018 14:18:34 +0000 (16:18 +0200)]
plat/common: PCI bus probes the device identifier

While probing the devices on the pci bus, the device identifier are
read from the configuration space. The pci device is identified with
* class_id
* vendor_id
* device_id
* subsystem_id
* subsystemvendor_id

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agolib/uksglist: A scatter/gather list data structure
Sharan Santhanam [Fri, 28 Sep 2018 18:15:02 +0000 (20:15 +0200)]
lib/uksglist: A scatter/gather list data structure

A scatter/gather list is a list of vectors with each describing the
location and length of one contiguous physical memory region. Scatter
gather lists are helpful for setting up I/O requests with devices.
The sg list provides support for the following operations:
  uk_sglist_init
  uk_sglist_reset
  uk_sglist_count
  uk_sglist_alloc
  uk_sglist_free
  uk_sglist_append
  uk_sglist_append_sglist
  uk_sglist_build
  uk_sglist_clone
  uk_sglist_length
  uk_sglist_split
  uk_sglist_join
  uk_sglist_slice

Taken and modified from FreeBSD source commit-id: 4736ccfd9c3

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
NOTE:
Please be aware that this patch uses the update uk_pr_* macros.
Please make sure the patch series "Update libukdebug printing" is reviewed before this patch.

6 years agoplat/*: Export address conversion with ukplat_virt_to_phys()
Sharan Santhanam [Fri, 28 Sep 2018 16:20:33 +0000 (18:20 +0200)]
plat/*: Export address conversion with ukplat_virt_to_phys()

ukplat_virt_to_phys() is promoted as a standard platform API and each
platform provides it's own function to convert the virtual address to
physical address.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agolib/ukboot: Correct line ending of UK_CRASH() messages
Simon Kuenzer [Fri, 28 Sep 2018 13:25:07 +0000 (15:25 +0200)]
lib/ukboot: Correct line ending of UK_CRASH() messages

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agolib/ukdebug: Remove unused uk_printkd()
Simon Kuenzer [Thu, 27 Sep 2018 12:41:11 +0000 (14:41 +0200)]
lib/ukdebug: Remove unused uk_printkd()

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agoplat/*: Replace uk_printd() with uk_pr_*() equivalents
Simon Kuenzer [Thu, 27 Sep 2018 12:41:10 +0000 (14:41 +0200)]
plat/*: Replace uk_printd() with uk_pr_*() equivalents

Replace all occurrences of uk_printk() with uk_pr_*() equivalents:
 uk_printd(DLVL_CRIT, ...)  --> uk_pr_crit(...)
 uk_printd(DLVL_ERROR, ...) --> uk_pr_err(...)
 uk_printd(DLVL_WARN, ...)  --> uk_pr_warn(...)
 uk_printd(DLVL_INFO, ...)  --> uk_pr_info(...)
 uk_printd(DLVL_EXTRA, ...) --> uk_pr_debug(...)

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agoplat/*: Replace uk_printk() with uk_pr_*() equivalents
Simon Kuenzer [Thu, 27 Sep 2018 12:41:09 +0000 (14:41 +0200)]
plat/*: Replace uk_printk() with uk_pr_*() equivalents

Replace all occurrences of uk_printk() with reasonable uk_pr_*()
equivalents. An exception is in LinuxU platform. The platform's
command line interaction (e.g., `-h`, `-V`) is going to use standard
output.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agoplat/linuxu: Use ukplat_coutk() for command line interaction
Simon Kuenzer [Thu, 27 Sep 2018 12:41:08 +0000 (14:41 +0200)]
plat/linuxu: Use ukplat_coutk() for command line interaction

The platform's command line interaction (e.g., `-h`, `-V`) should
actually use stdio to print messages. printf() would be suitable for
this. However, since this is provided by a libc, it may not be
initialized. Because of this we use ukplat_coutk directly.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agolib/ukdebug: Move 'Calling main...' message before calling main
Simon Kuenzer [Thu, 27 Sep 2018 12:41:07 +0000 (14:41 +0200)]
lib/ukdebug: Move 'Calling main...' message before calling main

Move the 'Calling main' info message right before actually calling
main.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agolib/ukboot: Use printf() for banner and weak main()
Simon Kuenzer [Thu, 27 Sep 2018 12:41:06 +0000 (14:41 +0200)]
lib/ukboot: Use printf() for banner and weak main()

Instead of using libukdebug's kernel console we print directly to
stdout with printf(). This makes the libukboot banner independent of
any print level configuration from libukdebug.  To make sure that the
corresponding libc had the chance to initialize its printf(), we move
the banner right before calling main.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agolib/ukdebug: Introduce uk_pr_*() wrapper for uk_printd()
Simon Kuenzer [Thu, 27 Sep 2018 12:41:05 +0000 (14:41 +0200)]
lib/ukdebug: Introduce uk_pr_*() wrapper for uk_printd()

Similar to Linux's printing wrappers pr_*() we introduce printing
wrappers for the libukdebug:

 uk_pr_debug(fmt, ...) - does uk_printd(DLVL_EXTRA, fmt, ...)
 uk_pr_info(fmt, ...)  - does uk_printd(DLVL_INFO, fmt, ...)
 uk_pr_warn(fmt, ...)  - does uk_printd(DLVL_WARN, fmt, ...)
 uk_pr_err(fmt, ...)   - does uk_printd(DLVL_ERR, fmt, ...)
 uk_pr_crit(fmt, ...)  - does uk_printd(DLVL_CRIT, fmt, ...)

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
6 years agobuild: choose arch-includes at makefile level
Yuri Volchkov [Fri, 21 Sep 2018 15:11:15 +0000 (17:11 +0200)]
build: choose arch-includes at makefile level

Instead of adding multiple ifdefs in the headers in order to choose a
header specific to current architecture, include
<uk/asm/arch_specific_header.h>. This will automatically resolve to
the correct header, via -I flags provided to compiler.

This also moves the arch headers in
arch/<arch_family>/<arch_name>/uk/asm

Signed-off-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agodoc: introduce unikraft logo
Alina Volchkova [Mon, 1 Oct 2018 12:48:34 +0000 (14:48 +0200)]
doc: introduce unikraft logo

Signed-off-by: Alina Volchkova <volchokaline@gmail.com>
6 years agolib/nolibc: don't include uk/plat/time.h from time.h
Dafna Hirschfeld [Sun, 23 Sep 2018 14:38:27 +0000 (17:38 +0300)]
lib/nolibc: don't include uk/plat/time.h from time.h

Including uk/plat/time.h in time.h of nolibc expose
platform's symbols such as ukplat_monotonic_clock
which are not part of libc.
Instead, uk/plat/time.h should be included directly
from time.c in nolibc

Signed-off-by: Dafna Hirschfeld <dafna3@gmail.com>
Reviewed-by: Florian Schmidt <florian.schmidt@neclab.eu>
6 years agolib/vfscore: Declare file operations as const
Simon Kuenzer [Thu, 23 Aug 2018 09:52:48 +0000 (11:52 +0200)]
lib/vfscore: Declare file operations as const

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
6 years agolib/vfscore: Make library un-selectable
Simon Kuenzer [Thu, 23 Aug 2018 09:49:25 +0000 (11:49 +0200)]
lib/vfscore: Make library un-selectable

This patch adds the option to unselect the vfscore library from builds.
In order to be inline with the Unikraft principle that "everything that
is not needed should be off", vfscore is unselected as default.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
6 years agoplat/xen: Export _xenbus_register_driver function
Costin Lupu [Tue, 18 Sep 2018 11:44:11 +0000 (14:44 +0300)]
plat/xen: Export _xenbus_register_driver function

Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
6 years agoplat/xen: Add driver state functions to client API
Costin Lupu [Mon, 17 Sep 2018 10:32:31 +0000 (13:32 +0300)]
plat/xen: Add driver state functions to client API

Extend the client API with functions for dealing with Xenbus driver
states.

Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
6 years agoplat/xen: Add Xenbus device probing
Costin Lupu [Mon, 17 Sep 2018 10:32:30 +0000 (13:32 +0300)]
plat/xen: Add Xenbus device probing

Extend the Xenbus bus driver with support for probing Xenbus
devices.

Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
6 years agoplat/xen: Add Xenstore watch support
Costin Lupu [Mon, 17 Sep 2018 10:32:29 +0000 (13:32 +0300)]
plat/xen: Add Xenstore watch support

Add support for processing Xenstore watch events coming from the
Xenstore daemon.

Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
6 years agoplat/xen: Introduce Xenbus watch
Costin Lupu [Mon, 17 Sep 2018 10:32:28 +0000 (13:32 +0300)]
plat/xen: Introduce Xenbus watch

Introduce the abstraction for Xenbus watches.

Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
6 years agoplat/xen: Introduce client API for Xenbus drivers
Costin Lupu [Mon, 17 Sep 2018 10:32:27 +0000 (13:32 +0300)]
plat/xen: Introduce client API for Xenbus drivers

Introduce the API needed by frontend drivers that require
communication with their backend counteparts.

Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
6 years agoplat/xen: Add API for Xenstore messages
Costin Lupu [Mon, 17 Sep 2018 10:32:26 +0000 (13:32 +0300)]
plat/xen: Add API for Xenstore messages

Add the API needed for sending Xenstore messages. These functions
are used by any client communicating with the Xenstore daemon.

Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
6 years agoplat/xen: Add support for communication with Xenstore daemon
Costin Lupu [Mon, 17 Sep 2018 10:32:25 +0000 (13:32 +0300)]
plat/xen: Add support for communication with Xenstore daemon

Add support for communication with Xenstore daemon via the shared
page. In Unikraft, the incoming messages are processed by the
Xenstore thread.

Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
6 years agoplat/common: Get arch_timer clock frequency from DT for Arm
Wei Chen [Fri, 14 Sep 2018 07:57:10 +0000 (07:57 +0000)]
plat/common: Get arch_timer clock frequency from DT for Arm

On a few platforms the frequency is not configured correctly
by the firmware. A property in the DT (clock-frequency) has
been introduced to workaround those firmware. So, we will try
to get clock-frequency from DT first, if failed we will read
the register directly.

Signed-off-by: Wei Chen <wei.chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoarch/arm64: Add function for stack pointer retrieval
Wei Chen [Fri, 14 Sep 2018 07:57:08 +0000 (07:57 +0000)]
arch/arm64: Add function for stack pointer retrieval

The ukdebug will print bottom address of stack in
debug messages. So we just implement this function
for Arm64 to retrieve stack pointer.

Signed-off-by: Wei Chen <wei.chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/kvm: Implement time_block_until for arm64
Wei Chen [Fri, 14 Sep 2018 07:57:06 +0000 (07:57 +0000)]
plat/kvm: Implement time_block_until for arm64

As we haven't implement full functions for timer for arm64.
But this function is needed by Unikraft. So we impplement
a temporary function to make compiler happy.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/kvm: Update linker.uk to link image for Arm64
Wei Chen [Fri, 14 Sep 2018 07:57:05 +0000 (07:57 +0000)]
plat/kvm: Update linker.uk to link image for Arm64

Update linker.uk to support link Arm64 image to aarch64elf
format.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/kvm: Build pci bus for x86_64 only
Wei Chen [Fri, 14 Sep 2018 07:57:07 +0000 (07:57 +0000)]
plat/kvm: Build pci bus for x86_64 only

PCI bus on Arm64 has not been ready, so we have to disable
it for Arm64 at this stage.

Signed-off-by: Wei Chen <wei.chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/kvm: Switch away from boot stack (Arm64)
Wei Chen [Fri, 14 Sep 2018 07:57:04 +0000 (07:57 +0000)]
plat/kvm: Switch away from boot stack (Arm64)

The boot stack is used for system initialization. This size
is limited, after we have done the initialization, we should
switch away from it as soon as possible. We will use the
memory top as the new stack's top address.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/kvm: Implement shutdown for Arm64
Wei Chen [Fri, 14 Sep 2018 07:57:03 +0000 (07:57 +0000)]
plat/kvm: Implement shutdown for Arm64

QEMU/KVM provide a PSCI interface for virtual machine on
Arm64 platform. So we use this interface to implement
platform system off function.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/x86: Implement system_off for x86
Wei Chen [Fri, 14 Sep 2018 07:57:02 +0000 (07:57 +0000)]
plat/x86: Implement system_off for x86

Implement system_off for x86 can make shutdown.c become
architecture independent.

Signed-off-by: Wei Chen <wei.chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/common: Implement system off for arm64
Wei Chen [Fri, 14 Sep 2018 07:57:01 +0000 (07:57 +0000)]
plat/common: Implement system off for arm64

Using PSCI despatch function to call PSCI_SYSTEM_OFF
function to shutdown system.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/common: Implement CPU reset for arm64
Wei Chen [Fri, 14 Sep 2018 07:57:00 +0000 (07:57 +0000)]
plat/common: Implement CPU reset for arm64

Using PSCI despatch function to call PSCI_CPU_RESET
function to reset CPU.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/common: Implement CPU halt function for arm64
Wei Chen [Fri, 14 Sep 2018 07:56:59 +0000 (07:56 +0000)]
plat/common: Implement CPU halt function for arm64

Halts the CPU until the next external interrupt is fired.
For Arm, we can use WFI to implement this feature.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/kvm: Get PSCI conduit method from DTB for Arm64
Wei Chen [Fri, 14 Sep 2018 07:56:58 +0000 (07:56 +0000)]
plat/kvm: Get PSCI conduit method from DTB for Arm64

PSCI supports two conduit method: HVC and SMC. The method
would be set value in device tree's PSCI node. This value
would decide which instruction we should use to call PSCI
functions. We only support PSCI-1.0 and PSCI-0.2 in this
stage.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/common: Implement PSCI despatch functions for arm64
Wei Chen [Fri, 14 Sep 2018 07:56:57 +0000 (07:56 +0000)]
plat/common: Implement PSCI despatch functions for arm64

Implement PSCI dispatch functions for different conduits.
The platforms can select correct despatch function as the
PSCI conduit they are using.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/kvm: Parse memory info from device tree for Arm64
Wei Chen [Fri, 14 Sep 2018 07:56:56 +0000 (07:56 +0000)]
plat/kvm: Parse memory info from device tree for Arm64

QEMU/KVM will store the memory informations like memory
region, memory base address and memory size to device
tree. We parse these informations for memory allocater and
new stack setting. QEMU/KVM will always provide us at least
one bank of memory and unikraft will use the first bank for
the time-being. So currently we only supported one bank.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agonolibc: Add errno.h header for time.c
Wei Chen [Fri, 14 Sep 2018 07:57:09 +0000 (07:57 +0000)]
nolibc: Add errno.h header for time.c

If we don't enable the CONFIG_HAVE_SCHED, we should get the error:
nolibc/time.c:65:3: error: errno undeclared (first use in this function)
   errno = EINVAL;
   ^~~~~
This because the uk/sched.h include the error.h implicitly. So we
add error.h to the headers.

Signed-off-by: Wei Chen <wei.chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/kvm: Parse command line from device tree for Arm64
Wei Chen [Fri, 14 Sep 2018 07:56:55 +0000 (07:56 +0000)]
plat/kvm: Parse command line from device tree for Arm64

Device tree has a "chosen" node, this node can be used to pass
parameters to virtual machine through bootargs property. We can
use this feature to pass command line to unikraft application,
and then parse it from device tree for further usage.

The command line will be modified in uk_argparse, but the memory
attribute of DTB is readonly, we need a copy of this command line.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/kvm: Initialize console from device tree for Arm64
Wei Chen [Fri, 14 Sep 2018 07:56:54 +0000 (07:56 +0000)]
plat/kvm: Initialize console from device tree for Arm64

We have implemented a console for early debug console. We had
hardcode the PL011 UART base address. But, after device tree
is ready, we can initialize console from device tree.

Signed-off-by: Wei Chen <wei.chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/kvm: Initialize device tree for Arm64
Wei Chen [Fri, 14 Sep 2018 07:56:53 +0000 (07:56 +0000)]
plat/kvm: Initialize device tree for Arm64

Arm64 entry code passed the base address of device tree
to _libkvmplat_start. We will check the device tree header
and then save the address for further usage.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/kvm: Enable MMU for Arm64
Wei Chen [Fri, 14 Sep 2018 07:56:52 +0000 (07:56 +0000)]
plat/kvm: Enable MMU for Arm64

QEMU/KVM provides a 1TB physical address for Arm64. In this case,
we should use 40-bit virtual address to map physical address.
In this patch, we enable the MMU to access memory with virtual
address.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/kvm: Create page tables for Arm64
Wei Chen [Fri, 14 Sep 2018 07:56:51 +0000 (07:56 +0000)]
plat/kvm: Create page tables for Arm64

We're design a direct mapping of physical memory and virtual
memory. In order to improve the security, we use mmu to control
the attributes of image sections. The minimal granularity is 4K.
If map entire physical address with 4k pages, the size of page
tables would be very big. So, wo just use 4K page to map the
area when image has been placed, and use 1G or 2M block to map
other memory areas. In this case, the page tables would only
occupy 20KB memory.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/kvm: Add exception table for Arm64
Wei Chen [Fri, 14 Sep 2018 07:56:50 +0000 (07:56 +0000)]
plat/kvm: Add exception table for Arm64

On Arm64, we need SYNC exception handler to handle some exceptions
like access NULL pointer, and we need IRQ exception handler to handle
IRQs like timer IRQ. Both these types of exceptions would be handled
in EL1. Except these two types of exceptions, other exceptions would
treated as invalid exceptions.

But we have't enabled the GIC, so the IRQ exception also be treated
as invalid exception in current stage.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
6 years agoplat/kvm: Add trap handler to dump registers
Wei Chen [Fri, 14 Sep 2018 07:56:49 +0000 (07:56 +0000)]
plat/kvm: Add trap handler to dump registers

Sometimes, for debug purpose, we would like to dump the
registers' value while exception happened. This patch add
a function to dump registers. Currently, we haven't enable
the interrupt controller, so any exception is not expected.
So any exception will cause registers dump.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/kvm: Add interrupt handle APIs for arm64
Wei Chen [Fri, 14 Sep 2018 07:56:48 +0000 (07:56 +0000)]
plat/kvm: Add interrupt handle APIs for arm64

These APIs are necessary for Unikraft. We have provided local CPU
interrupt functions already, so they can be wrapped in lcpu.c easily.
But we haven't implemented GIC libraries, so the APIs in intctrl.c
are TODO.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/common: Common arm64 CPU interrupt flag handling
Wei Chen [Fri, 14 Sep 2018 07:56:47 +0000 (07:56 +0000)]
plat/common: Common arm64 CPU interrupt flag handling

Although we haven't implemented the GIC libraries in this
stage, but we still can implement the interrupt flag handle
interface for CPU.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/common: Add counter workaround for Cortex-A73 erratum 858921
Wei Chen [Fri, 14 Sep 2018 07:56:46 +0000 (07:56 +0000)]
plat/common: Add counter workaround for Cortex-A73 erratum 858921

The errata #858921 describes that Cortex-A73 (r0p0 - r0p2)
counter read can return a wrong value when the counter crosses
a 32bit boundary, but newer Cortex-A73 are not affected.

The workaround involves performing the read twice, compare
bit[32] of the two read values. If bit[32] is different,
keep the first value, otherwise keep the second value.

Signed-off-by: Wei Chen <wei.chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
6 years agoplat/kvm: Add Arm64 virtual timer library to provide ticks
Wei Chen [Fri, 14 Sep 2018 07:56:45 +0000 (07:56 +0000)]
plat/kvm: Add Arm64 virtual timer library to provide ticks

On KVM platform, print debug message will use ukplat_monotonic_clock
to provide timestamp. So we implement this simple virtual timer
library for timestamp.

Signed-off-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>