Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

[gregory.clement@free-electrons.com: Fix size test for
mvebu_mbus_get_dram_win_info]

Signed-off-by: Marcin Wojtas <mw@semihalf.com>
[DRAM window information reference in LKv3.10]
Signed-off-by: Evan Wang <xswang@marvell.com>
Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Marcin Wojtas and committed by
David S. Miller
f2900ace 293fdc24

+55
+52
drivers/bus/mvebu-mbus.c
··· 948 948 *res = mbus_state.pcie_io_aperture; 949 949 } 950 950 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 + 951 1003 static __init int mvebu_mbus_debugfs_init(void) 952 1004 { 953 1005 struct mvebu_mbus_state *s = &mbus_state;
+3
include/linux/mbus.h
··· 69 69 int mvebu_mbus_save_cpu_target(u32 *store_addr); 70 70 void mvebu_mbus_get_pcie_mem_aperture(struct resource *res); 71 71 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); 72 75 int mvebu_mbus_add_window_remap_by_id(unsigned int target, 73 76 unsigned int attribute, 74 77 phys_addr_t base, size_t size,