Skip to content

Commit 56f3c14

Browse files
chleroympe
authored andcommitted
powerpc/mm: properly set PAGE_KERNEL flags in ioremap()
Set PAGE_KERNEL directly in the caller and do not rely on a hack adding PAGE_KERNEL flags when _PAGE_PRESENT is not set. As already done for PPC64, use pgprot_cache() helpers instead of _PAGE_XXX flags in PPC32 ioremap() derived functions. Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent aa91796 commit 56f3c14

File tree

7 files changed

+24
-33
lines changed

7 files changed

+24
-33
lines changed

arch/powerpc/include/asm/nohash/pgtable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long addre
197197
#if _PAGE_WRITETHRU != 0
198198
#define pgprot_cached_wthru(prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \
199199
_PAGE_COHERENT | _PAGE_WRITETHRU))
200+
#else
201+
#define pgprot_cached_wthru(prot) pgprot_noncached(prot)
200202
#endif
201203

202204
#define pgprot_cached_noncoherent(prot) \

arch/powerpc/kernel/isa-bridge.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ static void pci_process_ISA_OF_ranges(struct device_node *isa_node,
110110
size = 0x10000;
111111

112112
__ioremap_at(phb_io_base_phys, (void *)ISA_IO_BASE,
113-
size, pgprot_val(pgprot_noncached(__pgprot(0))));
113+
size, pgprot_val(pgprot_noncached(PAGE_KERNEL)));
114114
return;
115115

116116
inval_range:
117117
printk(KERN_ERR "no ISA IO ranges or unexpected isa range, "
118118
"mapping 64k\n");
119119
__ioremap_at(phb_io_base_phys, (void *)ISA_IO_BASE,
120-
0x10000, pgprot_val(pgprot_noncached(__pgprot(0))));
120+
0x10000, pgprot_val(pgprot_noncached(PAGE_KERNEL)));
121121
}
122122

123123

@@ -253,7 +253,7 @@ void __init isa_bridge_init_non_pci(struct device_node *np)
253253
*/
254254
isa_io_base = ISA_IO_BASE;
255255
__ioremap_at(pbase, (void *)ISA_IO_BASE,
256-
size, pgprot_val(pgprot_noncached(__pgprot(0))));
256+
size, pgprot_val(pgprot_noncached(PAGE_KERNEL)));
257257

258258
pr_debug("ISA: Non-PCI bridge is %pOF\n", np);
259259
}

arch/powerpc/kernel/pci_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static int pcibios_map_phb_io_space(struct pci_controller *hose)
159159

160160
/* Establish the mapping */
161161
if (__ioremap_at(phys_page, area->addr, size_page,
162-
pgprot_val(pgprot_noncached(__pgprot(0)))) == NULL)
162+
pgprot_val(pgprot_noncached(PAGE_KERNEL))) == NULL)
163163
return -ENOMEM;
164164

165165
/* Fixup hose IO resource */

arch/powerpc/mm/pgtable_32.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,32 +76,36 @@ pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
7676
void __iomem *
7777
ioremap(phys_addr_t addr, unsigned long size)
7878
{
79-
return __ioremap_caller(addr, size, _PAGE_NO_CACHE | _PAGE_GUARDED,
80-
__builtin_return_address(0));
79+
unsigned long flags = pgprot_val(pgprot_noncached(PAGE_KERNEL));
80+
81+
return __ioremap_caller(addr, size, flags, __builtin_return_address(0));
8182
}
8283
EXPORT_SYMBOL(ioremap);
8384

8485
void __iomem *
8586
ioremap_wc(phys_addr_t addr, unsigned long size)
8687
{
87-
return __ioremap_caller(addr, size, _PAGE_NO_CACHE,
88-
__builtin_return_address(0));
88+
unsigned long flags = pgprot_val(pgprot_noncached_wc(PAGE_KERNEL));
89+
90+
return __ioremap_caller(addr, size, flags, __builtin_return_address(0));
8991
}
9092
EXPORT_SYMBOL(ioremap_wc);
9193

9294
void __iomem *
9395
ioremap_wt(phys_addr_t addr, unsigned long size)
9496
{
95-
return __ioremap_caller(addr, size, _PAGE_WRITETHRU,
96-
__builtin_return_address(0));
97+
unsigned long flags = pgprot_val(pgprot_cached_wthru(PAGE_KERNEL));
98+
99+
return __ioremap_caller(addr, size, flags, __builtin_return_address(0));
97100
}
98101
EXPORT_SYMBOL(ioremap_wt);
99102

100103
void __iomem *
101104
ioremap_coherent(phys_addr_t addr, unsigned long size)
102105
{
103-
return __ioremap_caller(addr, size, _PAGE_COHERENT,
104-
__builtin_return_address(0));
106+
unsigned long flags = pgprot_val(pgprot_cached(PAGE_KERNEL));
107+
108+
return __ioremap_caller(addr, size, flags, __builtin_return_address(0));
105109
}
106110
EXPORT_SYMBOL(ioremap_coherent);
107111

