2017-10-16 18:52:35 +07:00
|
|
|
/*
|
|
|
|
* Based on linux/arch/arm/mm/nommu.c
|
|
|
|
*
|
|
|
|
* ARM PMSAv7 supporting functions.
|
|
|
|
*/
|
|
|
|
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
#include <linux/bitops.h>
|
2017-10-16 18:52:35 +07:00
|
|
|
#include <linux/memblock.h>
|
2018-01-03 16:09:33 +07:00
|
|
|
#include <linux/string.h>
|
2017-10-16 18:52:35 +07:00
|
|
|
|
2017-10-16 19:00:45 +07:00
|
|
|
#include <asm/cacheflush.h>
|
2017-10-16 18:52:35 +07:00
|
|
|
#include <asm/cp15.h>
|
|
|
|
#include <asm/cputype.h>
|
|
|
|
#include <asm/mpu.h>
|
2017-10-16 19:00:45 +07:00
|
|
|
#include <asm/sections.h>
|
2017-10-16 18:52:35 +07:00
|
|
|
|
|
|
|
#include "mm.h"
|
|
|
|
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
struct region {
|
|
|
|
phys_addr_t base;
|
|
|
|
phys_addr_t size;
|
|
|
|
unsigned long subreg;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct region __initdata mem[MPU_MAX_REGIONS];
|
2017-10-16 19:00:45 +07:00
|
|
|
#ifdef CONFIG_XIP_KERNEL
|
|
|
|
static struct region __initdata xip[MPU_MAX_REGIONS];
|
|
|
|
#endif
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
|
2017-10-16 18:54:05 +07:00
|
|
|
static unsigned int __initdata mpu_min_region_order;
|
|
|
|
static unsigned int __initdata mpu_max_regions;
|
|
|
|
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
static int __init __mpu_min_region_order(void);
|
|
|
|
static int __init __mpu_max_regions(void);
|
|
|
|
|
2017-10-16 18:57:48 +07:00
|
|
|
#ifndef CONFIG_CPU_V7M
|
|
|
|
|
2017-10-16 18:53:18 +07:00
|
|
|
#define DRBAR __ACCESS_CP15(c6, 0, c1, 0)
|
|
|
|
#define IRBAR __ACCESS_CP15(c6, 0, c1, 1)
|
|
|
|
#define DRSR __ACCESS_CP15(c6, 0, c1, 2)
|
|
|
|
#define IRSR __ACCESS_CP15(c6, 0, c1, 3)
|
|
|
|
#define DRACR __ACCESS_CP15(c6, 0, c1, 4)
|
|
|
|
#define IRACR __ACCESS_CP15(c6, 0, c1, 5)
|
|
|
|
#define RNGNR __ACCESS_CP15(c6, 0, c2, 0)
|
|
|
|
|
2017-10-16 18:52:35 +07:00
|
|
|
/* Region number */
|
2017-10-16 18:53:18 +07:00
|
|
|
static inline void rgnr_write(u32 v)
|
2017-10-16 18:52:35 +07:00
|
|
|
{
|
2017-10-16 18:53:18 +07:00
|
|
|
write_sysreg(v, RNGNR);
|
2017-10-16 18:52:35 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Data-side / unified region attributes */
|
|
|
|
|
|
|
|
/* Region access control register */
|
2017-10-16 18:53:18 +07:00
|
|
|
static inline void dracr_write(u32 v)
|
2017-10-16 18:52:35 +07:00
|
|
|
{
|
2017-10-16 18:53:18 +07:00
|
|
|
write_sysreg(v, DRACR);
|
2017-10-16 18:52:35 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Region size register */
|
2017-10-16 18:53:18 +07:00
|
|
|
static inline void drsr_write(u32 v)
|
2017-10-16 18:52:35 +07:00
|
|
|
{
|
2017-10-16 18:53:18 +07:00
|
|
|
write_sysreg(v, DRSR);
|
2017-10-16 18:52:35 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Region base address register */
|
2017-10-16 18:53:18 +07:00
|
|
|
static inline void drbar_write(u32 v)
|
2017-10-16 18:52:35 +07:00
|
|
|
{
|
2017-10-16 18:53:18 +07:00
|
|
|
write_sysreg(v, DRBAR);
|
2017-10-16 18:52:35 +07:00
|
|
|
}
|
|
|
|
|
2017-10-16 18:53:18 +07:00
|
|
|
static inline u32 drbar_read(void)
|
2017-10-16 18:52:35 +07:00
|
|
|
{
|
2017-10-16 18:53:18 +07:00
|
|
|
return read_sysreg(DRBAR);
|
2017-10-16 18:52:35 +07:00
|
|
|
}
|
|
|
|
/* Optional instruction-side region attributes */
|
|
|
|
|
|
|
|
/* I-side Region access control register */
|
2017-10-16 18:53:18 +07:00
|
|
|
static inline void iracr_write(u32 v)
|
2017-10-16 18:52:35 +07:00
|
|
|
{
|
2017-10-16 18:53:18 +07:00
|
|
|
write_sysreg(v, IRACR);
|
2017-10-16 18:52:35 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* I-side Region size register */
|
2017-10-16 18:53:18 +07:00
|
|
|
static inline void irsr_write(u32 v)
|
2017-10-16 18:52:35 +07:00
|
|
|
{
|
2017-10-16 18:53:18 +07:00
|
|
|
write_sysreg(v, IRSR);
|
2017-10-16 18:52:35 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* I-side Region base address register */
|
2017-10-16 18:53:18 +07:00
|
|
|
static inline void irbar_write(u32 v)
|
2017-10-16 18:52:35 +07:00
|
|
|
{
|
2017-10-16 18:53:18 +07:00
|
|
|
write_sysreg(v, IRBAR);
|
2017-10-16 18:52:35 +07:00
|
|
|
}
|
|
|
|
|
2017-10-16 18:53:18 +07:00
|
|
|
static inline u32 irbar_read(void)
|
2017-10-16 18:52:35 +07:00
|
|
|
{
|
2017-10-16 18:53:18 +07:00
|
|
|
return read_sysreg(IRBAR);
|
2017-10-16 18:52:35 +07:00
|
|
|
}
|
|
|
|
|
2017-10-16 18:57:48 +07:00
|
|
|
#else
|
|
|
|
|
|
|
|
static inline void rgnr_write(u32 v)
|
|
|
|
{
|
2018-04-03 16:36:37 +07:00
|
|
|
writel_relaxed(v, BASEADDR_V7M_SCB + PMSAv7_RNR);
|
2017-10-16 18:57:48 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Data-side / unified region attributes */
|
|
|
|
|
|
|
|
/* Region access control register */
|
|
|
|
static inline void dracr_write(u32 v)
|
|
|
|
{
|
2018-04-03 16:36:37 +07:00
|
|
|
u32 rsr = readl_relaxed(BASEADDR_V7M_SCB + PMSAv7_RASR) & GENMASK(15, 0);
|
2017-10-16 18:57:48 +07:00
|
|
|
|
2018-04-03 16:36:37 +07:00
|
|
|
writel_relaxed((v << 16) | rsr, BASEADDR_V7M_SCB + PMSAv7_RASR);
|
2017-10-16 18:57:48 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Region size register */
|
|
|
|
static inline void drsr_write(u32 v)
|
|
|
|
{
|
2018-04-03 16:36:37 +07:00
|
|
|
u32 racr = readl_relaxed(BASEADDR_V7M_SCB + PMSAv7_RASR) & GENMASK(31, 16);
|
2017-10-16 18:57:48 +07:00
|
|
|
|
2018-04-03 16:36:37 +07:00
|
|
|
writel_relaxed(v | racr, BASEADDR_V7M_SCB + PMSAv7_RASR);
|
2017-10-16 18:57:48 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Region base address register */
|
|
|
|
static inline void drbar_write(u32 v)
|
|
|
|
{
|
2018-04-03 16:36:37 +07:00
|
|
|
writel_relaxed(v, BASEADDR_V7M_SCB + PMSAv7_RBAR);
|
2017-10-16 18:57:48 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 drbar_read(void)
|
|
|
|
{
|
2018-04-03 16:36:37 +07:00
|
|
|
return readl_relaxed(BASEADDR_V7M_SCB + PMSAv7_RBAR);
|
2017-10-16 18:57:48 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARMv7-M only supports a unified MPU, so I-side operations are nop */
|
|
|
|
|
|
|
|
static inline void iracr_write(u32 v) {}
|
|
|
|
static inline void irsr_write(u32 v) {}
|
|
|
|
static inline void irbar_write(u32 v) {}
|
|
|
|
static inline unsigned long irbar_read(void) {return 0;}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
static bool __init try_split_region(phys_addr_t base, phys_addr_t size, struct region *region)
|
|
|
|
{
|
|
|
|
unsigned long subreg, bslots, sslots;
|
|
|
|
phys_addr_t abase = base & ~(size - 1);
|
|
|
|
phys_addr_t asize = base + size - abase;
|
|
|
|
phys_addr_t p2size = 1 << __fls(asize);
|
|
|
|
phys_addr_t bdiff, sdiff;
|
|
|
|
|
|
|
|
if (p2size != asize)
|
|
|
|
p2size *= 2;
|
|
|
|
|
|
|
|
bdiff = base - abase;
|
|
|
|
sdiff = p2size - asize;
|
2018-04-03 16:36:37 +07:00
|
|
|
subreg = p2size / PMSAv7_NR_SUBREGS;
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
|
|
|
|
if ((bdiff % subreg) || (sdiff % subreg))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bslots = bdiff / subreg;
|
|
|
|
sslots = sdiff / subreg;
|
|
|
|
|
|
|
|
if (bslots || sslots) {
|
|
|
|
int i;
|
|
|
|
|
2018-04-03 16:36:37 +07:00
|
|
|
if (subreg < PMSAv7_MIN_SUBREG_SIZE)
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
return false;
|
|
|
|
|
2018-04-03 16:36:37 +07:00
|
|
|
if (bslots + sslots > PMSAv7_NR_SUBREGS)
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
for (i = 0; i < bslots; i++)
|
|
|
|
_set_bit(i, ®ion->subreg);
|
|
|
|
|
|
|
|
for (i = 1; i <= sslots; i++)
|
2018-04-03 16:36:37 +07:00
|
|
|
_set_bit(PMSAv7_NR_SUBREGS - i, ®ion->subreg);
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
region->base = abase;
|
|
|
|
region->size = p2size;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init allocate_region(phys_addr_t base, phys_addr_t size,
|
|
|
|
unsigned int limit, struct region *regions)
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
phys_addr_t diff = size;
|
|
|
|
int attempts = MPU_MAX_REGIONS;
|
|
|
|
|
|
|
|
while (diff) {
|
|
|
|
/* Try cover region as is (maybe with help of subregions) */
|
|
|
|
if (try_split_region(base, size, ®ions[count])) {
|
|
|
|
count++;
|
|
|
|
base += size;
|
|
|
|
diff -= size;
|
|
|
|
size = diff;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Maximum aligned region might overflow phys_addr_t
|
|
|
|
* if "base" is 0. Hence we keep everything below 4G
|
|
|
|
* until we take the smaller of the aligned region
|
|
|
|
* size ("asize") and rounded region size ("p2size"),
|
|
|
|
* one of which is guaranteed to be smaller than the
|
|
|
|
* maximum physical address.
|
|
|
|
*/
|
|
|
|
phys_addr_t asize = (base - 1) ^ base;
|
|
|
|
phys_addr_t p2size = (1 << __fls(diff)) - 1;
|
|
|
|
|
|
|
|
size = asize < p2size ? asize + 1 : p2size + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > limit)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!attempts)
|
|
|
|
break;
|
|
|
|
|
|
|
|
attempts--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2017-10-16 18:52:35 +07:00
|
|
|
/* MPU initialisation functions */
|
2018-04-03 16:36:37 +07:00
|
|
|
void __init pmsav7_adjust_lowmem_bounds(void)
|
2017-10-16 18:52:35 +07:00
|
|
|
{
|
2017-11-02 19:20:31 +07:00
|
|
|
phys_addr_t specified_mem_size = 0, total_mem_size = 0;
|
2017-10-16 18:52:35 +07:00
|
|
|
struct memblock_region *reg;
|
|
|
|
bool first = true;
|
|
|
|
phys_addr_t mem_start;
|
|
|
|
phys_addr_t mem_end;
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
unsigned int mem_max_regions;
|
|
|
|
int num, i;
|
2017-10-16 18:52:35 +07:00
|
|
|
|
2018-04-03 16:36:37 +07:00
|
|
|
/* Free-up PMSAv7_PROBE_REGION */
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
mpu_min_region_order = __mpu_min_region_order();
|
|
|
|
|
|
|
|
/* How many regions are supported */
|
|
|
|
mpu_max_regions = __mpu_max_regions();
|
|
|
|
|
|
|
|
mem_max_regions = min((unsigned int)MPU_MAX_REGIONS, mpu_max_regions);
|
|
|
|
|
|
|
|
/* We need to keep one slot for background region */
|
|
|
|
mem_max_regions--;
|
|
|
|
|
|
|
|
#ifndef CONFIG_CPU_V7M
|
|
|
|
/* ... and one for vectors */
|
|
|
|
mem_max_regions--;
|
|
|
|
#endif
|
2017-10-16 19:00:45 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_XIP_KERNEL
|
|
|
|
/* plus some regions to cover XIP ROM */
|
|
|
|
num = allocate_region(CONFIG_XIP_PHYS_ADDR, __pa(_exiprom) - CONFIG_XIP_PHYS_ADDR,
|
|
|
|
mem_max_regions, xip);
|
|
|
|
|
|
|
|
mem_max_regions -= num;
|
|
|
|
#endif
|
|
|
|
|
2017-10-16 18:52:35 +07:00
|
|
|
for_each_memblock(memory, reg) {
|
|
|
|
if (first) {
|
2017-10-16 19:00:45 +07:00
|
|
|
phys_addr_t phys_offset = PHYS_OFFSET;
|
|
|
|
|
2017-10-16 18:52:35 +07:00
|
|
|
/*
|
|
|
|
* Initially only use memory continuous from
|
|
|
|
* PHYS_OFFSET */
|
|
|
|
if (reg->base != phys_offset)
|
|
|
|
panic("First memory bank must be contiguous from PHYS_OFFSET");
|
|
|
|
|
|
|
|
mem_start = reg->base;
|
|
|
|
mem_end = reg->base + reg->size;
|
|
|
|
specified_mem_size = reg->size;
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* memblock auto merges contiguous blocks, remove
|
|
|
|
* all blocks afterwards in one go (we can't remove
|
|
|
|
* blocks separately while iterating)
|
|
|
|
*/
|
|
|
|
pr_notice("Ignoring RAM after %pa, memory at %pa ignored\n",
|
|
|
|
&mem_end, ®->base);
|
|
|
|
memblock_remove(reg->base, 0 - reg->base);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-03 16:09:33 +07:00
|
|
|
memset(mem, 0, sizeof(mem));
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
num = allocate_region(mem_start, specified_mem_size, mem_max_regions, mem);
|
2017-10-16 18:52:35 +07:00
|
|
|
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
for (i = 0; i < num; i++) {
|
2018-04-03 16:36:37 +07:00
|
|
|
unsigned long subreg = mem[i].size / PMSAv7_NR_SUBREGS;
|
2017-10-16 18:52:35 +07:00
|
|
|
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
total_mem_size += mem[i].size - subreg * hweight_long(mem[i].subreg);
|
2017-10-16 18:52:35 +07:00
|
|
|
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
pr_debug("MPU: base %pa size %pa disable subregions: %*pbl\n",
|
2018-04-03 16:36:37 +07:00
|
|
|
&mem[i].base, &mem[i].size, PMSAv7_NR_SUBREGS, &mem[i].subreg);
|
2017-10-16 18:52:35 +07:00
|
|
|
}
|
|
|
|
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
if (total_mem_size != specified_mem_size) {
|
|
|
|
pr_warn("Truncating memory from %pa to %pa (MPU region constraints)",
|
|
|
|
&specified_mem_size, &total_mem_size);
|
|
|
|
memblock_remove(mem_start + total_mem_size,
|
|
|
|
specified_mem_size - total_mem_size);
|
|
|
|
}
|
2017-10-16 18:52:35 +07:00
|
|
|
}
|
|
|
|
|
2017-10-16 18:54:05 +07:00
|
|
|
static int __init __mpu_max_regions(void)
|
2017-10-16 18:52:35 +07:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We don't support a different number of I/D side regions so if we
|
|
|
|
* have separate instruction and data memory maps then return
|
|
|
|
* whichever side has a smaller number of supported regions.
|
|
|
|
*/
|
|
|
|
u32 dregions, iregions, mpuir;
|
2017-10-16 18:54:05 +07:00
|
|
|
|
2017-10-16 18:57:48 +07:00
|
|
|
mpuir = read_cpuid_mputype();
|
2017-10-16 18:52:35 +07:00
|
|
|
|
|
|
|
dregions = iregions = (mpuir & MPUIR_DREGION_SZMASK) >> MPUIR_DREGION;
|
|
|
|
|
|
|
|
/* Check for separate d-side and i-side memory maps */
|
|
|
|
if (mpuir & MPUIR_nU)
|
|
|
|
iregions = (mpuir & MPUIR_IREGION_SZMASK) >> MPUIR_IREGION;
|
|
|
|
|
|
|
|
/* Use the smallest of the two maxima */
|
|
|
|
return min(dregions, iregions);
|
|
|
|
}
|
|
|
|
|
2017-10-16 18:54:05 +07:00
|
|
|
static int __init mpu_iside_independent(void)
|
2017-10-16 18:52:35 +07:00
|
|
|
{
|
|
|
|
/* MPUIR.nU specifies whether there is *not* a unified memory map */
|
2017-10-16 18:57:48 +07:00
|
|
|
return read_cpuid_mputype() & MPUIR_nU;
|
2017-10-16 18:52:35 +07:00
|
|
|
}
|
|
|
|
|
2017-10-16 18:54:05 +07:00
|
|
|
static int __init __mpu_min_region_order(void)
|
2017-10-16 18:52:35 +07:00
|
|
|
{
|
|
|
|
u32 drbar_result, irbar_result;
|
2017-10-16 18:54:05 +07:00
|
|
|
|
2017-10-16 18:52:35 +07:00
|
|
|
/* We've kept a region free for this probing */
|
2018-04-03 16:36:37 +07:00
|
|
|
rgnr_write(PMSAv7_PROBE_REGION);
|
2017-10-16 18:52:35 +07:00
|
|
|
isb();
|
|
|
|
/*
|
|
|
|
* As per ARM ARM, write 0xFFFFFFFC to DRBAR to find the minimum
|
|
|
|
* region order
|
|
|
|
*/
|
|
|
|
drbar_write(0xFFFFFFFC);
|
|
|
|
drbar_result = irbar_result = drbar_read();
|
|
|
|
drbar_write(0x0);
|
|
|
|
/* If the MPU is non-unified, we use the larger of the two minima*/
|
|
|
|
if (mpu_iside_independent()) {
|
|
|
|
irbar_write(0xFFFFFFFC);
|
|
|
|
irbar_result = irbar_read();
|
|
|
|
irbar_write(0x0);
|
|
|
|
}
|
|
|
|
isb(); /* Ensure that MPU region operations have completed */
|
|
|
|
/* Return whichever result is larger */
|
2017-10-16 18:54:05 +07:00
|
|
|
|
2017-10-16 18:52:35 +07:00
|
|
|
return __ffs(max(drbar_result, irbar_result));
|
|
|
|
}
|
|
|
|
|
2017-10-16 18:54:05 +07:00
|
|
|
static int __init mpu_setup_region(unsigned int number, phys_addr_t start,
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
unsigned int size_order, unsigned int properties,
|
2017-10-16 19:00:45 +07:00
|
|
|
unsigned int subregions, bool need_flush)
|
2017-10-16 18:52:35 +07:00
|
|
|
{
|
|
|
|
u32 size_data;
|
|
|
|
|
|
|
|
/* We kept a region free for probing resolution of MPU regions*/
|
2017-10-16 18:54:05 +07:00
|
|
|
if (number > mpu_max_regions
|
|
|
|
|| number >= MPU_MAX_REGIONS)
|
2017-10-16 18:52:35 +07:00
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
if (size_order > 32)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2017-10-16 18:54:05 +07:00
|
|
|
if (size_order < mpu_min_region_order)
|
2017-10-16 18:52:35 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* Writing N to bits 5:1 (RSR_SZ) specifies region size 2^N+1 */
|
2018-04-03 16:36:37 +07:00
|
|
|
size_data = ((size_order - 1) << PMSAv7_RSR_SZ) | 1 << PMSAv7_RSR_EN;
|
|
|
|
size_data |= subregions << PMSAv7_RSR_SD;
|
2017-10-16 18:52:35 +07:00
|
|
|
|
2017-10-16 19:00:45 +07:00
|
|
|
if (need_flush)
|
|
|
|
flush_cache_all();
|
|
|
|
|
2017-10-16 18:52:35 +07:00
|
|
|
dsb(); /* Ensure all previous data accesses occur with old mappings */
|
|
|
|
rgnr_write(number);
|
|
|
|
isb();
|
|
|
|
drbar_write(start);
|
|
|
|
dracr_write(properties);
|
|
|
|
isb(); /* Propagate properties before enabling region */
|
|
|
|
drsr_write(size_data);
|
|
|
|
|
|
|
|
/* Check for independent I-side registers */
|
|
|
|
if (mpu_iside_independent()) {
|
|
|
|
irbar_write(start);
|
|
|
|
iracr_write(properties);
|
|
|
|
isb();
|
|
|
|
irsr_write(size_data);
|
|
|
|
}
|
|
|
|
isb();
|
|
|
|
|
|
|
|
/* Store region info (we treat i/d side the same, so only store d) */
|
|
|
|
mpu_rgn_info.rgns[number].dracr = properties;
|
|
|
|
mpu_rgn_info.rgns[number].drbar = start;
|
|
|
|
mpu_rgn_info.rgns[number].drsr = size_data;
|
2017-10-16 18:54:05 +07:00
|
|
|
|
|
|
|
mpu_rgn_info.used++;
|
|
|
|
|
2017-10-16 18:52:35 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up default MPU regions, doing nothing if there is no MPU
|
|
|
|
*/
|
2018-04-03 16:36:37 +07:00
|
|
|
void __init pmsav7_setup(void)
|
2017-10-16 18:52:35 +07:00
|
|
|
{
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
int i, region = 0, err = 0;
|
2017-10-16 18:54:05 +07:00
|
|
|
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
/* Setup MPU (order is important) */
|
2017-10-16 18:54:05 +07:00
|
|
|
|
|
|
|
/* Background */
|
|
|
|
err |= mpu_setup_region(region++, 0, 32,
|
2018-04-03 16:36:37 +07:00
|
|
|
PMSAv7_ACR_XN | PMSAv7_RGN_STRONGLY_ORDERED | PMSAv7_AP_PL1RW_PL0RW,
|
2017-10-16 19:00:45 +07:00
|
|
|
0, false);
|
|
|
|
|
|
|
|
#ifdef CONFIG_XIP_KERNEL
|
|
|
|
/* ROM */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(xip); i++) {
|
|
|
|
/*
|
|
|
|
* In case we overwrite RAM region we set earlier in
|
|
|
|
* head-nommu.S (which is cachable) all subsequent
|
|
|
|
* data access till we setup RAM bellow would be done
|
|
|
|
* with BG region (which is uncachable), thus we need
|
|
|
|
* to clean and invalidate cache.
|
|
|
|
*/
|
2018-04-03 16:36:37 +07:00
|
|
|
bool need_flush = region == PMSAv7_RAM_REGION;
|
2017-10-16 19:00:45 +07:00
|
|
|
|
|
|
|
if (!xip[i].size)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
err |= mpu_setup_region(region++, xip[i].base, ilog2(xip[i].size),
|
2018-04-03 16:36:37 +07:00
|
|
|
PMSAv7_AP_PL1RO_PL0NA | PMSAv7_RGN_NORMAL,
|
2017-10-16 19:00:45 +07:00
|
|
|
xip[i].subreg, need_flush);
|
|
|
|
}
|
|
|
|
#endif
|
2017-10-16 18:54:05 +07:00
|
|
|
|
|
|
|
/* RAM */
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
for (i = 0; i < ARRAY_SIZE(mem); i++) {
|
|
|
|
if (!mem[i].size)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
err |= mpu_setup_region(region++, mem[i].base, ilog2(mem[i].size),
|
2018-04-03 16:36:37 +07:00
|
|
|
PMSAv7_AP_PL1RW_PL0RW | PMSAv7_RGN_NORMAL,
|
2017-10-16 19:00:45 +07:00
|
|
|
mem[i].subreg, false);
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
}
|
2017-10-16 18:54:05 +07:00
|
|
|
|
|
|
|
/* Vectors */
|
2017-10-16 18:57:48 +07:00
|
|
|
#ifndef CONFIG_CPU_V7M
|
ARM: 8712/1: NOMMU: Use more MPU regions to cover memory
PMSAv7 defines curious alignment requirements to the regions:
- size must be power of 2, and
- region start must be aligned to the region size
Because of that we currently adjust lowmem bounds plus we assign
only one MPU region to cover memory all these lead to significant amount of
memory could be wasted. As an example, consider 64Mb of memory at
0x70000000 - it fits alignment requirements nicely; now, imagine that
2Mb of memory is reserved for coherent DMA allocation, so now Linux is
expected to see 62Mb of memory... and here annoying thing happens -
memory gets truncated to 32Mb (we've lost 30Mb!), i.e. MPU layout
looks like:
0: base 0x70000000, size 0x2000000
This patch tries to allocate as much as possible MPU slots to minimise
amount of truncated memory. Moreover, with this patch MPU subregions
starting to get used. MPU subregions allow us reduce the number of MPU
slots used. For example given above, MPU layout looks like:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x1000000, disable subreg 7 (0x73e00000 - 0x73ffffff)
Where without subregions we'd get:
0: base 0x70000000, size 0x2000000
1: base 0x72000000, size 0x1000000
2: base 0x73000000, size 0x800000
3: base 0x73800000, size 0x400000
4: base 0x73c00000, size 0x200000
To achieve better layout we fist try to cover specified memory as is
(maybe with help of subregions) and if we failed, we truncate memory
to fit alignment requirements (so it occupies one MPU slot) and
perform one more attempt with the reminder, and so on till we either
cover all memory or run out of MPU slots.
Tested-by: Szemző András <sza@esh.hu>
Tested-by: Alexandre TORGUE <alexandre.torgue@st.com>
Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2017-10-16 18:59:15 +07:00
|
|
|
err |= mpu_setup_region(region++, vectors_base, ilog2(2 * PAGE_SIZE),
|
2018-04-03 16:36:37 +07:00
|
|
|
PMSAv7_AP_PL1RW_PL0NA | PMSAv7_RGN_NORMAL,
|
2017-10-16 19:00:45 +07:00
|
|
|
0, false);
|
2017-10-16 18:57:48 +07:00
|
|
|
#endif
|
2017-10-16 18:54:05 +07:00
|
|
|
if (err) {
|
|
|
|
panic("MPU region initialization failure! %d", err);
|
2017-10-16 18:52:35 +07:00
|
|
|
} else {
|
|
|
|
pr_info("Using ARMv7 PMSA Compliant MPU. "
|
2017-10-16 18:54:05 +07:00
|
|
|
"Region independence: %s, Used %d of %d regions\n",
|
2017-10-16 18:52:35 +07:00
|
|
|
mpu_iside_independent() ? "Yes" : "No",
|
2017-10-16 18:54:05 +07:00
|
|
|
mpu_rgn_info.used, mpu_max_regions);
|
2017-10-16 18:52:35 +07:00
|
|
|
}
|
|
|
|
}
|