]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/bcm64/archbcm4.c
bcm64: do not use OTP_BOOTMODE_REG to determine OSC frequency (thanks richard miller)
[plan9front.git] / sys / src / 9 / bcm64 / archbcm4.c
1 /*
2  * bcm2711 (e.g.raspberry pi 4) 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 "sysreg.h"
13
14 typedef struct Mbox Mbox;
15 typedef struct Mboxes Mboxes;
16
17 #define POWERREGS       (VIRTIO+0x100000)
18
19 Soc soc = {
20         .dramsize       = 0xFC000000,
21         .busdram        = 0xC0000000,
22         .iosize         = 0x03000000,
23         .busio          = 0x7C000000,
24         .physio         = 0xFC000000,
25         .virtio         = VIRTIO2,
26         .armlocal       = 0xFF800000,
27         .pciwin         = 0x0600000000ULL,
28         .oscfreq        = 54000000,
29 };
30
31 enum {
32         Wdogfreq        = 65536,
33         Wdogtime        = 10,   /* seconds, ≤ 15 */
34 };
35
36 /*
37  * Power management / watchdog registers
38  */
39 enum {
40         Rstc            = 0x1c>>2,
41                 Password        = 0x5A<<24,
42                 CfgMask         = 0x03<<4,
43                 CfgReset        = 0x02<<4,
44         Rsts            = 0x20>>2,
45         Wdog            = 0x24>>2,
46 };
47
48 /*
49  * Arm local regs for smp
50  */
51 struct Mbox {
52         u32int  doorbell;
53         u32int  mbox1;
54         u32int  mbox2;
55         u32int  startcpu;
56 };
57 struct Mboxes {
58         Mbox    set[4];
59         Mbox    clr[4];
60 };
61
62 enum {
63         Mboxregs        = 0x80,
64 };
65
66 void
67 archreset(void)
68 {
69 }
70
71 void
72 archreboot(void)
73 {
74         u32int *r;
75
76         r = (u32int*)POWERREGS;
77         r[Wdog] = Password | 1;
78         r[Rstc] = Password | (r[Rstc] & ~CfgMask) | CfgReset;
79         coherence();
80         for(;;)
81                 ;
82 }
83
84 void
85 wdogfeed(void)
86 {
87         u32int *r;
88
89         r = (u32int*)POWERREGS;
90         r[Wdog] = Password | (Wdogtime * Wdogfreq);
91         r[Rstc] = Password | (r[Rstc] & ~CfgMask) | CfgReset;
92 }
93
94 void
95 wdogoff(void)
96 {
97         u32int *r;
98
99         r = (u32int*)POWERREGS;
100         r[Rstc] = Password | (r[Rstc] & ~CfgMask);
101 }
102
103
104 char *
105 cputype2name(char *buf, int size)
106 {
107         u32int r, part;
108         char *p;
109
110         r = sysrd(MIDR_EL1);
111         part = (r >> 4) & 0xFFF;
112         switch(part){
113         case 0xc07:
114                 p = seprint(buf, buf + size, "Cortex-A7");
115                 break;
116         case 0xd03:
117                 p = seprint(buf, buf + size, "Cortex-A53");
118                 break;
119         case 0xd08:
120                 p = seprint(buf, buf + size, "Cortex-A72");
121                 break;
122         default:
123                 p = seprint(buf, buf + size, "Unknown-%#x", part);
124                 break;
125         }
126         seprint(p, buf + size, " r%udp%ud", (r >> 20) & 0xF, r & 0xF);
127         return buf;
128 }
129
130 void
131 cpuidprint(void)
132 {
133         char name[64];
134
135         cputype2name(name, sizeof name);
136         iprint("cpu%d: %dMHz ARM %s\n", m->machno, m->cpumhz, name);
137 }
138
139 int
140 getncpus(void)
141 {
142         int n, max;
143         char *p;
144
145         n = 4;
146         if(n > MAXMACH)
147                 n = MAXMACH;
148         p = getconf("*ncpu");
149         if(p && (max = atoi(p)) > 0 && n > max)
150                 n = max;
151         return n;
152 }
153
154 void
155 mboxclear(uint cpu)
156 {
157         Mboxes *mb;
158
159         mb = (Mboxes*)(ARMLOCAL + Mboxregs);
160         mb->clr[cpu].mbox1 = 1;
161 }
162
163 void
164 wakecpu(uint cpu)
165 {
166         Mboxes *mb;
167
168         mb = (Mboxes*)(ARMLOCAL + Mboxregs);
169         mb->set[cpu].mbox1 = 1;
170 }
171
172 void
173 archbcm4link(void)
174 {
175         // addclock0link(wdogfeed, HZ);
176 }