@@ -134,14 +138,6 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, unsigned long flags,
134138
phys_addr_t p;
135139
int err;
136140

137-
/* Make sure we have the base flags */
138-
if ((flags & _PAGE_PRESENT) == 0)
139-
flags |= pgprot_val(PAGE_KERNEL);
140-
141-
/* Non-cacheable page cannot be coherent */
142-
if (flags & _PAGE_NO_CACHE)
143-
flags &= ~_PAGE_COHERENT;
144-
145141
/*
146142
* Choose an address to map it to.
147143
* Once the vmalloc system is running, we use it.

arch/powerpc/mm/pgtable_64.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ void __iomem * __ioremap_at(phys_addr_t pa, void *ea, unsigned long size,
118118
{
119119
unsigned long i;
120120

121-
/* Make sure we have the base flags */
122-
if ((flags & _PAGE_PRESENT) == 0)
123-
flags |= pgprot_val(PAGE_KERNEL);
124-
125121
/* We don't support the 4K PFN hack with ioremap */
126122
if (flags & H_PAGE_4K_PFN)
127123
return NULL;
@@ -204,7 +200,7 @@ void __iomem * __ioremap(phys_addr_t addr, unsigned long size,
204200

205201
void __iomem * ioremap(phys_addr_t addr, unsigned long size)
206202
{
207-
unsigned long flags = pgprot_val(pgprot_noncached(__pgprot(0)));
203+
unsigned long flags = pgprot_val(pgprot_noncached(PAGE_KERNEL));
208204
void *caller = __builtin_return_address(0);
209205

210206
if (ppc_md.ioremap)
@@ -214,7 +210,7 @@ void __iomem * ioremap(phys_addr_t addr, unsigned long size)
214210

215211
void __iomem * ioremap_wc(phys_addr_t addr, unsigned long size)
216212
{
217-
unsigned long flags = pgprot_val(pgprot_noncached_wc(__pgprot(0)));
213+
unsigned long flags = pgprot_val(pgprot_noncached_wc(PAGE_KERNEL));
218214
void *caller = __builtin_return_address(0);
219215

220216
if (ppc_md.ioremap)
@@ -224,7 +220,7 @@ void __iomem * ioremap_wc(phys_addr_t addr, unsigned long size)
224220

225221
void __iomem *ioremap_coherent(phys_addr_t addr, unsigned long size)
226222
{
227-
unsigned long flags = pgprot_val(pgprot_cached(__pgprot(0)));
223+
unsigned long flags = pgprot_val(pgprot_cached(PAGE_KERNEL));
228224
void *caller = __builtin_return_address(0);
229225

230226
if (ppc_md.ioremap)

arch/powerpc/platforms/4xx/ocm.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ static void __init ocm_init_node(int count, struct device_node *node)
113113
int len;
114114

115115
struct resource rsrc;
116-
int ioflags;
117116

118117
ocm = ocm_get_node(count);
119118

@@ -179,9 +178,8 @@ static void __init ocm_init_node(int count, struct device_node *node)
179178

180179
/* ioremap the non-cached region */
181180
if (ocm->nc.memtotal) {
182-
ioflags = _PAGE_NO_CACHE | _PAGE_GUARDED | _PAGE_EXEC;
183181
ocm->nc.virt = __ioremap(ocm->nc.phys, ocm->nc.memtotal,
184-
ioflags);
182+
_PAGE_EXEC | PAGE_KERNEL_NCG);
185183

186184
if (!ocm->nc.virt) {
187185
printk(KERN_ERR
@@ -195,9 +193,8 @@ static void __init ocm_init_node(int count, struct device_node *node)
195193
/* ioremap the cached region */
196194

197195
if (ocm->c.memtotal) {
198-
ioflags = _PAGE_EXEC;
199196
ocm->c.virt = __ioremap(ocm->c.phys, ocm->c.memtotal,
200-
ioflags);
197+
_PAGE_EXEC | PAGE_KERNEL);
201198

202199
if (!ocm->c.virt) {
203200
printk(KERN_ERR

drivers/pcmcia/electra_cf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static int electra_cf_probe(struct platform_device *ofdev)
230230

231231
if (!cf->mem_base || !cf->io_virt || !cf->gpio_base ||
232232
(__ioremap_at(io.start, cf->io_virt, cf->io_size,
233-
pgprot_val(pgprot_noncached(__pgprot(0)))) == NULL)) {
233+
pgprot_val(pgprot_noncached(PAGE_KERNEL))) == NULL)) {
234234
dev_err(device, "can't ioremap ranges\n");
235235
status = -ENOMEM;
236236
goto fail1;

0 commit comments

Comments
 (0)