2019-05-27 08:55:01 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2015-11-04 17:26:10 +01:00
|
|
|
/*
|
|
|
|
* OpenRISC cache.c
|
|
|
|
*
|
|
|
|
* Linux architectural port borrowing liberally from similar works of
|
|
|
|
* others. All original copyrights apply as per the original source
|
|
|
|
* declaration.
|
|
|
|
*
|
|
|
|
* Modifications for the OpenRISC architecture:
|
|
|
|
* Copyright (C) 2015 Jan Henrik Weinstock <jan.weinstock@rwth-aachen.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <asm/spr.h>
|
|
|
|
#include <asm/spr_defs.h>
|
|
|
|
#include <asm/cache.h>
|
|
|
|
#include <asm/cacheflush.h>
|
2025-04-19 21:18:18 +05:30
|
|
|
#include <asm/cpuinfo.h>
|
2015-11-04 17:26:10 +01:00
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
|
2025-04-19 21:18:18 +05:30
|
|
|
/*
|
|
|
|
* Check if the cache component exists.
|
|
|
|
*/
|
|
|
|
bool cpu_cache_is_present(const unsigned int cache_type)
|
2015-11-04 17:26:10 +01:00
|
|
|
{
|
2025-04-19 21:18:18 +05:30
|
|
|
unsigned long upr = mfspr(SPR_UPR);
|
|
|
|
unsigned long mask = SPR_UPR_UP | cache_type;
|
|
|
|
|
|
|
|
return !((upr & mask) ^ mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline void cache_loop(unsigned long paddr, unsigned long end,
|
|
|
|
const unsigned short reg, const unsigned int cache_type)
|
|
|
|
{
|
|
|
|
if (!cpu_cache_is_present(cache_type))
|
|
|
|
return;
|
2015-11-04 17:26:10 +01:00
|
|
|
|
2025-04-19 21:18:18 +05:30
|
|
|
while (paddr < end) {
|
|
|
|
mtspr(reg, paddr);
|
|
|
|
paddr += L1_CACHE_BYTES;
|
2015-11-04 17:26:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-19 21:18:18 +05:30
|
|
|
static __always_inline void cache_loop_page(struct page *page, const unsigned short reg,
|
|
|
|
const unsigned int cache_type)
|
|
|
|
{
|
|
|
|
unsigned long paddr = page_to_pfn(page) << PAGE_SHIFT;
|
|
|
|
unsigned long end = paddr + PAGE_SIZE;
|
|
|
|
|
|
|
|
paddr &= ~(L1_CACHE_BYTES - 1);
|
|
|
|
|
|
|
|
cache_loop(paddr, end, reg, cache_type);
|
|
|
|
}
|
|
|
|
|
2015-11-04 17:26:10 +01:00
|
|
|
void local_dcache_page_flush(struct page *page)
|
|
|
|
{
|
2025-04-19 21:18:18 +05:30
|
|
|
cache_loop_page(page, SPR_DCBFR, SPR_UPR_DCP);
|
2015-11-04 17:26:10 +01:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(local_dcache_page_flush);
|
|
|
|
|
|
|
|
void local_icache_page_inv(struct page *page)
|
|
|
|
{
|
2025-04-19 21:18:18 +05:30
|
|
|
cache_loop_page(page, SPR_ICBIR, SPR_UPR_ICP);
|
2015-11-04 17:26:10 +01:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(local_icache_page_inv);
|
|
|
|
|
2025-04-19 21:18:18 +05:30
|
|
|
void local_dcache_range_flush(unsigned long start, unsigned long end)
|
|
|
|
{
|
|
|
|
cache_loop(start, end, SPR_DCBFR, SPR_UPR_DCP);
|
|
|
|
}
|
|
|
|
|
|
|
|
void local_dcache_range_inv(unsigned long start, unsigned long end)
|
|
|
|
{
|
|
|
|
cache_loop(start, end, SPR_DCBIR, SPR_UPR_DCP);
|
|
|
|
}
|
|
|
|
|
|
|
|
void local_icache_range_inv(unsigned long start, unsigned long end)
|
|
|
|
{
|
|
|
|
cache_loop(start, end, SPR_ICBIR, SPR_UPR_ICP);
|
|
|
|
}
|
|
|
|
|
2015-11-04 17:26:10 +01:00
|
|
|
void update_cache(struct vm_area_struct *vma, unsigned long address,
|
|
|
|
pte_t *pte)
|
|
|
|
{
|
|
|
|
unsigned long pfn = pte_val(*pte) >> PAGE_SHIFT;
|
2023-08-02 16:13:47 +01:00
|
|
|
struct folio *folio = page_folio(pfn_to_page(pfn));
|
|
|
|
int dirty = !test_and_set_bit(PG_dc_clean, &folio->flags);
|
2015-11-04 17:26:10 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Since icaches do not snoop for updated data on OpenRISC, we
|
|
|
|
* must write back and invalidate any dirty pages manually. We
|
|
|
|
* can skip data pages, since they will not end up in icaches.
|
|
|
|
*/
|
2023-08-02 16:13:47 +01:00
|
|
|
if ((vma->vm_flags & VM_EXEC) && dirty) {
|
|
|
|
unsigned int nr = folio_nr_pages(folio);
|
|
|
|
|
|
|
|
while (nr--)
|
|
|
|
sync_icache_dcache(folio_page(folio, nr));
|
|
|
|
}
|
2015-11-04 17:26:10 +01:00
|
|
|
}
|