]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/bcm/archbcm.c
bcm, bcm64: add dmaflush() function and make virtio size and virtual address configur...
[plan9front.git] / sys / src / 9 / bcm / archbcm.c
1 /*
2  * bcm2835 (e.g. original raspberry pi) architecture-specific stuff
3  */
4
5 #include "u.h"
6 #include "../port/lib.h"
7 #include "mem.h"
8 #include "dat.h"
9 #include "fns.h"
10 #include "../port/error.h"
11 #include "io.h"
12 #include "arm.h"
13
14 #define POWERREGS       (VIRTIO+0x100000)
15
16 Soc soc = {
17         .dramsize       = 512*MiB,
18         .busdram        = 0x40000000,
19         .iosize         = 16*MiB,
20         .virtio         = VIRTIO,
21         .physio         = 0x20000000,
22         .busio          = 0x7E000000,
23         .armlocal       = 0,
24         .l1ptedramattrs = Cached | Buffered,
25         .l2ptedramattrs = Cached | Buffered,
26 };
27
28 enum {
29         Wdogfreq        = 65536,
30         Wdogtime        = 10,   /* seconds, ≤ 15 */
31 };
32
33 /*
34  * Power management / watchdog registers
35  */
36 enum {
37         Rstc            = 0x1c>>2,
38                 Password        = 0x5A<<24,
39                 CfgMask         = 0x03<<4,
40                 CfgReset        = 0x02<<4,
41         Rsts            = 0x20>>2,
42         Wdog            = 0x24>>2,
43 };
44
45 void
46 archreset(void)
47 {
48         fpon();
49 }
50
51 void
52 archreboot(void)
53 {
54         u32int *r;
55
56         r = (u32int*)POWERREGS;
57         r[Wdog] = Password | 1;
58         r[Rstc] = Password | (r[Rstc] & ~CfgMask) | CfgReset;
59         coherence();
60         for(;;)
61                 ;
62 }
63
64 void
65 wdogfeed(void)
66 {
67         u32int *r;
68
69         r = (u32int*)POWERREGS;
70         r[Wdog] = Password | (Wdogtime * Wdogfreq);
71         r[Rstc] = Password | (r[Rstc] & ~CfgMask) | CfgReset;
72 }
73
74 void
75 wdogoff(void)
76 {
77         u32int *r;
78
79         r = (u32int*)POWERREGS;
80         r[Rstc] = Password | (r[Rstc] & ~CfgMask);
81 }
82         
83 char *
84 cputype2name(char *buf, int size)
85 {
86         seprint(buf, buf + size, "1176JZF-S");
87         return buf;
88 }
89
90 void
91 cpuidprint(void)
92 {
93         char name[64];
94
95         cputype2name(name, sizeof name);
96         delay(50);                              /* let uart catch up */
97         print("cpu%d: %dMHz ARM %s\n", m->machno, m->cpumhz, name);
98 }
99
100 int
101 getncpus(void)
102 {
103         return 1;
104 }
105
106 int
107 startcpus(uint)
108 {
109         return 1;
110 }
111
112 void
113 archbcmlink(void)
114 {
115         addclock0link(wdogfeed, HZ);
116 }
117
118 int
119 l2ap(int ap)
120 {
121         return (AP(3, (ap))|AP(2, (ap))|AP(1, (ap))|AP(0, (ap)));
122 }
123
124 int
125 cmpswap(long *addr, long old, long new)
126 {
127         return cas32(addr, old, new);
128 }
129