]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/bcm/mem.h
add raspberry pi kernel (from sources)
[plan9front.git] / sys / src / 9 / bcm / 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  * Sizes
16  */
17 #define BY2PG           (4*KiB)                 /* bytes per page */
18 #define PGSHIFT         12                      /* log(BY2PG) */
19 #define PGROUND(s)      ROUNDUP(s, BY2PG)
20 #define ROUND(s, sz)    (((s)+(sz-1))&~(sz-1))
21
22 #define MAXMACH         1                       /* max # cpus system can run */
23 #define MACHSIZE        BY2PG
24
25 #define KSTKSIZE        (8*KiB)
26 #define STACKALIGN(sp)  ((sp) & ~3)             /* bug: assure with alloc */
27
28 /*
29  * Address spaces.
30  * KTZERO is used by kprof and dumpstack (if any).
31  *
32  * KZERO is mapped to physical 0 (start of ram).
33  *
34  * vectors are at 0, plan9.ini is at KZERO+256 and is limited to 16K by
35  * devenv.
36  */
37
38 #define KSEG0           0x80000000              /* kernel segment */
39 /* mask to check segment; good for 512MB dram */
40 #define KSEGM           0xE0000000
41 #define KZERO           KSEG0                   /* kernel address space */
42 #define CONFADDR        (KZERO+0x100)           /* unparsed plan9.ini */
43 #define MACHADDR        (KZERO+0x2000)          /* Mach structure */
44 #define L2              (KZERO+0x3000)          /* L2 ptes for vectors etc */
45 #define VCBUFFER        (KZERO+0x3400)          /* videocore mailbox buffer */
46 #define FIQSTKTOP       (KZERO+0x4000)          /* FIQ stack */
47 #define L1              (KZERO+0x4000)          /* tt ptes: 16KiB aligned */
48 #define KTZERO          (KZERO+0x8000)          /* kernel text start */
49 #define VIRTIO          0x7E000000              /* i/o registers */
50 #define FRAMEBUFFER     0xA0000000              /* video framebuffer */
51
52 #define UZERO           0                       /* user segment */
53 #define UTZERO          (UZERO+BY2PG)           /* user text start */
54 #define USTKTOP         0x20000000              /* user segment end +1 */
55 #define USTKSIZE        (8*1024*1024)           /* user stack size */
56 #define TSTKTOP         (USTKTOP-USTKSIZE)      /* sysexec temporary stack */
57 #define TSTKSIZ         256
58
59 /* address at which to copy and execute rebootcode */
60 #define REBOOTADDR      (KZERO+0x3400)
61
62 /*
63  * Legacy...
64  */
65 #define BLOCKALIGN      32                      /* only used in allocb.c */
66 #define KSTACK          KSTKSIZE
67
68 /*
69  * Sizes
70  */
71 #define BI2BY           8                       /* bits per byte */
72 #define BY2SE           4
73 #define BY2WD           4
74 #define BY2V            8                       /* only used in xalloc.c */
75
76 #define CACHELINESZ     32
77 #define PTEMAPMEM       (1024*1024)
78 #define PTEPERTAB       (PTEMAPMEM/BY2PG)
79 #define SEGMAPSIZE      1984
80 #define SSEGMAPSIZE     16
81 #define PPN(x)          ((x)&~(BY2PG-1))
82
83 /*
84  * With a little work these move to port.
85  */
86 #define PTEVALID        (1<<0)
87 #define PTERONLY        0
88 #define PTEWRITE        (1<<1)
89 #define PTEUNCACHED     (1<<2)
90 #define PTEKERNEL       (1<<3)
91
92 /*
93  * Physical machine information from here on.
94  *      PHYS addresses as seen from the arm cpu.
95  *      BUS  addresses as seen from the videocore gpu.
96  */
97 #define PHYSDRAM        0
98 #define BUSDRAM         0x40000000
99 #define DRAMSIZE        (512*MiB)
100 #define PHYSIO          0x20000000
101 #define BUSIO           0x7E000000
102 #define IOSIZE          (16*MiB)