mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-01-11 17:10:13 +00:00
Patch series "Add and use memdesc_flags_t". At some point struct page will be separated from struct slab and struct folio. This is a step towards that by introducing a type for the 'flags' word of all three structures. This gives us a certain amount of type safety by establishing that some of these unsigned longs are different from other unsigned longs in that they contain things like node ID, section number and zone number in the upper bits. That lets us have functions that can be easily called by anyone who has a slab, folio or page (but not easily by anyone else) to get the node or zone. There's going to be some unusual merge problems with this as some odd bits of the kernel decide they want to print out the flags value or something similar by writing page->flags and now they'll need to write page->flags.f instead. That's most of the churn here. Maybe we should be removing these things from the debug output? This patch (of 11): Wrap the unsigned long flags in a typedef. In upcoming patches, this will provide a strong hint that you can't just pass a random unsigned long to functions which take this as an argument. [willy@infradead.org: s/flags/flags.f/ in several architectures] Link: https://lkml.kernel.org/r/aKMgPRLD-WnkPxYm@casper.infradead.org [nicola.vetrini@gmail.com: mips: fix compilation error] Link: https://lore.kernel.org/lkml/CA+G9fYvkpmqGr6wjBNHY=dRp71PLCoi2341JxOudi60yqaeUdg@mail.gmail.com/ Link: https://lkml.kernel.org/r/20250825214245.1838158-1-nicola.vetrini@gmail.com Link: https://lkml.kernel.org/r/20250805172307.1302730-1-willy@infradead.org Link: https://lkml.kernel.org/r/20250805172307.1302730-2-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Acked-by: Zi Yan <ziy@nvidia.com> Cc: Shakeel Butt <shakeel.butt@linux.dev> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
201 lines
5.0 KiB
C
201 lines
5.0 KiB
C
/*
|
|
* arch/sh/mm/cache-sh7705.c
|
|
*
|
|
* Copyright (C) 1999, 2000 Niibe Yutaka
|
|
* Copyright (C) 2004 Alex Song
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
* for more details.
|
|
*
|
|
*/
|
|
#include <linux/init.h>
|
|
#include <linux/mman.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/pagemap.h>
|
|
#include <linux/threads.h>
|
|
#include <asm/addrspace.h>
|
|
#include <asm/page.h>
|
|
#include <asm/processor.h>
|
|
#include <asm/cache.h>
|
|
#include <asm/io.h>
|
|
#include <linux/uaccess.h>
|
|
#include <asm/mmu_context.h>
|
|
#include <asm/cacheflush.h>
|
|
|
|
/*
|
|
* The 32KB cache on the SH7705 suffers from the same synonym problem
|
|
* as SH4 CPUs
|
|
*/
|
|
static inline void cache_wback_all(void)
|
|
{
|
|
unsigned long ways, waysize, addrstart;
|
|
|
|
ways = current_cpu_data.dcache.ways;
|
|
waysize = current_cpu_data.dcache.sets;
|
|
waysize <<= current_cpu_data.dcache.entry_shift;
|
|
|
|
addrstart = CACHE_OC_ADDRESS_ARRAY;
|
|
|
|
do {
|
|
unsigned long addr;
|
|
|
|
for (addr = addrstart;
|
|
addr < addrstart + waysize;
|
|
addr += current_cpu_data.dcache.linesz) {
|
|
unsigned long data;
|
|
int v = SH_CACHE_UPDATED | SH_CACHE_VALID;
|
|
|
|
data = __raw_readl(addr);
|
|
|
|
if ((data & v) == v)
|
|
__raw_writel(data & ~v, addr);
|
|
|
|
}
|
|
|
|
addrstart += current_cpu_data.dcache.way_incr;
|
|
} while (--ways);
|
|
}
|
|
|
|
/*
|
|
* Write back the range of D-cache, and purge the I-cache.
|
|
*
|
|
* Called from kernel/module.c:sys_init_module and routine for a.out format.
|
|
*/
|
|
static void sh7705_flush_icache_range(void *args)
|
|
{
|
|
struct flusher_data *data = args;
|
|
unsigned long start, end;
|
|
|
|
start = data->addr1;
|
|
end = data->addr2;
|
|
|
|
__flush_wback_region((void *)start, end - start);
|
|
}
|
|
|
|
/*
|
|
* Writeback&Invalidate the D-cache of the page
|
|
*/
|
|
static void __flush_dcache_page(unsigned long phys)
|
|
{
|
|
unsigned long ways, waysize, addrstart;
|
|
unsigned long flags;
|
|
|
|
phys |= SH_CACHE_VALID;
|
|
|
|
/*
|
|
* Here, phys is the physical address of the page. We check all the
|
|
* tags in the cache for those with the same page number as this page
|
|
* (by masking off the lowest 2 bits of the 19-bit tag; these bits are
|
|
* derived from the offset within in the 4k page). Matching valid
|
|
* entries are invalidated.
|
|
*
|
|
* Since 2 bits of the cache index are derived from the virtual page
|
|
* number, knowing this would reduce the number of cache entries to be
|
|
* searched by a factor of 4. However this function exists to deal with
|
|
* potential cache aliasing, therefore the optimisation is probably not
|
|
* possible.
|
|
*/
|
|
local_irq_save(flags);
|
|
jump_to_uncached();
|
|
|
|
ways = current_cpu_data.dcache.ways;
|
|
waysize = current_cpu_data.dcache.sets;
|
|
waysize <<= current_cpu_data.dcache.entry_shift;
|
|
|
|
addrstart = CACHE_OC_ADDRESS_ARRAY;
|
|
|
|
do {
|
|
unsigned long addr;
|
|
|
|
for (addr = addrstart;
|
|
addr < addrstart + waysize;
|
|
addr += current_cpu_data.dcache.linesz) {
|
|
unsigned long data;
|
|
|
|
data = __raw_readl(addr) & (0x1ffffC00 | SH_CACHE_VALID);
|
|
if (data == phys) {
|
|
data &= ~(SH_CACHE_VALID | SH_CACHE_UPDATED);
|
|
__raw_writel(data, addr);
|
|
}
|
|
}
|
|
|
|
addrstart += current_cpu_data.dcache.way_incr;
|
|
} while (--ways);
|
|
|
|
back_to_cached();
|
|
local_irq_restore(flags);
|
|
}
|
|
|
|
/*
|
|
* Write back & invalidate the D-cache of the page.
|
|
* (To avoid "alias" issues)
|
|
*/
|
|
static void sh7705_flush_dcache_folio(void *arg)
|
|
{
|
|
struct folio *folio = arg;
|
|
struct address_space *mapping = folio_flush_mapping(folio);
|
|
|
|
if (mapping && !mapping_mapped(mapping))
|
|
clear_bit(PG_dcache_clean, &folio->flags.f);
|
|
else {
|
|
unsigned long pfn = folio_pfn(folio);
|
|
unsigned int i, nr = folio_nr_pages(folio);
|
|
|
|
for (i = 0; i < nr; i++)
|
|
__flush_dcache_page((pfn + i) * PAGE_SIZE);
|
|
}
|
|
}
|
|
|
|
static void sh7705_flush_cache_all(void *args)
|
|
{
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
|
jump_to_uncached();
|
|
|
|
cache_wback_all();
|
|
back_to_cached();
|
|
local_irq_restore(flags);
|
|
}
|
|
|
|
/*
|
|
* Write back and invalidate I/D-caches for the page.
|
|
*
|
|
* ADDRESS: Virtual Address (U0 address)
|
|
*/
|
|
static void sh7705_flush_cache_page(void *args)
|
|
{
|
|
struct flusher_data *data = args;
|
|
unsigned long pfn = data->addr2;
|
|
|
|
__flush_dcache_page(pfn << PAGE_SHIFT);
|
|
}
|
|
|
|
/*
|
|
* This is called when a page-cache page is about to be mapped into a
|
|
* user process' address space. It offers an opportunity for a
|
|
* port to ensure d-cache/i-cache coherency if necessary.
|
|
*
|
|
* Not entirely sure why this is necessary on SH3 with 32K cache but
|
|
* without it we get occasional "Memory fault" when loading a program.
|
|
*/
|
|
static void sh7705_flush_icache_folio(void *arg)
|
|
{
|
|
struct folio *folio = arg;
|
|
__flush_purge_region(folio_address(folio), folio_size(folio));
|
|
}
|
|
|
|
void __init sh7705_cache_init(void)
|
|
{
|
|
local_flush_icache_range = sh7705_flush_icache_range;
|
|
local_flush_dcache_folio = sh7705_flush_dcache_folio;
|
|
local_flush_cache_all = sh7705_flush_cache_all;
|
|
local_flush_cache_mm = sh7705_flush_cache_all;
|
|
local_flush_cache_dup_mm = sh7705_flush_cache_all;
|
|
local_flush_cache_range = sh7705_flush_cache_all;
|
|
local_flush_cache_page = sh7705_flush_cache_page;
|
|
local_flush_icache_folio = sh7705_flush_icache_folio;
|
|
}
|