From: Jonas Weståker <jo...@retotech.se>

Signed-off-by: Jonas Weståker <jo...@retotech.se>
Signed-off-by: Henning Schild <henning.sch...@siemens.com>
---
 inmates/lib/arm-common/Makefile.lib     |  1 +
 inmates/lib/arm-common/include/inmate.h |  2 +
 inmates/lib/arm-common/pci.c            | 85 +++++++++++++++++++++++++++++++++
 3 files changed, 88 insertions(+)
 create mode 100644 inmates/lib/arm-common/pci.c

diff --git a/inmates/lib/arm-common/Makefile.lib 
b/inmates/lib/arm-common/Makefile.lib
index 1cd45a5..c029ade 100644
--- a/inmates/lib/arm-common/Makefile.lib
+++ b/inmates/lib/arm-common/Makefile.lib
@@ -43,5 +43,6 @@ OBJS-y += printk.o gic.o timer.o
 OBJS-y += uart-jailhouse.o uart-pl011.o uart-8250.o uart-8250-8.o
 OBJS-y += uart-xuartps.o uart-mvebu.o uart-hscif.o
 OBJS-y += gic-v2.o gic-v3.o
+OBJS-y += ../pci.o pci.o
 
 COMMON_OBJECTS = $(addprefix ../arm-common/,$(OBJS-y))
diff --git a/inmates/lib/arm-common/include/inmate.h 
b/inmates/lib/arm-common/include/inmate.h
index 25960f0..5ca22e6 100644
--- a/inmates/lib/arm-common/include/inmate.h
+++ b/inmates/lib/arm-common/include/inmate.h
@@ -95,6 +95,8 @@ u64 timer_get_ticks(void);
 u64 timer_ticks_to_ns(u64 ticks);
 void timer_start(u64 timeout);
 
+void pci_set_mmio_base(u32 base);
+
 #include <arch/inmate.h>
 
 #include "../inmate_common.h"
diff --git a/inmates/lib/arm-common/pci.c b/inmates/lib/arm-common/pci.c
new file mode 100644
index 0000000..8ce1b1a
--- /dev/null
+++ b/inmates/lib/arm-common/pci.c
@@ -0,0 +1,85 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Retotech AB, 2017
+ * Copyright (c) Siemens AG, 2017
+ *
+ * Authors:
+ *  Jonas Weståker <jo...@retotech.se>
+ *  Henning Schild <henning.sch...@siemens.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Alternatively, you can use or redistribute this file under the following
+ * BSD license:
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+#include <inmate.h>
+
+#define PCI_MMIO_SIZE  0xfffff
+static u32 mmio_base;
+
+void pci_set_mmio_base(u32 base)
+{
+       mmio_base = base;
+}
+
+u32 pci_read_config(u16 bdf, unsigned int addr, unsigned int size)
+{
+       u32 reg_addr = mmio_base | ((u32)bdf << 8) | (addr & 0xfc);
+       if (!mmio_base || reg_addr + size >= (mmio_base + PCI_MMIO_SIZE))
+               return -1;
+
+       switch (size) {
+       case 1:
+               return mmio_read8((u8 *)(reg_addr + (addr & 0x3)));
+       case 2:
+               return mmio_read16((u16 *)(reg_addr + (addr & 0x3)));
+       case 4:
+               return mmio_read32((u32 *)(reg_addr));
+       default:
+               return -1;
+       }
+}
+
+void pci_write_config(u16 bdf, unsigned int addr, u32 value, unsigned int size)
+{
+       u32 reg_addr = mmio_base | ((u32)bdf << 8) | (addr & 0xfc);
+       if (!mmio_base || reg_addr + size >= (mmio_base + PCI_MMIO_SIZE))
+               return;
+       switch (size) {
+       case 1:
+               mmio_write8((u8 *)(reg_addr + (addr & 0x3)), value);
+               break;
+       case 2:
+               mmio_write16((u16 *)(reg_addr + (addr & 0x3)), value);
+               break;
+       case 4:
+               mmio_write32((u32 *)(reg_addr), value);
+               break;
+       }
+}
-- 
2.13.6

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jailhouse-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to