add pci_bus_map_region and pci_map_region macro

Signed-off-by: lipengfei28 <lipengfei28@xiaomi.com>
This commit is contained in:
lipengfei28 2024-07-24 10:22:10 +08:00 committed by Xiang Xiao
parent 3b09de844f
commit 1eb151bef6
2 changed files with 52 additions and 9 deletions

View File

@ -1560,6 +1560,33 @@ int pci_select_bars(FAR struct pci_device_s *dev, unsigned int flags)
return bars;
}
/****************************************************************************
* Name: pci_bus_map_region
*
* Description:
* Create a virtual mapping for a address.
*
* Using this function you will get an virtual address.
* These functions hide the details if this is a MMIO or PIO address
* space and will just do what you expect from them in the correct way.
*
* Input Parameters:
* bus - PCI bus
* start - The address base
* size - The length of the address
*
* Returned Value:
* Virtual address or zero if failed
****************************************************************************/
FAR void *
pci_bus_map_region(FAR struct pci_bus_s *bus, uintptr_t start, size_t size)
{
return bus->ctrl->ops->map ?
(FAR void *)bus->ctrl->ops->map(bus, start, start + size)
: (FAR void *)start;
}
/****************************************************************************
* Name: pci_map_bar_region
*
@ -1583,16 +1610,8 @@ int pci_select_bars(FAR struct pci_device_s *dev, unsigned int flags)
FAR void *pci_map_bar_region(FAR struct pci_device_s *dev, int bar,
uintptr_t offset, size_t length)
{
FAR struct pci_bus_s *bus = dev->bus;
uintptr_t start = pci_resource_start(dev, bar) + offset;
uintptr_t end = start + length;
if (bus->ctrl->ops->map)
{
start = bus->ctrl->ops->map(bus, start, end);
}
return (FAR void *)start;
return pci_map_region(dev, start, length);
}
/****************************************************************************

View File

@ -207,6 +207,8 @@
#define pci_read_mmio_dword(dev, addr, val) \
(*val) = *((FAR volatile uint32_t *)(addr))
#define pci_map_region(dev, start, size) pci_bus_map_region((dev)->bus, start, size)
/****************************************************************************
* Public Types
****************************************************************************/
@ -615,6 +617,28 @@ int pci_disable_device(FAR struct pci_device_s *dev);
int pci_select_bars(FAR struct pci_device_s *dev, unsigned int flags);
/****************************************************************************
* Name: pci_bus_map_region
*
* Description:
* Create a virtual mapping for a address.
*
* Using this function you will get an virtual address.
* These functions hide the details if this is a MMIO or PIO address
* space and will just do what you expect from them in the correct way.
*
* Input Parameters:
* bus - PCI bus
* start - The address base
* size - The length of the address
*
* Returned Value:
* Virtual address or zero if failed
****************************************************************************/
FAR void *
pci_bus_map_region(FAR struct pci_bus_s *bus, uintptr_t start, size_t size);
/****************************************************************************
* Name: pci_map_bar_region
*