xref: /openbmc/linux/arch/mips/include/asm/maar.h (revision e060f6ed)
1ab9988a3SPaul Burton /*
2ab9988a3SPaul Burton  * Copyright (C) 2014 Imagination Technologies
3ab9988a3SPaul Burton  * Author: Paul Burton <paul.burton@imgtec.com>
4ab9988a3SPaul Burton  *
5ab9988a3SPaul Burton  * This program is free software; you can redistribute it and/or modify it
6ab9988a3SPaul Burton  * under the terms of the GNU General Public License as published by the
7ab9988a3SPaul Burton  * Free Software Foundation;  either version 2 of the  License, or (at your
8ab9988a3SPaul Burton  * option) any later version.
9ab9988a3SPaul Burton  */
10ab9988a3SPaul Burton 
11ab9988a3SPaul Burton #ifndef __MIPS_ASM_MIPS_MAAR_H__
12ab9988a3SPaul Burton #define __MIPS_ASM_MIPS_MAAR_H__
13ab9988a3SPaul Burton 
14ab9988a3SPaul Burton #include <asm/hazards.h>
15ab9988a3SPaul Burton #include <asm/mipsregs.h>
16ab9988a3SPaul Burton 
17ab9988a3SPaul Burton /**
18ab9988a3SPaul Burton  * platform_maar_init() - perform platform-level MAAR configuration
19ab9988a3SPaul Burton  * @num_pairs:	The number of MAAR pairs present in the system.
20ab9988a3SPaul Burton  *
21ab9988a3SPaul Burton  * Platforms should implement this function such that it configures as many
22ab9988a3SPaul Burton  * MAAR pairs as required, from 0 up to the maximum of num_pairs-1, and returns
23ab9988a3SPaul Burton  * the number that were used. Any further MAARs will be configured to be
24ab9988a3SPaul Burton  * invalid. The default implementation of this function will simply indicate
25ab9988a3SPaul Burton  * that it has configured 0 MAAR pairs.
26ab9988a3SPaul Burton  *
27ab9988a3SPaul Burton  * Return:	The number of MAAR pairs configured.
28ab9988a3SPaul Burton  */
2927d8d449SBjorn Helgaas unsigned platform_maar_init(unsigned num_pairs);
30ab9988a3SPaul Burton 
31ab9988a3SPaul Burton /**
32ab9988a3SPaul Burton  * write_maar_pair() - write to a pair of MAARs
33ab9988a3SPaul Burton  * @idx:	The index of the pair (ie. use MAARs idx*2 & (idx*2)+1).
34ab9988a3SPaul Burton  * @lower:	The lowest address that the MAAR pair will affect. Must be
35ab9988a3SPaul Burton  *		aligned to a 2^16 byte boundary.
36ab9988a3SPaul Burton  * @upper:	The highest address that the MAAR pair will affect. Must be
37ab9988a3SPaul Burton  *		aligned to one byte before a 2^16 byte boundary.
38ab9988a3SPaul Burton  * @attrs:	The accessibility attributes to program, eg. MIPS_MAAR_S. The
39ab9988a3SPaul Burton  *		MIPS_MAAR_V attribute will automatically be set.
40ab9988a3SPaul Burton  *
41ab9988a3SPaul Burton  * Program the pair of MAAR registers specified by idx to apply the attributes
42ab9988a3SPaul Burton  * specified by attrs to the range of addresses from lower to higher.
43ab9988a3SPaul Burton  */
44ab9988a3SPaul Burton static inline void write_maar_pair(unsigned idx, phys_addr_t lower,
45ab9988a3SPaul Burton 				   phys_addr_t upper, unsigned attrs)
46ab9988a3SPaul Burton {
47ab9988a3SPaul Burton 	/* Addresses begin at bit 16, but are shifted right 4 bits */
48ab9988a3SPaul Burton 	BUG_ON(lower & (0xffff | ~(MIPS_MAAR_ADDR << 4)));
49ab9988a3SPaul Burton 	BUG_ON(((upper & 0xffff) != 0xffff)
50ab9988a3SPaul Burton 		|| ((upper & ~0xffffull) & ~(MIPS_MAAR_ADDR << 4)));
51ab9988a3SPaul Burton 
52ab9988a3SPaul Burton 	/* Automatically set MIPS_MAAR_V */
53ab9988a3SPaul Burton 	attrs |= MIPS_MAAR_V;
54ab9988a3SPaul Burton 
55ab9988a3SPaul Burton 	/* Write the upper address & attributes (only MIPS_MAAR_V matters) */
56ab9988a3SPaul Burton 	write_c0_maari(idx << 1);
57ab9988a3SPaul Burton 	back_to_back_c0_hazard();
58ab9988a3SPaul Burton 	write_c0_maar(((upper >> 4) & MIPS_MAAR_ADDR) | attrs);
59ab9988a3SPaul Burton 	back_to_back_c0_hazard();
60ab9988a3SPaul Burton 
61ab9988a3SPaul Burton 	/* Write the lower address & attributes */
62ab9988a3SPaul Burton 	write_c0_maari((idx << 1) | 0x1);
63ab9988a3SPaul Burton 	back_to_back_c0_hazard();
64ab9988a3SPaul Burton 	write_c0_maar((lower >> 4) | attrs);
65ab9988a3SPaul Burton 	back_to_back_c0_hazard();
66ab9988a3SPaul Burton }
67ab9988a3SPaul Burton 
68ab9988a3SPaul Burton /**
69e060f6edSPaul Burton  * maar_init() - initialise MAARs
70e060f6edSPaul Burton  *
71e060f6edSPaul Burton  * Performs initialisation of MAARs for the current CPU, making use of the
72e060f6edSPaul Burton  * platforms implementation of platform_maar_init where necessary and
73e060f6edSPaul Burton  * duplicating the setup it provides on secondary CPUs.
74e060f6edSPaul Burton  */
75e060f6edSPaul Burton extern void maar_init(void);
76e060f6edSPaul Burton 
77e060f6edSPaul Burton /**
78ab9988a3SPaul Burton  * struct maar_config - MAAR configuration data
79ab9988a3SPaul Burton  * @lower:	The lowest address that the MAAR pair will affect. Must be
80ab9988a3SPaul Burton  *		aligned to a 2^16 byte boundary.
81ab9988a3SPaul Burton  * @upper:	The highest address that the MAAR pair will affect. Must be
82ab9988a3SPaul Burton  *		aligned to one byte before a 2^16 byte boundary.
83ab9988a3SPaul Burton  * @attrs:	The accessibility attributes to program, eg. MIPS_MAAR_S. The
84ab9988a3SPaul Burton  *		MIPS_MAAR_V attribute will automatically be set.
85ab9988a3SPaul Burton  *
86ab9988a3SPaul Burton  * Describes the configuration of a pair of Memory Accessibility Attribute
87ab9988a3SPaul Burton  * Registers - applying attributes from attrs to the range of physical
88ab9988a3SPaul Burton  * addresses from lower to upper inclusive.
89ab9988a3SPaul Burton  */
90ab9988a3SPaul Burton struct maar_config {
91ab9988a3SPaul Burton 	phys_addr_t lower;
92ab9988a3SPaul Burton 	phys_addr_t upper;
93ab9988a3SPaul Burton 	unsigned attrs;
94ab9988a3SPaul Burton };
95ab9988a3SPaul Burton 
96ab9988a3SPaul Burton /**
97ab9988a3SPaul Burton  * maar_config() - configure MAARs according to provided data
98ab9988a3SPaul Burton  * @cfg:	Pointer to an array of struct maar_config.
99ab9988a3SPaul Burton  * @num_cfg:	The number of structs in the cfg array.
100ab9988a3SPaul Burton  * @num_pairs:	The number of MAAR pairs present in the system.
101ab9988a3SPaul Burton  *
102ab9988a3SPaul Burton  * Configures as many MAARs as are present and specified in the cfg
103ab9988a3SPaul Burton  * array with the values taken from the cfg array.
104ab9988a3SPaul Burton  *
105ab9988a3SPaul Burton  * Return:	The number of MAAR pairs configured.
106ab9988a3SPaul Burton  */
107ab9988a3SPaul Burton static inline unsigned maar_config(const struct maar_config *cfg,
108ab9988a3SPaul Burton 				   unsigned num_cfg, unsigned num_pairs)
109ab9988a3SPaul Burton {
110ab9988a3SPaul Burton 	unsigned i;
111ab9988a3SPaul Burton 
112ab9988a3SPaul Burton 	for (i = 0; i < min(num_cfg, num_pairs); i++)
113ab9988a3SPaul Burton 		write_maar_pair(i, cfg[i].lower, cfg[i].upper, cfg[i].attrs);
114ab9988a3SPaul Burton 
115ab9988a3SPaul Burton 	return i;
116ab9988a3SPaul Burton }
117ab9988a3SPaul Burton 
118ab9988a3SPaul Burton #endif /* __MIPS_ASM_MIPS_MAAR_H__ */
119