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