You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ra...@apache.org on 2024/01/20 13:10:27 UTC
(nuttx) 03/06: virt: add qemu pci-testdev driver
This is an automated email from the ASF dual-hosted git repository.
raiden00 pushed a commit to branch pci
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 97cb379f235eea09f8d5e1a5e60839fe4069faf8
Author: Yang Chung-Fan <so...@gmail.com>
AuthorDate: Wed May 6 01:02:38 2020 +0900
virt: add qemu pci-testdev driver
pcie: types array should be null terminated
---
drivers/Kconfig | 1 +
drivers/Makefile | 1 +
drivers/pcie/pcie_root.c | 4 ++
drivers/virt/Kconfig | 22 +++++++
drivers/virt/Make.defs | 37 ++++++++++++
drivers/virt/qemu_pci_test.c | 130 ++++++++++++++++++++++++++++++++++++++++++
include/nuttx/virt/qemu_pci.h | 53 +++++++++++++++++
7 files changed, 248 insertions(+)
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 43f8949994..da93ca190f 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -60,3 +60,4 @@ source "drivers/dma/Kconfig"
source "drivers/devicetree/Kconfig"
source "drivers/reset/Kconfig"
source "drivers/pcie/Kconfig"
+source "drivers/virt/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index 7f94dfd2da..f5584c5370 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -78,6 +78,7 @@ include segger/Make.defs
include usrsock/Make.defs
include reset/Make.defs
include pcie/Make.defs
+include virt/Make.defs
ifeq ($(CONFIG_SPECIFIC_DRIVERS),y)
-include platform/Make.defs
diff --git a/drivers/pcie/pcie_root.c b/drivers/pcie/pcie_root.c
index 25718aa5ae..b85c5862fa 100644
--- a/drivers/pcie/pcie_root.c
+++ b/drivers/pcie/pcie_root.c
@@ -29,6 +29,7 @@
#include <debug.h>
#include <nuttx/pcie/pcie.h>
+#include <nuttx/virt/qemu_pci.h>
/****************************************************************************
* Pre-processor Definitions
@@ -40,6 +41,9 @@
struct pcie_dev_type_s *pci_device_types[] =
{
+#ifdef CONFIG_VIRT_QEMU_PCI_TEST
+ &pcie_type_qemu_pci_test,
+#endif /* CONFIG_VIRT_QEMU_PCI_TEST */
NULL,
};
diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig
new file mode 100644
index 0000000000..bf8fb8591c
--- /dev/null
+++ b/drivers/virt/Kconfig
@@ -0,0 +1,22 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+#
+#
+menuconfig VIRT
+ bool "Virtualization"
+ default n
+ ---help---
+ Drivers for virtualized and emulated devices
+
+if VIRT
+
+config VIRT_QEMU_PCI_TEST
+ bool "Driver for QEMU PCI test device"
+ default n
+ select PCIE
+ ---help---
+ Driver for QEMU PCI test device
+
+endif # VIRT
diff --git a/drivers/virt/Make.defs b/drivers/virt/Make.defs
new file mode 100644
index 0000000000..8ccfbe06c5
--- /dev/null
+++ b/drivers/virt/Make.defs
@@ -0,0 +1,37 @@
+############################################################################
+# drivers/pcie/Make.defs
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+############################################################################
+
+# Don't build anything if there is no CAN support
+
+ifeq ($(CONFIG_VIRT_QEMU_PCI_TEST),y)
+
+CSRCS += qemu_pci_test.c
+
+endif
+
+# Include virt device driver build support
+#
+ifeq ($(CONFIG_VIRT),y)
+
+DEPPATH += --dep-path virt
+VPATH += :virt
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)virt}
+
+endif
diff --git a/drivers/virt/qemu_pci_test.c b/drivers/virt/qemu_pci_test.c
new file mode 100644
index 0000000000..d0df753121
--- /dev/null
+++ b/drivers/virt/qemu_pci_test.c
@@ -0,0 +1,130 @@
+/*****************************************************************************
+ * drivers/virt/qemu_pci_test.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Included Files
+ *****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/arch.h>
+
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <math.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sched.h>
+
+#include <nuttx/pcie/pcie.h>
+#include <nuttx/virt/qemu_pci.h>
+
+/*****************************************************************************
+ * Pre-processor Definitions
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Private Types
+ *****************************************************************************/
+
+struct pci_test_dev_hdr_s
+{
+ volatile uint8_t test; /* write-only, starts a given test number */
+ volatile uint8_t width_type; /* read-only, type and width of access for a given test.
+ * 1,2,4 for byte,word or long write.
+ * any other value if test not supported on this BAR */
+ volatile uint8_t pad0[2];
+ volatile uint32_t offset; /* read-only, offset in this BAR for a given test */
+ volatile uint32_t data; /* read-only, data to use for a given test */
+ volatile uint32_t count; /* for debugging. number of writes detected. */
+ volatile uint8_t name[]; /* for debugging. 0-terminated ASCII string. */
+};
+
+/*****************************************************************************
+ * Public Functions
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Name: qemu_pci_test_probe
+ *
+ * Description:
+ * Initialize device
+ *****************************************************************************/
+
+int qemu_pci_test_probe(FAR struct pcie_bus_s *bus,
+ FAR struct pcie_dev_type_s *type, uint16_t bdf)
+{
+ uint32_t bar[2];
+ struct pcie_dev_s dev =
+ {
+ .bus = bus,
+ .type = type,
+ .bdf = bdf,
+ };
+
+ pci_enable_device(&dev);
+
+ for (int ii = 0; ii < 2; ii++)
+ {
+ pci_get_bar(&dev, ii, bar + ii);
+
+ if ((bar[ii] & PCI_BAR_IO) != PCI_BAR_IO)
+ {
+ pciinfo("Mapping BAR%d: %x\n", ii, bar[ii]);
+
+ pci_map_bar(&dev, ii, 0x1000, NULL);
+
+ struct pci_test_dev_hdr_s *ptr =
+ (struct pci_test_dev_hdr_s *)(uintptr_t)bar[ii];
+
+ int i = 0;
+ while (1)
+ {
+ ptr->test = i;
+
+ if (ptr->width_type != 1 &&
+ ptr->width_type != 2 &&
+ ptr->width_type != 4)
+ break;
+
+ pciinfo("Test[%d] Size:%d %s\n",
+ i, ptr->width_type,
+ ptr->name);
+
+ i++;
+ }
+ }
+ }
+
+ return OK;
+}
+
+/*****************************************************************************
+ * Public Data
+ *****************************************************************************/
+
+struct pcie_dev_type_s pcie_type_qemu_pci_test =
+{
+ .vendor = 0x1b36,
+ .device = 0x0005,
+ .class_rev = PCI_ID_ANY,
+ .name = "Qemu PCI test device",
+ .probe = qemu_pci_test_probe
+};
diff --git a/include/nuttx/virt/qemu_pci.h b/include/nuttx/virt/qemu_pci.h
new file mode 100644
index 0000000000..f8e38f9241
--- /dev/null
+++ b/include/nuttx/virt/qemu_pci.h
@@ -0,0 +1,53 @@
+/****************************************************************************
+ * include/nuttx/serial/uart_mcs99xx.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_VIRT_QEMU_PCI_TEST_H
+#define __INCLUDE_NUTTX_VIRT_QEMU_PCI_TEST_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdbool.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#ifdef CONFIG_VIRT_QEMU_PCI_TEST
+extern struct pcie_dev_type_s pcie_type_qemu_pci_test;
+#endif /* CONFIG_VIRT_QEMU_PCI_TEST */
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __INCLUDE_NUTTX_VIRT_QEMU_PCI_TEST_H */