Skip to content

Commit f2900ac

Browse files
wojtas-marcindavem330
authored andcommitted
bus: mvebu-mbus: provide api for obtaining IO and DRAM window information
This commit enables finding appropriate mbus window and obtaining its target id and attribute for given physical address in two separate routines, both for IO and DRAM windows. This functionality is needed for Armada XP/38x Network Controller's Buffer Manager and PnC configuration. [[email protected]: Fix size test for mvebu_mbus_get_dram_win_info] Signed-off-by: Marcin Wojtas <[email protected]> [DRAM window information reference in LKv3.10] Signed-off-by: Evan Wang <[email protected]> Signed-off-by: Gregory CLEMENT <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 293fdc2 commit f2900ac

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

drivers/bus/mvebu-mbus.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,58 @@ void mvebu_mbus_get_pcie_io_aperture(struct resource *res)
948948
*res = mbus_state.pcie_io_aperture;
949949
}
950950

951+
int mvebu_mbus_get_dram_win_info(phys_addr_t phyaddr, u8 *target, u8 *attr)
952+
{
953+
const struct mbus_dram_target_info *dram;
954+
int i;
955+
956+
/* Get dram info */
957+
dram = mv_mbus_dram_info();
958+
if (!dram) {
959+
pr_err("missing DRAM information\n");
960+
return -ENODEV;
961+
}
962+
963+
/* Try to find matching DRAM window for phyaddr */
964+
for (i = 0; i < dram->num_cs; i++) {
965+
const struct mbus_dram_window *cs = dram->cs + i;
966+
967+
if (cs->base <= phyaddr &&
968+
phyaddr <= (cs->base + cs->size - 1)) {
969+
*target = dram->mbus_dram_target_id;
970+
*attr = cs->mbus_attr;
971+
return 0;
972+
}
973+
}
974+
975+
pr_err("invalid dram address 0x%x\n", phyaddr);
976+
return -EINVAL;
977+
}
978+
EXPORT_SYMBOL_GPL(mvebu_mbus_get_dram_win_info);
979+
980+
int mvebu_mbus_get_io_win_info(phys_addr_t phyaddr, u32 *size, u8 *target,
981+
u8 *attr)
982+
{
983+
int win;
984+
985+
for (win = 0; win < mbus_state.soc->num_wins; win++) {
986+
u64 wbase;
987+
int enabled;
988+
989+
mvebu_mbus_read_window(&mbus_state, win, &enabled, &wbase,
990+
size, target, attr, NULL);
991+
992+
if (!enabled)
993+
continue;
994+
995+
if (wbase <= phyaddr && phyaddr <= wbase + *size)
996+
return win;
997+
}
998+
999+
return -EINVAL;
1000+
}
1001+
EXPORT_SYMBOL_GPL(mvebu_mbus_get_io_win_info);
1002+
9511003
static __init int mvebu_mbus_debugfs_init(void)
9521004
{
9531005
struct mvebu_mbus_state *s = &mbus_state;

include/linux/mbus.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ static inline const struct mbus_dram_target_info *mv_mbus_dram_info_nooverlap(vo
6969
int mvebu_mbus_save_cpu_target(u32 *store_addr);
7070
void mvebu_mbus_get_pcie_mem_aperture(struct resource *res);
7171
void mvebu_mbus_get_pcie_io_aperture(struct resource *res);
72+
int mvebu_mbus_get_dram_win_info(phys_addr_t phyaddr, u8 *target, u8 *attr);
73+
int mvebu_mbus_get_io_win_info(phys_addr_t phyaddr, u32 *size, u8 *target,
74+
u8 *attr);
7275
int mvebu_mbus_add_window_remap_by_id(unsigned int target,
7376
unsigned int attribute,
7477
phys_addr_t base, size_t size,

0 commit comments

Comments
 (0)