18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci#ifndef __ASM_CSKY_PAGE_H
48c2ecf20Sopenharmony_ci#define __ASM_CSKY_PAGE_H
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <asm/setup.h>
78c2ecf20Sopenharmony_ci#include <asm/cache.h>
88c2ecf20Sopenharmony_ci#include <linux/const.h>
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/*
118c2ecf20Sopenharmony_ci * PAGE_SHIFT determines the page size: 4KB
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci#define PAGE_SHIFT	12
148c2ecf20Sopenharmony_ci#define PAGE_SIZE	(_AC(1, UL) << PAGE_SHIFT)
158c2ecf20Sopenharmony_ci#define PAGE_MASK	(~(PAGE_SIZE - 1))
168c2ecf20Sopenharmony_ci#define THREAD_SIZE	(PAGE_SIZE * 2)
178c2ecf20Sopenharmony_ci#define THREAD_MASK	(~(THREAD_SIZE - 1))
188c2ecf20Sopenharmony_ci#define THREAD_SHIFT	(PAGE_SHIFT + 1)
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/*
228c2ecf20Sopenharmony_ci * For C-SKY "User-space:Kernel-space" is "2GB:2GB" fixed by hardware and there
238c2ecf20Sopenharmony_ci * are two segment registers (MSA0 + MSA1) to mapping 512MB + 512MB physical
248c2ecf20Sopenharmony_ci * address region. We use them mapping kernel 1GB direct-map address area and
258c2ecf20Sopenharmony_ci * for more than 1GB of memory we use highmem.
268c2ecf20Sopenharmony_ci */
278c2ecf20Sopenharmony_ci#define PAGE_OFFSET	0x80000000
288c2ecf20Sopenharmony_ci#define SSEG_SIZE	0x20000000
298c2ecf20Sopenharmony_ci#define LOWMEM_LIMIT	(SSEG_SIZE * 2)
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define PHYS_OFFSET_OFFSET (CONFIG_DRAM_BASE & (SSEG_SIZE - 1))
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#include <linux/pfn.h>
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#define virt_to_pfn(kaddr)      (__pa(kaddr) >> PAGE_SHIFT)
388c2ecf20Sopenharmony_ci#define pfn_to_virt(pfn)        __va((pfn) << PAGE_SHIFT)
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define virt_addr_valid(kaddr)  ((void *)(kaddr) >= (void *)PAGE_OFFSET && \
418c2ecf20Sopenharmony_ci			(void *)(kaddr) < high_memory)
428c2ecf20Sopenharmony_ci#define pfn_valid(pfn)		((pfn) >= ARCH_PFN_OFFSET && ((pfn) - ARCH_PFN_OFFSET) < max_mapnr)
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ciextern void *memset(void *dest, int c, size_t l);
458c2ecf20Sopenharmony_ciextern void *memcpy(void *to, const void *from, size_t l);
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#define clear_page(page)	memset((page), 0, PAGE_SIZE)
488c2ecf20Sopenharmony_ci#define copy_page(to, from)	memcpy((to), (from), PAGE_SIZE)
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#define page_to_phys(page)	(page_to_pfn(page) << PAGE_SHIFT)
518c2ecf20Sopenharmony_ci#define phys_to_page(paddr)	(pfn_to_page(PFN_DOWN(paddr)))
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistruct page;
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#include <abi/page.h>
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cistruct vm_area_struct;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_citypedef struct { unsigned long pte_low; } pte_t;
608c2ecf20Sopenharmony_ci#define pte_val(x)	((x).pte_low)
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_citypedef struct { unsigned long pgd; } pgd_t;
638c2ecf20Sopenharmony_citypedef struct { unsigned long pgprot; } pgprot_t;
648c2ecf20Sopenharmony_citypedef struct page *pgtable_t;
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define pgd_val(x)	((x).pgd)
678c2ecf20Sopenharmony_ci#define pgprot_val(x)	((x).pgprot)
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#define ptep_buddy(x)	((pte_t *)((unsigned long)(x) ^ sizeof(pte_t)))
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define __pte(x)	((pte_t) { (x) })
728c2ecf20Sopenharmony_ci#define __pgd(x)	((pgd_t) { (x) })
738c2ecf20Sopenharmony_ci#define __pgprot(x)	((pgprot_t) { (x) })
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ciextern unsigned long va_pa_offset;
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#define ARCH_PFN_OFFSET	PFN_DOWN(va_pa_offset + PHYS_OFFSET_OFFSET)
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci#define __pa(x)		 ((unsigned long)(x) - PAGE_OFFSET + va_pa_offset)
808c2ecf20Sopenharmony_ci#define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET - va_pa_offset))
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci#define __pa_symbol(x)	__pa(RELOC_HIDE((unsigned long)(x), 0))
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#define MAP_NR(x)	PFN_DOWN((unsigned long)(x) - PAGE_OFFSET - \
858c2ecf20Sopenharmony_ci				 PHYS_OFFSET_OFFSET)
868c2ecf20Sopenharmony_ci#define virt_to_page(x)	(mem_map + MAP_NR(x))
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci#define pfn_to_kaddr(x)	__va(PFN_PHYS(x))
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#include <asm-generic/memory_model.h>
918c2ecf20Sopenharmony_ci#include <asm-generic/getorder.h>
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */
948c2ecf20Sopenharmony_ci#endif /* __ASM_CSKY_PAGE_H */
95