Skip to content

Commit 79d9468

Browse files
ezequielgarciaJason Cooper
authored andcommitted
bus: mvebu-mbus: Add new API for the PCIe memory and IO aperture
We add two optional properties to the MBus DT binding, to encode the PCIe memory and IO aperture. This allows such information to be retrieved by -for instance- the pci driver to allocate the MBus decoding windows. Correspondingly, and in order to retrieve this information, we add two new APIs. Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com> Tested-by: Andrew Lunn <andrew@lunn.ch> Tested-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> Signed-off-by: Jason Cooper <jason@lakedaemon.net>
1 parent bb24cab commit 79d9468

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

drivers/bus/mvebu-mbus.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ struct mvebu_mbus_state {
142142
struct dentry *debugfs_root;
143143
struct dentry *debugfs_sdram;
144144
struct dentry *debugfs_devs;
145+
struct resource pcie_mem_aperture;
146+
struct resource pcie_io_aperture;
145147
const struct mvebu_mbus_soc_data *soc;
146148
int hw_io_coherency;
147149
};
@@ -821,6 +823,20 @@ int mvebu_mbus_del_window(phys_addr_t base, size_t size)
821823
return 0;
822824
}
823825

826+
void mvebu_mbus_get_pcie_mem_aperture(struct resource *res)
827+
{
828+
if (!res)
829+
return;
830+
*res = mbus_state.pcie_mem_aperture;
831+
}
832+
833+
void mvebu_mbus_get_pcie_io_aperture(struct resource *res)
834+
{
835+
if (!res)
836+
return;
837+
*res = mbus_state.pcie_io_aperture;
838+
}
839+
824840
static __init int mvebu_mbus_debugfs_init(void)
825841
{
826842
struct mvebu_mbus_state *s = &mbus_state;
@@ -1023,6 +1039,35 @@ static int __init mbus_dt_setup(struct mvebu_mbus_state *mbus,
10231039
return 0;
10241040
}
10251041

1042+
static void __init mvebu_mbus_get_pcie_resources(struct device_node *np,
1043+
struct resource *mem,
1044+
struct resource *io)
1045+
{
1046+
u32 reg[2];
1047+
int ret;
1048+
1049+
/*
1050+
* These are optional, so we clear them and they'll
1051+
* be zero if they are missing from the DT.
1052+
*/
1053+
memset(mem, 0, sizeof(struct resource));
1054+
memset(io, 0, sizeof(struct resource));
1055+
1056+
ret = of_property_read_u32_array(np, "pcie-mem-aperture", reg, ARRAY_SIZE(reg));
1057+
if (!ret) {
1058+
mem->start = reg[0];
1059+
mem->end = mem->start + reg[1];
1060+
mem->flags = IORESOURCE_MEM;
1061+
}
1062+
1063+
ret = of_property_read_u32_array(np, "pcie-io-aperture", reg, ARRAY_SIZE(reg));
1064+
if (!ret) {
1065+
io->start = reg[0];
1066+
io->end = io->start + reg[1];
1067+
io->flags = IORESOURCE_IO;
1068+
}
1069+
}
1070+
10261071
int __init mvebu_mbus_dt_init(void)
10271072
{
10281073
struct resource mbuswins_res, sdramwins_res;
@@ -1062,6 +1107,10 @@ int __init mvebu_mbus_dt_init(void)
10621107
return -EINVAL;
10631108
}
10641109

1110+
/* Get optional pcie-{mem,io}-aperture properties */
1111+
mvebu_mbus_get_pcie_resources(np, &mbus_state.pcie_mem_aperture,
1112+
&mbus_state.pcie_io_aperture);
1113+
10651114
ret = mvebu_mbus_common_init(&mbus_state,
10661115
mbuswins_res.start,
10671116
resource_size(&mbuswins_res),

include/linux/mbus.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#ifndef __LINUX_MBUS_H
1212
#define __LINUX_MBUS_H
1313

14+
struct resource;
15+
1416
struct mbus_dram_target_info
1517
{
1618
/*
@@ -59,6 +61,8 @@ static inline const struct mbus_dram_target_info *mv_mbus_dram_info(void)
5961
}
6062
#endif
6163

64+
void mvebu_mbus_get_pcie_mem_aperture(struct resource *res);
65+
void mvebu_mbus_get_pcie_io_aperture(struct resource *res);
6266
int mvebu_mbus_add_window_remap_flags(const char *devname, phys_addr_t base,
6367
size_t size, phys_addr_t remap,
6468
unsigned int flags);

0 commit comments

Comments
 (0)