1 From: Marcin Wojtas <mw@semihalf.com>
2 Date: Mon, 14 Mar 2016 09:39:02 +0100
3 Subject: [PATCH] bus: mvebu-mbus: provide api for obtaining IO and DRAM window
6 This commit enables finding appropriate mbus window and obtaining its
7 target id and attribute for given physical address in two separate
8 routines, both for IO and DRAM windows. This functionality
9 is needed for Armada XP/38x Network Controller's Buffer Manager and
12 [gregory.clement@free-electrons.com: Fix size test for
13 mvebu_mbus_get_dram_win_info]
15 Signed-off-by: Marcin Wojtas <mw@semihalf.com>
16 [DRAM window information reference in LKv3.10]
17 Signed-off-by: Evan Wang <xswang@marvell.com>
18 Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
19 Signed-off-by: David S. Miller <davem@davemloft.net>
22 --- a/drivers/bus/mvebu-mbus.c
23 +++ b/drivers/bus/mvebu-mbus.c
24 @@ -948,6 +948,58 @@ void mvebu_mbus_get_pcie_io_aperture(str
25 *res = mbus_state.pcie_io_aperture;
28 +int mvebu_mbus_get_dram_win_info(phys_addr_t phyaddr, u8 *target, u8 *attr)
30 + const struct mbus_dram_target_info *dram;
34 + dram = mv_mbus_dram_info();
36 + pr_err("missing DRAM information\n");
40 + /* Try to find matching DRAM window for phyaddr */
41 + for (i = 0; i < dram->num_cs; i++) {
42 + const struct mbus_dram_window *cs = dram->cs + i;
44 + if (cs->base <= phyaddr &&
45 + phyaddr <= (cs->base + cs->size - 1)) {
46 + *target = dram->mbus_dram_target_id;
47 + *attr = cs->mbus_attr;
52 + pr_err("invalid dram address 0x%x\n", phyaddr);
55 +EXPORT_SYMBOL_GPL(mvebu_mbus_get_dram_win_info);
57 +int mvebu_mbus_get_io_win_info(phys_addr_t phyaddr, u32 *size, u8 *target,
62 + for (win = 0; win < mbus_state.soc->num_wins; win++) {
66 + mvebu_mbus_read_window(&mbus_state, win, &enabled, &wbase,
67 + size, target, attr, NULL);
72 + if (wbase <= phyaddr && phyaddr <= wbase + *size)
78 +EXPORT_SYMBOL_GPL(mvebu_mbus_get_io_win_info);
80 static __init int mvebu_mbus_debugfs_init(void)
82 struct mvebu_mbus_state *s = &mbus_state;
83 --- a/include/linux/mbus.h
84 +++ b/include/linux/mbus.h
85 @@ -69,6 +69,9 @@ static inline const struct mbus_dram_tar
86 int mvebu_mbus_save_cpu_target(u32 *store_addr);
87 void mvebu_mbus_get_pcie_mem_aperture(struct resource *res);
88 void mvebu_mbus_get_pcie_io_aperture(struct resource *res);
89 +int mvebu_mbus_get_dram_win_info(phys_addr_t phyaddr, u8 *target, u8 *attr);
90 +int mvebu_mbus_get_io_win_info(phys_addr_t phyaddr, u32 *size, u8 *target,
92 int mvebu_mbus_add_window_remap_by_id(unsigned int target,
93 unsigned int attribute,
94 phys_addr_t base, size_t size,