This is an automated email from the ASF dual-hosted git repository. raiden00 pushed a commit to branch releases/12.7 in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit f2a4d5990049b6d356e43eb460cc11bfee165dc4 Author: Bowen Wang <[email protected]> AuthorDate: Mon May 6 15:19:04 2024 +0800 pci/pci_ecam: add read_io/write_io for pci ecam Signed-off-by: Bowen Wang <[email protected]> --- drivers/pci/pci_ecam.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci_ecam.c b/drivers/pci/pci_ecam.c index 4cc974180b..f238bb4eee 100644 --- a/drivers/pci/pci_ecam.c +++ b/drivers/pci/pci_ecam.c @@ -55,6 +55,12 @@ static int pci_ecam_write_config(FAR struct pci_bus_s *bus, unsigned int devfn, int where, int size, uint32_t val); +static int pci_ecam_read_io(FAR struct pci_bus_s *bus, uintptr_t addr, + int size, FAR uint32_t *val); + +static int pci_ecam_write_io(FAR struct pci_bus_s *bus, uintptr_t addr, + int size, uint32_t val); + /**************************************************************************** * Private Types ****************************************************************************/ @@ -71,8 +77,10 @@ struct pci_ecam_s static const struct pci_ops_s g_pci_ecam_ops = { - .read = pci_ecam_read_config, - .write = pci_ecam_write_config, + .read = pci_ecam_read_config, + .write = pci_ecam_write_config, + .read_io = pci_ecam_read_io, + .write_io = pci_ecam_write_io, }; /**************************************************************************** @@ -266,6 +274,100 @@ static int pci_ecam_write_config(FAR struct pci_bus_s *bus, return OK; } +/**************************************************************************** + * Name: pci_ecam_read_io + * + * Description: + * Read data from the specific address. + * + * Input Parameters: + * bus - The bus on this to read reg data + * addr - Data address + * size - Data size + * val - Return value to this var + * + * Returned Value: + * Zero (OK) is returned on success. A negated errno value is returned + * on failure. + * + ****************************************************************************/ + +static int pci_ecam_read_io(FAR struct pci_bus_s *bus, uintptr_t addr, + int size, FAR uint32_t *val) +{ + if (!IS_ALIGNED(addr, size)) + { + *val = 0; + return -EINVAL; + } + + if (size == 4) + { + *val = readl(addr); + } + else if (size == 2) + { + *val = readw(addr); + } + else if (size == 1) + { + *val = readb(addr); + } + else + { + *val = 0; + return -EINVAL; + } + + return OK; +} + +/**************************************************************************** + * Name: pci_ecam_read_io + * + * Description: + * Write data to the specific address. + * + * Input Parameters: + * bus - The bus on this to read reg data + * addr - Data address + * size - Data size + * val - Write this value to specific address + * + * Returned Value: + * Zero (OK) is returned on success. A negated errno value is returned + * on failure. + * + ****************************************************************************/ + +static int pci_ecam_write_io(FAR struct pci_bus_s *bus, uintptr_t addr, + int size, uint32_t val) +{ + if (!IS_ALIGNED(addr, size)) + { + return -EINVAL; + } + + if (size == 4) + { + writel(val, addr); + } + else if (size == 2) + { + writew(val, addr); + } + else if (size == 1) + { + writeb(val, addr); + } + else + { + return -EINVAL; + } + + return OK; +} + /**************************************************************************** * Public Functions ****************************************************************************/
