18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci// Copyright (C) 2005-2017 Andes Technology Corporation
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#ifndef __ASM_NDS32_MEMORY_H
58c2ecf20Sopenharmony_ci#define __ASM_NDS32_MEMORY_H
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/compiler.h>
88c2ecf20Sopenharmony_ci#include <linux/sizes.h>
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
118c2ecf20Sopenharmony_ci#include <asm/page.h>
128c2ecf20Sopenharmony_ci#endif
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#ifndef PHYS_OFFSET
158c2ecf20Sopenharmony_ci#define PHYS_OFFSET     (0x0)
168c2ecf20Sopenharmony_ci#endif
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/*
198c2ecf20Sopenharmony_ci * TASK_SIZE - the maximum size of a user space task.
208c2ecf20Sopenharmony_ci * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_ci#define TASK_SIZE		((CONFIG_PAGE_OFFSET) - (SZ_32M))
238c2ecf20Sopenharmony_ci#define TASK_UNMAPPED_BASE	ALIGN(TASK_SIZE / 3, SZ_32M)
248c2ecf20Sopenharmony_ci#define PAGE_OFFSET		(CONFIG_PAGE_OFFSET)
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/*
278c2ecf20Sopenharmony_ci * Physical vs virtual RAM address space conversion.  These are
288c2ecf20Sopenharmony_ci * private definitions which should NOT be used outside memory.h
298c2ecf20Sopenharmony_ci * files.  Use virt_to_phys/phys_to_virt/__pa/__va instead.
308c2ecf20Sopenharmony_ci */
318c2ecf20Sopenharmony_ci#ifndef __virt_to_phys
328c2ecf20Sopenharmony_ci#define __virt_to_phys(x)	((x) - PAGE_OFFSET + PHYS_OFFSET)
338c2ecf20Sopenharmony_ci#define __phys_to_virt(x)	((x) - PHYS_OFFSET + PAGE_OFFSET)
348c2ecf20Sopenharmony_ci#endif
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/*
378c2ecf20Sopenharmony_ci * The module space lives between the addresses given by TASK_SIZE
388c2ecf20Sopenharmony_ci * and PAGE_OFFSET - it must be within 32MB of the kernel text.
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_ci#define MODULES_END	(PAGE_OFFSET)
418c2ecf20Sopenharmony_ci#define MODULES_VADDR	(MODULES_END - SZ_32M)
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#if TASK_SIZE > MODULES_VADDR
448c2ecf20Sopenharmony_ci#error Top of user space clashes with start of module space
458c2ecf20Sopenharmony_ci#endif
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/*
508c2ecf20Sopenharmony_ci * PFNs are used to describe any physical page; this means
518c2ecf20Sopenharmony_ci * PFN 0 == physical address 0.
528c2ecf20Sopenharmony_ci *
538c2ecf20Sopenharmony_ci * This is the PFN of the first RAM page in the kernel
548c2ecf20Sopenharmony_ci * direct-mapped view.  We assume this is the first page
558c2ecf20Sopenharmony_ci * of RAM in the mem_map as well.
568c2ecf20Sopenharmony_ci */
578c2ecf20Sopenharmony_ci#define PHYS_PFN_OFFSET	(PHYS_OFFSET >> PAGE_SHIFT)
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/*
608c2ecf20Sopenharmony_ci * Drivers should NOT use these either.
618c2ecf20Sopenharmony_ci */
628c2ecf20Sopenharmony_ci#define __pa(x)			__virt_to_phys((unsigned long)(x))
638c2ecf20Sopenharmony_ci#define __va(x)			((void *)__phys_to_virt((unsigned long)(x)))
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/*
668c2ecf20Sopenharmony_ci * Conversion between a struct page and a physical address.
678c2ecf20Sopenharmony_ci *
688c2ecf20Sopenharmony_ci * Note: when converting an unknown physical address to a
698c2ecf20Sopenharmony_ci * struct page, the resulting pointer must be validated
708c2ecf20Sopenharmony_ci * using VALID_PAGE().  It must return an invalid struct page
718c2ecf20Sopenharmony_ci * for any physical address not corresponding to a system
728c2ecf20Sopenharmony_ci * RAM address.
738c2ecf20Sopenharmony_ci *
748c2ecf20Sopenharmony_ci *  pfn_valid(pfn)	indicates whether a PFN number is valid
758c2ecf20Sopenharmony_ci *
768c2ecf20Sopenharmony_ci *  virt_to_page(k)	convert a _valid_ virtual address to struct page *
778c2ecf20Sopenharmony_ci *  virt_addr_valid(k)	indicates whether a virtual address is valid
788c2ecf20Sopenharmony_ci */
798c2ecf20Sopenharmony_ci#ifndef CONFIG_DISCONTIGMEM
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#define ARCH_PFN_OFFSET		PHYS_PFN_OFFSET
828c2ecf20Sopenharmony_ci#define pfn_valid(pfn)		((pfn) >= PHYS_PFN_OFFSET && (pfn) < (PHYS_PFN_OFFSET + max_mapnr))
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#define virt_to_page(kaddr)	(pfn_to_page(__pa(kaddr) >> PAGE_SHIFT))
858c2ecf20Sopenharmony_ci#define virt_addr_valid(kaddr)	((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#else /* CONFIG_DISCONTIGMEM */
888c2ecf20Sopenharmony_ci#error CONFIG_DISCONTIGMEM is not supported yet.
898c2ecf20Sopenharmony_ci#endif /* !CONFIG_DISCONTIGMEM */
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#define page_to_phys(page)	(page_to_pfn(page) << PAGE_SHIFT)
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#endif
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#include <asm-generic/memory_model.h>
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#endif
98