This is an automated email from the ASF dual-hosted git repository. btashton pushed a commit to branch pci in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit caeb2a72fa0a56ac3cdc8c04372dd0b2d6c1634a Author: Yang Chung-Fan <sonic.tw...@gmail.com> AuthorDate: Wed May 6 01:02:38 2020 +0900 virt: add qemu pci-testdev driver --- drivers/Kconfig | 1 + drivers/Makefile | 1 + drivers/pcie/pcie_root.c | 5 +- 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(+), 1 deletion(-) diff --git a/drivers/Kconfig b/drivers/Kconfig index 513d3ea..aa11b3c 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -108,3 +108,4 @@ source drivers/syslog/Kconfig source drivers/platform/Kconfig source drivers/rf/Kconfig source drivers/pcie/Kconfig +source drivers/virt/Kconfig diff --git a/drivers/Makefile b/drivers/Makefile index 4a2e9eb..5f6e0b0 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -84,6 +84,7 @@ include contactless$(DELIM)Make.defs include 1wire$(DELIM)Make.defs include rf$(DELIM)Make.defs include pcie$(DELIM)Make.defs +include virt$(DELIM)Make.defs ifeq ($(CONFIG_SPECIFIC_DRIVERS),y) include platform$(DELIM)Make.defs diff --git a/drivers/pcie/pcie_root.c b/drivers/pcie/pcie_root.c index 8764492..1fe2181 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,7 +41,9 @@ struct pcie_dev_type_s *pci_device_types[] = { - NULL, +#ifdef CONFIG_VIRT_QEMU_PCI_TEST + &pcie_type_qemu_pci_test, +#endif /* CONFIG_VIRT_QEMU_PCI_TEST */ }; /**************************************************************************** diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig new file mode 100644 index 0000000..bf8fb85 --- /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 0000000..8ccfbe0 --- /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 0000000..ff1af63 --- /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, (PCI_CMD_MASTER | PCI_CMD_MEM)); + + 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 0000000..f8e38f9 --- /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 */