summaryrefslogtreecommitdiffstats
path: root/include/asm-sparc/page.h
blob: a048ac76c085cabcfd9465b3a0ae6c74cfb29591 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* page.h:  Various defines and such for MMU operations on the Sparc for
            the Linux kernel.

   Copyright (C) 1994 David S. Miller (davem@caip.rutgers.edu)
*/

#ifndef _SPARC_PAGE_H
#define _SPARC_PAGE_H

#include <asm/asi.h>        /* for get/set segmap/pte routines */
#include <asm/contregs.h>   /* for switch_to_context */

#define PAGE_SHIFT   12             /* This is the virtual page... */

#ifndef __ASSEMBLY__
#define PAGE_SIZE    (1UL << PAGE_SHIFT)

/* to mask away the intra-page address bits */
#define PAGE_MASK         (~(PAGE_SIZE-1))

#ifdef __KERNEL__

/* The following structure is used to hold the physical
 * memory configuration of the machine.  This is filled
 * in probe_memory() and is later used by mem_init() to
 * set up mem_map[].  We statically allocate 14 of these
 * structs, this is arbitrary.  The entry after the last
 * valid one has num_bytes==0.
 */

struct sparc_phys_banks {
  unsigned long base_addr;
  unsigned long num_bytes;
};

#define CONFIG_STRICT_MM_TYPECHECKS

#ifdef CONFIG_STRICT_MM_TYPECHECKS
/*
 * These are used to make use of C type-checking..
 */
typedef struct { unsigned long pte; } pte_t;
typedef struct { unsigned long pmd; } pmd_t;
typedef struct { unsigned long pgd; } pgd_t;
typedef struct { unsigned long pgprot; } pgprot_t;

#define pte_val(x)	((x).pte)
#define pmd_val(x)      ((x).pmd)
#define pgd_val(x)	((x).pgd)
#define pgprot_val(x)	((x).pgprot)

#define __pte(x)	((pte_t) { (x) } )
#define __pmd(x)        ((pmd_t) { (x) } )
#define __pgd(x)	((pgd_t) { (x) } )
#define __pgprot(x)	((pgprot_t) { (x) } )

#else
/*
 * .. while these make it easier on the compiler
 */
typedef unsigned long pte_t;
typedef unsigned long pmd_t;
typedef unsigned long pgd_t;
typedef unsigned long pgprot_t;

#define pte_val(x)	(x)
#define pmd_val(x)      (x)
#define pgd_val(x)	(x)
#define pgprot_val(x)	(x)

#define __pte(x)	(x)
#define __pmd(x)        (x)
#define __pgd(x)	(x)
#define __pgprot(x)	(x)

#endif

/* The current va context is global and known, so all that is needed to
 * do an invalidate is flush the VAC.
 */

#define invalidate() flush_vac_context()  /* how conveeeiiiiinnnient :> */

#define copy_page(from,to) memcpy((void *) to, (void *) from, PAGE_SIZE)

/* to align the pointer to the (next) page boundary */
#define PAGE_ALIGN(addr)  (((addr)+PAGE_SIZE-1)&PAGE_MASK)

#define PAGE_OFFSET    0
#define MAP_NR(addr) (((unsigned long)(addr)) >> PAGE_SHIFT)
#define MAP_PAGE_RESERVED (1<<15)


#endif /* !(__ASSEMBLY__) */

/* The rest is kind of funky because on the sparc, the offsets into the mmu 
 * entries are encoded in magic alternate address space tables. I will 
 * probably find some nifty inline assembly routines to do the equivalent. 
 * Much thought must go into this code.   (davem@caip.rutgers.edu)
 */

/* Bitfields within a Sparc sun4c PTE (page table entry). */

#define PTE_V     0x80000000   /* valid bit */
#define PTE_ACC   0x60000000   /* access bits */
#define PTE_W     0x40000000   /* writable bit */
#define PTE_P     0x20000000   /* privileged page */
#define PTE_NC    0x10000000   /* page is non-cacheable */
#define PTE_TYP   0x0c000000   /* page type field */
#define PTE_RMEM  0x00000000   /* type == on board real memory */
#define PTE_IO    0x04000000   /* type == i/o area */
#define PTE_VME16 0x08000000   /* type == 16-bit VME area */
#define PTE_VME32 0x0c000000   /* type == 32-bit VME area */
#define PTE_R     0x02000000   /* page has been referenced */
#define PTE_M     0x01000000   /* page has been modified */
#define PTE_RESV  0x00f80000   /* reserved bits */
#define PTE_PHYPG 0x0007ffff   /* phys pg number, sun4c only uses 16bits */

extern __inline__ unsigned long get_segmap(unsigned long addr)
{
  register unsigned long entry;

  __asm__ __volatile__("lduba [%1] 0x3, %0" : 
		       "=r" (entry) :
		       "r" (addr));

  return (entry&0x7f);
}

extern __inline__ void put_segmap(unsigned long addr, unsigned long entry)
{

  __asm__ __volatile__("stba %1, [%0] 0x3" : : "r" (addr), "r" (entry&0x7f));

  return;
}

extern __inline__ unsigned long get_pte(unsigned long addr)
{
  register unsigned long entry;

  __asm__ __volatile__("lda [%1] 0x4, %0" : 
		       "=r" (entry) :
		       "r" (addr));
  return entry;
}

extern __inline__ void put_pte(unsigned long addr, unsigned long entry)
{
  __asm__ __volatile__("sta %1, [%0] 0x4" : :
		       "r" (addr), 
		       "r" (entry));

  return;
}

extern __inline__ void switch_to_context(int context)
{
  __asm__ __volatile__("stba %0, [%1] 0x2" : :
		       "r" (context),
		       "r" (0x30000000));		       

  return;
}

extern __inline__ int get_context(void)
{
  register int ctx;

  __asm__ __volatile__("lduba [%1] 0x2, %0" :
		       "=r" (ctx) :
		       "r" (0x30000000));

  return ctx;
}

typedef unsigned short mem_map_t;

#endif /* __KERNEL__ */

#endif /* _SPARC_PAGE_H */