]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/kw/mem.h
Import sources from 2011-03-30 iso image
[plan9front.git] / sys / src / 9 / kw / mem.h
1 /*
2  * Memory and machine-specific definitions.  Used in C and assembler.
3  */
4 #define KiB             1024u                   /* Kibi 0x0000000000000400 */
5 #define MiB             1048576u                /* Mebi 0x0000000000100000 */
6 #define GiB             1073741824u             /* Gibi 000000000040000000 */
7
8 #define HOWMANY(x, y)   (((x)+((y)-1))/(y))
9 #define ROUNDUP(x, y)   (HOWMANY((x), (y))*(y)) /* ceiling */
10 #define ROUNDDN(x, y)   (((x)/(y))*(y))         /* floor */
11 #define MIN(a, b)       ((a) < (b)? (a): (b))
12 #define MAX(a, b)       ((a) > (b)? (a): (b))
13
14 /*
15  * Not sure where these macros should go.
16  * This probably isn't right but will do for now.
17  * The macro names are problematic too.
18  */
19 /*
20  * In B(o), 'o' is the bit offset in the register.
21  * For multi-bit fields use F(v, o, w) where 'v' is the value
22  * of the bit-field of width 'w' with LSb at bit offset 'o'.
23  */
24 #define B(o)            (1<<(o))
25 #define F(v, o, w)      (((v) & ((1<<(w))-1))<<(o))
26
27 #define FCLR(d, o, w)   ((d) & ~(((1<<(w))-1)<<(o)))
28 #define FEXT(d, o, w)   (((d)>>(o)) & ((1<<(w))-1))
29 #define FINS(d, o, w, v) (FCLR((d), (o), (w))|F((v), (o), (w)))
30 #define FSET(d, o, w)   ((d)|(((1<<(w))-1)<<(o)))
31
32 #define FMASK(o, w)     (((1<<(w))-1)<<(o))
33
34 /*
35  * Sizes
36  */
37 #define BY2PG           (4*KiB)                 /* bytes per page */
38 #define PGSHIFT         12                      /* log(BY2PG) */
39 #define PGROUND(s)      ROUNDUP(s, BY2PG)
40 #define ROUND(s, sz)    (((s)+(sz-1))&~(sz-1))
41
42 #define MAXMACH         1                       /* max # cpus system can run */
43 #define MACHSIZE        BY2PG
44
45 #define KSTKSIZE        (8*KiB)
46 #define STACKALIGN(sp)  ((sp) & ~3)             /* bug: assure with alloc */
47
48 /*
49  * Address spaces.
50  * KTZERO is used by kprof and dumpstack (if any).
51  *
52  * KZERO is mapped to physical 0.
53  * u-boot claims to take 0 - 8MB.
54  *
55  * vectors are at 0, plan9.ini is at KZERO+4K and is limited to 16K by
56  * devenv.  L2 PTEs for trap vectors & i/o regs are stored from KZERO+56K
57  * to L1-MACHSIZE (KZERO+60K).  cpu0's Mach struct is at L1 - MACHSIZE(4K)
58  * to L1 (KZERO+60K to KZERO+64K).  L1 PTEs are stored from L1 to L1+32K
59  * (KZERO+64K to KZERO+96K).  KTZERO may be anywhere after KZERO+96K.
60  */
61
62 #define KSEG0           0x60000000              /* kernel segment */
63 /* mask to check segment; good for 512MB dram */
64 #define KSEGM           0xE0000000
65 #define KZERO           KSEG0                   /* kernel address space */
66 #define CONFADDR        (KZERO+4*KiB)           /* unparsed plan9.ini */
67 #define L1              (KZERO+64*KiB)          /* tt ptes: 16KiB aligned */
68 #define KTZERO          (KZERO+0x800000)        /* kernel text start */
69
70 #define UZERO           0                       /* user segment */
71 #define UTZERO          (UZERO+BY2PG)           /* user text start */
72 #define USTKTOP         KZERO                   /* user segment end +1 */
73 #define USTKSIZE        (8*1024*1024)           /* user stack size */
74 #define TSTKTOP         (USTKTOP-USTKSIZE)      /* sysexec temporary stack */
75 #define TSTKSIZ         256
76
77 /* address at which to copy and execute rebootcode */
78 #define REBOOTADDR      KADDR(0x100)
79
80 /*
81  * Time.
82  * Does this need to be here? Used in assembler?
83  */
84 #define HZ              100                     /* clock frequency */
85 #define MS2HZ           (1000/HZ)               /* millisec per clock tick */
86 #define TK2SEC(t)       ((t)/HZ)                /* ticks to seconds */
87
88 /*
89  * More accurate time
90  */
91 #define CLOCKFREQ       (200*1000*1000)         /* TCLK on sheeva: 200MHz */
92 //#define MS2TMR(t)     ((ulong)(((uvlong)(t)*CLOCKFREQ)/1000))
93 //#define US2TMR(t)     ((ulong)(((uvlong)(t)*CLOCKFREQ)/1000000))
94
95 /*
96  * Legacy...
97  */
98 #define BLOCKALIGN      32                      /* only used in allocb.c */
99 #define KSTACK          KSTKSIZE
100
101 /*
102  * Sizes
103  */
104 #define BI2BY           8                       /* bits per byte */
105 #define BY2SE           4
106 #define BY2WD           4
107 #define BY2V            8                       /* only used in xalloc.c */
108
109 #define CACHELINESZ     32
110 #define PTEMAPMEM       (1024*1024)
111 #define PTEPERTAB       (PTEMAPMEM/BY2PG)
112 #define SEGMAPSIZE      1984
113 #define SSEGMAPSIZE     16
114 #define PPN(x)          ((x)&~(BY2PG-1))
115
116 /*
117  * With a little work these move to port.
118  */
119 #define PTEVALID        (1<<0)
120 #define PTERONLY        0
121 #define PTEWRITE        (1<<1)
122 #define PTEUNCACHED     (1<<2)
123 #define PTEKERNEL       (1<<3)
124
125 /*
126  * Physical machine information from here on.
127  */
128 #define PHYSDRAM        0
129
130 /* from 0x80000000 up is uncached by L2 (see archkw.c) */
131 #define PHYSCESASRAM    0xc8010000
132 // #define PHYSSPIFLASH 0xe8000000              /* ignore spi flash */
133 /* this address is configured by u-boot, and is 0xd0000000 at reset */
134 #define PHYSIO          0xf1000000              /* internal registers */
135 #define PHYSCONS        (PHYSIO + 0x12000)      /* uart */
136 #define PHYSNAND1       0xf9000000              /* sheeva/openrd (remapped) */
137 #define PHYSNAND2       0xd8000000              /* guru */
138 #define PHYSBOOTROM     0xffff0000              /* boot rom */
139
140 #define FLASHSIZE       (512*MiB)               /* but not addressed linearly */
141
142 #define VIRTIO          PHYSIO