[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH v3 3/3] plat/common: virt to phys addr conversion
Platform drivers need a way to get the virtual address coverted to the physical address. We provide an common interface to enable such conversion. Signed-off-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx> --- include/uk/arch/arm/intsizes.h | 1 + include/uk/arch/types.h | 19 ++++++++++++++++++ include/uk/arch/x86_64/intsizes.h | 1 + plat/common/include/io.h | 41 +++++++++++++++++++++++++++++++++++++++ plat/drivers/virtio/virtio_ring.c | 7 +++++-- plat/kvm/Makefile.uk | 1 + plat/kvm/io.c | 40 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 plat/common/include/io.h create mode 100644 plat/kvm/io.c diff --git a/include/uk/arch/arm/intsizes.h b/include/uk/arch/arm/intsizes.h index 5b36c4b..0051c0a 100644 --- a/include/uk/arch/arm/intsizes.h +++ b/include/uk/arch/arm/intsizes.h @@ -43,3 +43,4 @@ #define __L_IS_32 /* long */ #define __LL_IS_64 /* long long */ #define __PTR_IS_32 /* void * */ +#define __PHY_ADDR_IS_32 /* phys_addr */ diff --git a/include/uk/arch/types.h b/include/uk/arch/types.h index e8d7726..a69dc49 100644 --- a/include/uk/arch/types.h +++ b/include/uk/arch/types.h @@ -211,6 +211,20 @@ typedef __uptr __sz; /* size_t equivalent */ typedef __sptr __ssz; /* ssize_t equivalent */ typedef __sptr __off; /* off_t equivalent */ +#if (defined __PHY_ADDR_IS_16) +typedef __u16 __phys_addr; +#define __PRIpaddr __PRIx16 +#define __HAVE_PHYS_ADDR__ +#elif (defined __PHY_ADDR_IS_32) +typedef __u32 __phys_addr; +#define __PRIpaddr __PRIx32 +#define __HAVE_PHYS_ADDR__ +#elif (defined __PHY_ADDR_IS_64) +typedef __u64 __phys_addr; +#define __PRIpaddr __PRIx64 +#define __HAVE_PHYS_ADDR__ +#endif + /* Sanity check */ #ifndef __HAVE_INT8__ #error Missing 8-bit integer definitions @@ -237,6 +251,11 @@ typedef __sptr __off; /* off_t equivalent */ #else #undef __HAVE_PTR__ #endif +#ifndef __HAVE_PHYS_ADDR__ +#error Missing physical address definitions +#else +#undef __HAVE_PHYS_ADDR__ +#endif #ifndef __NULL #define __NULL ((void *) 0) diff --git a/include/uk/arch/x86_64/intsizes.h b/include/uk/arch/x86_64/intsizes.h index e3ef510..946ceca 100644 --- a/include/uk/arch/x86_64/intsizes.h +++ b/include/uk/arch/x86_64/intsizes.h @@ -43,3 +43,4 @@ #define __L_IS_64 /* long */ #define __LL_IS_64 /* long long */ #define __PTR_IS_64 /* void * */ +#define __PHY_ADDR_IS_64 /* phys_addr */ diff --git a/plat/common/include/io.h b/plat/common/include/io.h new file mode 100644 index 0000000..6a92186 --- /dev/null +++ b/plat/common/include/io.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * + * + * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY. + */ +#ifndef __UKPLAT_IO_H__ +#define __UKPLAT_IO_H__ + +#include <uk/arch/types.h> + +__phys_addr ukplat_virt_to_phys(const volatile void *address); + +#endif /* __UKPLAT_IO_H__ */ diff --git a/plat/drivers/virtio/virtio_ring.c b/plat/drivers/virtio/virtio_ring.c index 098c324..790f0bb 100644 --- a/plat/drivers/virtio/virtio_ring.c +++ b/plat/drivers/virtio/virtio_ring.c @@ -28,6 +28,7 @@ #include <string.h> #include <uk/print.h> #include <cpu.h> +#include <io.h> #include <pci/virtio/virtio_pci.h> #include <pci/virtio/virtio_ring.h> #include <uk/arch/atomic.h> @@ -106,6 +107,7 @@ int virtq_rings_init(struct virtq *vq, __u16 pci_base, __u8 *data = NULL; __u16 vq_num; __sz vq_size; + __phys_addr pa; UK_ASSERT(vq != NULL); UK_ASSERT(a != NULL); @@ -141,9 +143,10 @@ int virtq_rings_init(struct virtq *vq, __u16 pci_base, /* set queue memory */ outw(pci_base + VIRTIO_PCI_QUEUE_SEL, queue_select); - /* TODO use physical address */ + /* use physical address */ + pa = ukplat_virt_to_phys(data); outl(pci_base + VIRTIO_PCI_QUEUE_PFN, - (__u64) data >> VIRTIO_PCI_QUEUE_ADDR_SHIFT); + (pa >> VIRTIO_PCI_QUEUE_ADDR_SHIFT)); return 0; } diff --git a/plat/kvm/Makefile.uk b/plat/kvm/Makefile.uk index 1ae1b08..e379c83 100644 --- a/plat/kvm/Makefile.uk +++ b/plat/kvm/Makefile.uk @@ -38,6 +38,7 @@ LIBKVMPLAT_SRCS-y += $(LIBKVMPLAT_BASE)/memory.c LIBKVMPLAT_SRCS-y += $(LIBKVMPLAT_BASE)/irq.c LIBKVMPLAT_SRCS-y += $(LIBKVMPLAT_BASE)/time.c LIBKVMPLAT_SRCS-y += $(LIBKVMPLAT_BASE)/tscclock.c +LIBKVMPLAT_SRCS-y += $(LIBKVMPLAT_BASE)/io.c LIBKVMPLAT_SRCS-y += $(UK_PLAT_COMMON_BASE)/lcpu.c|common LIBKVMPLAT_SRCS-y += $(UK_PLAT_COMMON_BASE)/memory.c|common diff --git a/plat/kvm/io.c b/plat/kvm/io.c new file mode 100644 index 0000000..ca83e44 --- /dev/null +++ b/plat/kvm/io.c @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Authors: Sharan Santhanam <sharan.santhanam@xxxxxxxxx> + * + * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY. + */ + +#include <io.h> + +__phys_addr ukplat_virt_to_phys(const volatile void *address) +{ + return (__phys_addr)address; +} -- 2.7.4 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |