]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/machine_routines_asm.s
e0d376d44bf91a60521839a16866930bae0be6de
[apple/xnu.git] / osfmk / ppc / machine_routines_asm.s
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 #include <ppc/asm.h>
23 #include <ppc/proc_reg.h>
24 #include <cpus.h>
25 #include <assym.s>
26 #include <debug.h>
27 #include <mach/ppc/vm_param.h>
28 #include <ppc/exception.h>
29
30
31 /*
32 * ml_set_physical() -- turn off DR and (if 64-bit) turn SF on
33 * it is assumed that pf64Bit is already in cr6
34 * ml_set_physical_get_ffs() -- turn DR off, SF on, and get feature flags
35 * ml_set_physical_disabled() -- turn DR and EE off, SF on, get feature flags
36 * ml_set_translation_off() -- turn DR, IR, and EE off, SF on, get feature flags
37 *
38 * Callable only from assembler, these return:
39 * r2 -- new MSR
40 * r11 -- old MSR
41 * r10 -- feature flags (pf64Bit etc, ie SPRG 2)
42 * cr6 -- feature flags 24-27, ie pf64Bit, pf128Byte, and pf32Byte
43 *
44 * Uses r0 and r2. ml_set_translation_off also uses r3 and cr5.
45 */
46
47 .align 4
48 .globl EXT(ml_set_translation_off)
49 LEXT(ml_set_translation_off)
50 mfsprg r10,2 // get feature flags
51 li r0,0 ; Clear this
52 mtcrf 0x02,r10 // move pf64Bit etc to cr6
53 ori r0,r0,lo16(MASK(MSR_EE)+MASK(MSR_FP)+MASK(MSR_IR)+MASK(MSR_DR)) // turn off all 4
54 mfmsr r11 // get MSR
55 oris r0,r0,hi16(MASK(MSR_VEC)) // Turn off vector too
56 mtcrf 0x04,r10 // move pfNoMSRir etc to cr5
57 andc r2,r11,r0 // turn off EE, IR, and DR
58 bt++ pf64Bitb,ml_set_physical_64 // skip if 64-bit (only they take the hint)
59 bf pfNoMSRirb,ml_set_physical_32 // skip if we can load MSR directly
60 li r0,loadMSR // Get the MSR setter SC
61 mr r3,r2 // copy new MSR to r2
62 sc // Set it
63 blr
64
65 .align 4
66 .globl EXT(ml_set_physical_disabled)
67
68 LEXT(ml_set_physical_disabled)
69 li r0,0 ; Clear
70 mfsprg r10,2 // get feature flags
71 ori r0,r0,lo16(MASK(MSR_EE)) // turn EE and fp off
72 mtcrf 0x02,r10 // move pf64Bit etc to cr6
73 b ml_set_physical_join
74
75 .align 5
76 .globl EXT(ml_set_physical_get_ffs)
77
78 LEXT(ml_set_physical_get_ffs)
79 mfsprg r10,2 // get feature flags
80 mtcrf 0x02,r10 // move pf64Bit etc to cr6
81
82 .globl EXT(ml_set_physical)
83 LEXT(ml_set_physical)
84
85 li r0,0 // do not turn off interrupts
86
87 ml_set_physical_join:
88 oris r0,r0,hi16(MASK(MSR_VEC)) // Always gonna turn of vectors
89 mfmsr r11 // get MSR
90 ori r0,r0,lo16(MASK(MSR_DR)+MASK(MSR_FP)) // always turn off DR and FP bit
91 andc r2,r11,r0 // turn off DR and maybe EE
92 bt++ pf64Bitb,ml_set_physical_64 // skip if 64-bit (only they take the hint)
93 ml_set_physical_32:
94 mtmsr r2 // turn off translation
95 isync
96 blr
97
98 ml_set_physical_64:
99 li r0,1 // get a 1 to slam into SF
100 rldimi r2,r0,63,MSR_SF_BIT // set SF bit (bit 0)
101 mtmsrd r2 // set 64-bit mode, turn off data relocation
102 isync // synchronize
103 blr
104
105
106 /*
107 * ml_restore(old_MSR)
108 *
109 * Callable only from assembler, restores the MSR in r11 saved by ml_set_physical.
110 * We assume cr6 and r11 are as set by ml_set_physical, ie:
111 * cr6 - pf64Bit flag (feature flags 24-27)
112 * r11 - old MSR
113 */
114
115 .align 5
116 .globl EXT(ml_restore)
117
118 LEXT(ml_restore)
119 bt++ pf64Bitb,ml_restore_64 // handle 64-bit cpus (only they take the hint)
120 mtmsr r11 // restore a 32-bit MSR
121 isync
122 blr
123
124 ml_restore_64:
125 mtmsrd r11 // restore a 64-bit MSR
126 isync
127 blr
128
129
130 /* PCI config cycle probing
131 *
132 * boolean_t ml_probe_read(vm_offset_t paddr, unsigned int *val)
133 *
134 * Read the memory location at physical address paddr.
135 * This is a part of a device probe, so there is a good chance we will
136 * have a machine check here. So we have to be able to handle that.
137 * We assume that machine checks are enabled both in MSR and HIDs
138 */
139
140 ; Force a line boundry here
141 .align 5
142 .globl EXT(ml_probe_read)
143
144 LEXT(ml_probe_read)
145
146 mfsprg r9,2 ; Get feature flags
147
148 rlwinm. r0,r9,0,pf64Bitb,pf64Bitb ; Are we on a 64-bit machine?
149 rlwinm r3,r3,0,0,31 ; Clean up for 64-bit machines
150 bne++ mpr64bit ; Go do this the 64-bit way...
151
152 mpr32bit: lis r8,hi16(MASK(MSR_VEC)) ; Get the vector flag
153 mfmsr r0 ; Save the current MSR
154 ori r8,r8,lo16(MASK(MSR_FP)) ; Add the FP flag
155
156 neg r10,r3 ; Number of bytes to end of page
157 andc r0,r0,r8 ; Clear VEC and FP
158 rlwinm. r10,r10,0,20,31 ; Clear excess junk and test for page bndry
159 ori r8,r8,lo16(MASK(MSR_EE)|MASK(MSR_IR)|MASK(MSR_DR)) ; Drop EE, IR, and DR
160 mr r12,r3 ; Save the load address
161 andc r2,r0,r8 ; Clear VEC, FP, and EE
162 mtcrf 0x04,r9 ; Set the features
163 cmplwi cr1,r10,4 ; At least 4 bytes left in page?
164 beq- mprdoit ; We are right on the boundary...
165 li r3,0
166 bltlr- cr1 ; No, just return failure...
167
168 mprdoit:
169
170 bt pfNoMSRirb,mprNoMSR ; No MSR...
171
172 mtmsr r2 ; Translation and all off
173 isync ; Toss prefetch
174 b mprNoMSRx
175
176 mprNoMSR:
177 mr r5,r0
178 li r0,loadMSR ; Get the MSR setter SC
179 mr r3,r2 ; Get new MSR
180 sc ; Set it
181 mr r0,r5
182 li r3,0
183 mprNoMSRx:
184
185 mfspr r6, hid0 ; Get a copy of hid0
186
187 rlwinm. r5, r9, 0, pfNoMuMMCKb, pfNoMuMMCKb ; Check for NoMuMMCK
188 bne mprNoMuM
189
190 rlwinm r5, r6, 0, ice+1, ice-1 ; Turn off L1 I-Cache
191 mtspr hid0, r5
192 isync ; Wait for I-Cache off
193 rlwinm r5, r6, 0, mum+1, mum-1 ; Turn off MuM w/ I-Cache on
194 mtspr hid0, r5
195 mprNoMuM:
196
197 ;
198 ; We need to insure that there is no more than 1 BAT register that
199 ; can get a hit. There could be repercussions beyond the ken
200 ; of mortal man. It is best not to tempt fate.
201 ;
202
203 ; Note: we will reload these from the shadow BATs later
204
205 li r10,0 ; Clear a register
206
207 sync ; Make sure all is well
208
209 mtdbatu 1,r10 ; Invalidate DBAT 1
210 mtdbatu 2,r10 ; Invalidate DBAT 2
211 mtdbatu 3,r10 ; Invalidate DBAT 3
212
213 rlwinm r10,r12,0,0,14 ; Round down to a 128k boundary
214 ori r11,r10,0x32 ; Set uncached, coherent, R/W
215 ori r10,r10,2 ; Make the upper half (128k, valid supervisor)
216 mtdbatl 0,r11 ; Set lower BAT first
217 mtdbatu 0,r10 ; Now the upper
218 sync ; Just make sure
219
220 dcbf 0,r12 ; Make sure we kill the cache to avoid paradoxes
221 sync
222
223 ori r11,r2,lo16(MASK(MSR_DR)) ; Turn on data translation
224 mtmsr r11 ; Do it for real
225 isync ; Make sure of it
226
227 eieio ; Make sure of all previous accesses
228 sync ; Make sure it is all caught up
229
230 lwz r11,0(r12) ; Get it and maybe machine check here
231
232 eieio ; Make sure of ordering again
233 sync ; Get caught up yet again
234 isync ; Do not go further till we are here
235
236 mtmsr r2 ; Turn translation back off
237 isync
238
239 lis r10,hi16(EXT(shadow_BAT)+shdDBAT) ; Get shadow address
240 ori r10,r10,lo16(EXT(shadow_BAT)+shdDBAT) ; Get shadow address
241
242 lwz r5,0(r10) ; Pick up DBAT 0 high
243 lwz r6,4(r10) ; Pick up DBAT 0 low
244 lwz r7,8(r10) ; Pick up DBAT 1 high
245 lwz r8,16(r10) ; Pick up DBAT 2 high
246 lwz r9,24(r10) ; Pick up DBAT 3 high
247
248 mtdbatu 0,r5 ; Restore DBAT 0 high
249 mtdbatl 0,r6 ; Restore DBAT 0 low
250 mtdbatu 1,r7 ; Restore DBAT 1 high
251 mtdbatu 2,r8 ; Restore DBAT 2 high
252 mtdbatu 3,r9 ; Restore DBAT 3 high
253 sync
254
255 li r3,1 ; We made it
256
257 mtmsr r0 ; Restore translation and exceptions
258 isync ; Toss speculations
259
260 stw r11,0(r4) ; Save the loaded value
261 blr ; Return...
262
263 ; Force a line boundry here. This means we will be able to check addresses better
264 .align 5
265 .globl EXT(ml_probe_read_mck)
266 LEXT(ml_probe_read_mck)
267
268
269 /* PCI config cycle probing - 64-bit
270 *
271 * boolean_t ml_probe_read_64(addr64_t paddr, unsigned int *val)
272 *
273 * Read the memory location at physical address paddr.
274 * This is a part of a device probe, so there is a good chance we will
275 * have a machine check here. So we have to be able to handle that.
276 * We assume that machine checks are enabled both in MSR and HIDs
277 */
278
279 ; Force a line boundry here
280 .align 6
281 .globl EXT(ml_probe_read_64)
282
283 LEXT(ml_probe_read_64)
284
285 mfsprg r9,2 ; Get feature flags
286 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
287 rlwinm. r0,r9,0,pf64Bitb,pf64Bitb ; Are we on a 64-bit machine?
288 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
289
290 mr r4,r5 ; Move result to common register
291 beq-- mpr32bit ; Go do this the 32-bit way...
292
293 mpr64bit: andi. r0,r3,3 ; Check if we are on a word boundary
294 li r0,0 ; Clear the EE bit (and everything else for that matter)
295 bne-- mprFail ; Boundary not good...
296 mfmsr r11 ; Get the MSR
297 mtmsrd r0,1 ; Set the EE bit only (do not care about RI)
298 rlwinm r11,r11,0,MSR_EE_BIT,MSR_EE_BIT ; Isolate just the EE bit
299 mfmsr r10 ; Refresh our view of the MSR (VMX/FP may have changed)
300 or r12,r10,r11 ; Turn on EE if on before we turned it off
301 ori r0,r0,lo16(MASK(MSR_IR)|MASK(MSR_DR)) ; Get the IR and DR bits
302 li r2,1 ; Get a 1
303 sldi r2,r2,63 ; Get the 64-bit bit
304 andc r10,r10,r0 ; Clear IR and DR
305 or r10,r10,r2 ; Set 64-bit
306
307 li r0,1 ; Get a 1
308 mtmsrd r10 ; Translation and EE off, 64-bit on
309 isync
310
311 sldi r0,r0,32+8 ; Get the right bit to inhibit caching
312
313 mfspr r8,hid4 ; Get HID4
314 or r2,r8,r0 ; Set bit to make real accesses cache-inhibited
315 sync ; Sync up
316 mtspr hid4,r2 ; Make real accesses cache-inhibited
317 isync ; Toss prefetches
318
319 lis r7,0xE000 ; Get the unlikeliest ESID possible
320 srdi r7,r7,1 ; Make 0x7FFFFFFFF0000000
321 slbie r7 ; Make sure the ERAT is cleared
322
323 sync
324 isync
325
326 eieio ; Make sure of all previous accesses
327
328 lwz r11,0(r3) ; Get it and maybe machine check here
329
330 eieio ; Make sure of ordering again
331 sync ; Get caught up yet again
332 isync ; Do not go further till we are here
333
334 sync ; Sync up
335 mtspr hid4,r8 ; Make real accesses not cache-inhibited
336 isync ; Toss prefetches
337
338 lis r7,0xE000 ; Get the unlikeliest ESID possible
339 srdi r7,r7,1 ; Make 0x7FFFFFFFF0000000
340 slbie r7 ; Make sure the ERAT is cleared
341
342 mtmsrd r12 ; Restore entry MSR
343 isync
344
345 stw r11,0(r4) ; Pass back the result
346 li r3,1 ; Indicate success
347 blr ; Leave...
348
349 mprFail: li r3,0 ; Set failure
350 blr ; Leave...
351
352 ; Force a line boundry here. This means we will be able to check addresses better
353 .align 6
354 .globl EXT(ml_probe_read_mck_64)
355 LEXT(ml_probe_read_mck_64)
356
357
358 /* Read physical address byte
359 *
360 * unsigned int ml_phys_read_byte(vm_offset_t paddr)
361 * unsigned int ml_phys_read_byte_64(addr64_t paddr)
362 *
363 * Read the byte at physical address paddr. Memory should not be cache inhibited.
364 */
365
366 ; Force a line boundry here
367
368 .align 5
369 .globl EXT(ml_phys_read_byte_64)
370
371 LEXT(ml_phys_read_byte_64)
372
373 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
374 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
375 b ml_phys_read_byte_join
376
377 .globl EXT(ml_phys_read_byte)
378
379 LEXT(ml_phys_read_byte)
380 rlwinm r3,r3,0,0,31 ; truncate address to 32-bits
381 ml_phys_read_byte_join: ; r3 = address to read (reg64_t)
382 mflr r11 ; Save the return
383 bl rdwrpre ; Get set up, translation/interrupts off, 64-bit on, etc.
384
385 lbz r3,0(r3) ; Get the byte
386 b rdwrpost ; Clean up and leave...
387
388
389 /* Read physical address half word
390 *
391 * unsigned int ml_phys_read_half(vm_offset_t paddr)
392 * unsigned int ml_phys_read_half_64(addr64_t paddr)
393 *
394 * Read the half word at physical address paddr. Memory should not be cache inhibited.
395 */
396
397 ; Force a line boundry here
398
399 .align 5
400 .globl EXT(ml_phys_read_half_64)
401
402 LEXT(ml_phys_read_half_64)
403
404 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
405 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
406 b ml_phys_read_half_join
407
408 .globl EXT(ml_phys_read_half)
409
410 LEXT(ml_phys_read_half)
411 rlwinm r3,r3,0,0,31 ; truncate address to 32-bits
412 ml_phys_read_half_join: ; r3 = address to read (reg64_t)
413 mflr r11 ; Save the return
414 bl rdwrpre ; Get set up, translation/interrupts off, 64-bit on, etc.
415
416 lhz r3,0(r3) ; Get the half word
417 b rdwrpost ; Clean up and leave...
418
419
420 /* Read physical address word
421 *
422 * unsigned int ml_phys_read(vm_offset_t paddr)
423 * unsigned int ml_phys_read_64(addr64_t paddr)
424 * unsigned int ml_phys_read_word(vm_offset_t paddr)
425 * unsigned int ml_phys_read_word_64(addr64_t paddr)
426 *
427 * Read the word at physical address paddr. Memory should not be cache inhibited.
428 */
429
430 ; Force a line boundry here
431
432 .align 5
433 .globl EXT(ml_phys_read_64)
434 .globl EXT(ml_phys_read_word_64)
435
436 LEXT(ml_phys_read_64)
437 LEXT(ml_phys_read_word_64)
438
439 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
440 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
441 b ml_phys_read_word_join
442
443 .globl EXT(ml_phys_read)
444 .globl EXT(ml_phys_read_word)
445
446 LEXT(ml_phys_read)
447 LEXT(ml_phys_read_word)
448 rlwinm r3,r3,0,0,31 ; truncate address to 32-bits
449 ml_phys_read_word_join: ; r3 = address to read (reg64_t)
450 mflr r11 ; Save the return
451 bl rdwrpre ; Get set up, translation/interrupts off, 64-bit on, etc.
452
453 lwz r3,0(r3) ; Get the word
454 b rdwrpost ; Clean up and leave...
455
456
457 /* Read physical address double word
458 *
459 * unsigned long long ml_phys_read_double(vm_offset_t paddr)
460 * unsigned long long ml_phys_read_double_64(addr64_t paddr)
461 *
462 * Read the double word at physical address paddr. Memory should not be cache inhibited.
463 */
464
465 ; Force a line boundry here
466
467 .align 5
468 .globl EXT(ml_phys_read_double_64)
469
470 LEXT(ml_phys_read_double_64)
471
472 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
473 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
474 b ml_phys_read_double_join
475
476 .globl EXT(ml_phys_read_double)
477
478 LEXT(ml_phys_read_double)
479 rlwinm r3,r3,0,0,31 ; truncate address to 32-bits
480 ml_phys_read_double_join: ; r3 = address to read (reg64_t)
481 mflr r11 ; Save the return
482 bl rdwrpre ; Get set up, translation/interrupts off, 64-bit on, etc.
483
484 lwz r4,4(r3) ; Get the low word
485 lwz r3,0(r3) ; Get the high word
486 b rdwrpost ; Clean up and leave...
487
488
489 /* Write physical address byte
490 *
491 * void ml_phys_write_byte(vm_offset_t paddr, unsigned int data)
492 * void ml_phys_write_byte_64(addr64_t paddr, unsigned int data)
493 *
494 * Write the byte at physical address paddr. Memory should not be cache inhibited.
495 */
496
497 .align 5
498 .globl EXT(ml_phys_write_byte_64)
499
500 LEXT(ml_phys_write_byte_64)
501
502 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
503 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
504 mr r4,r5 ; Copy over the data
505 b ml_phys_write_byte_join
506
507 .globl EXT(ml_phys_write_byte)
508
509 LEXT(ml_phys_write_byte)
510 rlwinm r3,r3,0,0,31 ; truncate address to 32-bits
511 ml_phys_write_byte_join: ; r3 = address to write (reg64_t), r4 = data
512 mflr r11 ; Save the return
513 bl rdwrpre ; Get set up, translation/interrupts off, 64-bit on, etc.
514
515 stb r4,0(r3) ; Set the byte
516 b rdwrpost ; Clean up and leave...
517
518
519 /* Write physical address half word
520 *
521 * void ml_phys_write_half(vm_offset_t paddr, unsigned int data)
522 * void ml_phys_write_half_64(addr64_t paddr, unsigned int data)
523 *
524 * Write the half word at physical address paddr. Memory should not be cache inhibited.
525 */
526
527 .align 5
528 .globl EXT(ml_phys_write_half_64)
529
530 LEXT(ml_phys_write_half_64)
531
532 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
533 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
534 mr r4,r5 ; Copy over the data
535 b ml_phys_write_half_join
536
537 .globl EXT(ml_phys_write_half)
538
539 LEXT(ml_phys_write_half)
540 rlwinm r3,r3,0,0,31 ; truncate address to 32-bits
541 ml_phys_write_half_join: ; r3 = address to write (reg64_t), r4 = data
542 mflr r11 ; Save the return
543 bl rdwrpre ; Get set up, translation/interrupts off, 64-bit on, etc.
544
545 sth r4,0(r3) ; Set the half word
546 b rdwrpost ; Clean up and leave...
547
548
549 /* Write physical address word
550 *
551 * void ml_phys_write(vm_offset_t paddr, unsigned int data)
552 * void ml_phys_write_64(addr64_t paddr, unsigned int data)
553 * void ml_phys_write_word(vm_offset_t paddr, unsigned int data)
554 * void ml_phys_write_word_64(addr64_t paddr, unsigned int data)
555 *
556 * Write the word at physical address paddr. Memory should not be cache inhibited.
557 */
558
559 .align 5
560 .globl EXT(ml_phys_write_64)
561 .globl EXT(ml_phys_write_word_64)
562
563 LEXT(ml_phys_write_64)
564 LEXT(ml_phys_write_word_64)
565
566 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
567 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
568 mr r4,r5 ; Copy over the data
569 b ml_phys_write_word_join
570
571 .globl EXT(ml_phys_write)
572 .globl EXT(ml_phys_write_word)
573
574 LEXT(ml_phys_write)
575 LEXT(ml_phys_write_word)
576 rlwinm r3,r3,0,0,31 ; truncate address to 32-bits
577 ml_phys_write_word_join: ; r3 = address to write (reg64_t), r4 = data
578 mflr r11 ; Save the return
579 bl rdwrpre ; Get set up, translation/interrupts off, 64-bit on, etc.
580
581 stw r4,0(r3) ; Set the word
582 b rdwrpost ; Clean up and leave...
583
584
585 /* Write physical address double word
586 *
587 * void ml_phys_write_double(vm_offset_t paddr, unsigned long long data)
588 * void ml_phys_write_double_64(addr64_t paddr, unsigned long long data)
589 *
590 * Write the double word at physical address paddr. Memory should not be cache inhibited.
591 */
592
593 .align 5
594 .globl EXT(ml_phys_write_double_64)
595
596 LEXT(ml_phys_write_double_64)
597
598 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
599 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
600 mr r4,r5 ; Copy over the high data
601 mr r5,r6 ; Copy over the low data
602 b ml_phys_write_double_join
603
604 .globl EXT(ml_phys_write_double)
605
606 LEXT(ml_phys_write_double)
607 rlwinm r3,r3,0,0,31 ; truncate address to 32-bits
608 ml_phys_write_double_join: ; r3 = address to write (reg64_t), r4,r5 = data (long long)
609 mflr r11 ; Save the return
610 bl rdwrpre ; Get set up, translation/interrupts off, 64-bit on, etc.
611
612 stw r4,0(r3) ; Set the high word
613 stw r5,4(r3) ; Set the low word
614 b rdwrpost ; Clean up and leave...
615
616
617 .align 5
618
619 rdwrpre: mfsprg r12,2 ; Get feature flags
620 lis r8,hi16(MASK(MSR_VEC)) ; Get the vector flag
621 mfmsr r10 ; Save the MSR
622 ori r8,r8,lo16(MASK(MSR_FP)) ; Add the FP flag
623 mtcrf 0x02,r12 ; move pf64Bit
624 andc r10,r10,r8 ; Clear VEC and FP
625 ori r9,r8,lo16(MASK(MSR_EE)|MASK(MSR_IR)|MASK(MSR_DR)) ; Drop EE, DR, and IR
626 li r2,1 ; Prepare for 64 bit
627 andc r9,r10,r9 ; Clear VEC, FP, DR, and EE
628 bf-- pf64Bitb,rdwrpre32 ; Join 32-bit code...
629
630 srdi r7,r3,31 ; Get a 1 if address is in I/O memory
631 rldimi r9,r2,63,MSR_SF_BIT ; set SF bit (bit 0)
632 cmpldi cr7,r7,1 ; Is source in I/O memory?
633 mtmsrd r9 ; set 64-bit mode, turn off EE, DR, and IR
634 isync ; synchronize
635
636 sldi r0,r2,32+8 ; Get the right bit to turn off caching
637
638 bnelr++ cr7 ; We are not in the I/O area, all ready...
639
640 mfspr r8,hid4 ; Get HID4
641 or r2,r8,r0 ; Set bit to make real accesses cache-inhibited
642 sync ; Sync up
643 mtspr hid4,r2 ; Make real accesses cache-inhibited
644 isync ; Toss prefetches
645
646 lis r7,0xE000 ; Get the unlikeliest ESID possible
647 srdi r7,r7,1 ; Make 0x7FFFFFFFF0000000
648 slbie r7 ; Make sure the ERAT is cleared
649
650 sync
651 isync
652 blr ; Finally, all ready...
653
654 .align 5
655
656 rdwrpre32: rlwimi r9,r10,0,MSR_IR_BIT,MSR_IR_BIT ; Leave the IR bit unchanged
657 mtmsr r9 ; Drop EE, DR, and leave IR unchanged
658 isync
659 blr ; All set up, leave...
660
661 .align 5
662
663 rdwrpost: mtlr r11 ; Restore the return
664 bt++ pf64Bitb,rdwrpost64 ; Join 64-bit code...
665
666 mtmsr r10 ; Restore entry MSR (sans FP and VEC)
667 isync
668 blr ; Leave...
669
670 rdwrpost64: bne++ cr7,rdwrpcok ; Skip enabling real mode caching if we did not change it...
671
672 sync ; Sync up
673 mtspr hid4,r8 ; Make real accesses not cache-inhibited
674 isync ; Toss prefetches
675
676 lis r7,0xE000 ; Get the unlikeliest ESID possible
677 srdi r7,r7,1 ; Make 0x7FFFFFFFF0000000
678 slbie r7 ; Make sure the ERAT is cleared
679
680 rdwrpcok: mtmsrd r10 ; Restore entry MSR (sans FP and VEC)
681 isync
682 blr ; Leave...
683
684
685 /* set interrupts enabled or disabled
686 *
687 * boolean_t set_interrupts_enabled(boolean_t enable)
688 *
689 * Set EE bit to "enable" and return old value as boolean
690 */
691
692 ; Force a line boundry here
693 .align 5
694 .globl EXT(ml_set_interrupts_enabled)
695
696 LEXT(ml_set_interrupts_enabled)
697
698 andi. r4,r3,1 ; Are we turning interruptions on?
699 lis r0,hi16(MASK(MSR_VEC)) ; Get vector enable
700 mfmsr r5 ; Get the current MSR
701 ori r0,r0,lo16(MASK(MSR_EE)|MASK(MSR_FP)) ; Get float enable and EE enable
702 rlwinm r3,r5,17,31,31 ; Set return value
703 andc r5,r5,r0 ; Force VEC and FP off
704 bne CheckPreemption ; Interrupts going on, check ASTs...
705
706 mtmsr r5 ; Slam diable (always going disabled here)
707 isync ; Need this because FP/Vec might go off
708 blr
709
710 .align 5
711
712 CheckPreemption:
713 mfsprg r7,0
714 ori r5,r5,lo16(MASK(MSR_EE)) ; Turn on the enable
715 lwz r8,PP_NEED_AST(r7) ; Get pointer to AST flags
716 mfsprg r9,1 ; Get current activation
717 li r6,AST_URGENT ; Get the type we will preempt for
718 lwz r7,ACT_PREEMPT_CNT(r9) ; Get preemption count
719 lwz r8,0(r8) ; Get AST flags
720 lis r0,hi16(DoPreemptCall) ; High part of Preempt FW call
721 cmpwi cr1,r7,0 ; Are preemptions masked off?
722 and. r8,r8,r6 ; Are we urgent?
723 crorc cr1_eq,cr0_eq,cr1_eq ; Remember if preemptions are masked or not urgent
724 ori r0,r0,lo16(DoPreemptCall) ; Bottome of FW call
725
726 mtmsr r5 ; Restore the MSR now, before we can preempt
727 isync ; Need this because FP/Vec might go off
728
729 beqlr++ cr1 ; Return if no premption...
730 sc ; Preempt
731 blr
732
733 /* Emulate a decremeter exception
734 *
735 * void machine_clock_assist(void)
736 *
737 */
738
739 ; Force a line boundry here
740 .align 5
741 .globl EXT(machine_clock_assist)
742
743 LEXT(machine_clock_assist)
744
745 mfsprg r7,0
746 lwz r4,PP_INTS_ENABLED(r7)
747 mr. r4,r4
748 bnelr+ cr0
749 b EXT(CreateFakeDEC)
750
751 /* Set machine into idle power-saving mode.
752 *
753 * void machine_idle_ppc(void)
754 *
755 * We will use the PPC NAP or DOZE for this.
756 * This call always returns. Must be called with spllo (i.e., interruptions
757 * enabled).
758 *
759 */
760
761 ; Force a line boundry here
762 .align 5
763 .globl EXT(machine_idle_ppc)
764
765 LEXT(machine_idle_ppc)
766
767 lis r0,hi16(MASK(MSR_VEC)) ; Get the vector flag
768 mfmsr r3 ; Save the MSR
769 ori r0,r0,lo16(MASK(MSR_FP)) ; Add the FP flag
770 andc r3,r3,r0 ; Clear VEC and FP
771 ori r0,r0,lo16(MASK(MSR_EE)) ; Drop EE also
772 andc r5,r3,r0 ; Clear VEC, FP, DR, and EE
773
774 mtmsr r5 ; Hold up interruptions for now
775 isync ; May have messed with fp/vec
776 mfsprg r12,0 ; Get the per_proc_info
777 mfsprg r11,2 ; Get CPU specific features
778 mfspr r6,hid0 ; Get the current power-saving mode
779 mtcrf 0xC7,r11 ; Get the facility flags
780
781 lis r4,hi16(napm) ; Assume we can nap
782 bt pfWillNapb,yesnap ; Yeah, nap is ok...
783
784 lis r4,hi16(dozem) ; Assume we can doze
785 bt pfCanDozeb,yesnap ; We can sleep or doze one this machine...
786
787 ori r3,r3,lo16(MASK(MSR_EE)) ; Flip on EE
788 mtmsr r3 ; Turn interruptions back on
789 blr ; Leave...
790
791 yesnap: mftbu r9 ; Get the upper timebase
792 mftb r7 ; Get the lower timebase
793 mftbu r8 ; Get the upper one again
794 cmplw r9,r8 ; Did the top tick?
795 bne- yesnap ; Yeah, need to get it again...
796
797 stw r8,napStamp(r12) ; Set high order time stamp
798 stw r7,napStamp+4(r12) ; Set low order nap stamp
799
800 rlwinm. r0,r11,0,pfAltivecb,pfAltivecb ; Do we have altivec?
801 beq- minovec ; No...
802 dssall ; Stop the streams before we nap/doze
803 sync
804 lwz r8,napStamp(r12) ; Reload high order time stamp
805 clearpipe:
806 cmplw r8,r8
807 bne- clearpipe
808 isync
809 minovec:
810
811 rlwinm. r7,r11,0,pfNoL2PFNapb,pfNoL2PFNapb ; Turn off L2 Prefetch before nap?
812 beq miL2PFok
813
814 mfspr r7,msscr0 ; Get currect MSSCR0 value
815 rlwinm r7,r7,0,0,l2pfes-1 ; Disable L2 Prefetch
816 mtspr msscr0,r7 ; Updates MSSCR0 value
817 sync
818 isync
819
820 miL2PFok:
821 rlwinm. r7,r11,0,pfSlowNapb,pfSlowNapb ; Should nap at slow speed?
822 beq minoslownap
823
824 mfspr r7,hid1 ; Get current HID1 value
825 oris r7,r7,hi16(hid1psm) ; Select PLL1
826 mtspr hid1,r7 ; Update HID1 value
827
828 minoslownap:
829
830 ;
831 ; We have to open up interruptions here because book 4 says that we should
832 ; turn on only the POW bit and that we should have interrupts enabled
833 ; The interrupt handler will detect that nap or doze is set if an interrupt
834 ; is taken and set everything up to return directly to machine_idle_ret.
835 ; So, make sure everything we need there is already set up...
836 ;
837
838 lis r10,hi16(dozem|napm|sleepm) ; Mask of power management bits
839
840 bf-- pf64Bitb,mipNSF1 ; skip if 32-bit...
841
842 sldi r4,r4,32 ; Position the flags
843 sldi r10,r10,32 ; Position the masks
844
845
846 mipNSF1: andc r6,r6,r10 ; Clean up the old power bits
847
848 ori r7,r5,lo16(MASK(MSR_EE)) ; Flip on EE
849 or r6,r6,r4 ; Set nap or doze
850 oris r5,r7,hi16(MASK(MSR_POW)) ; Turn on power management in next MSR
851
852 sync
853 mtspr hid0,r6 ; Set up the HID for nap/doze
854 mfspr r6,hid0 ; Yes, this is silly, keep it here
855 mfspr r6,hid0 ; Yes, this is a duplicate, keep it here
856 mfspr r6,hid0 ; Yes, this is a duplicate, keep it here
857 mfspr r6,hid0 ; Yes, this is a duplicate, keep it here
858 mfspr r6,hid0 ; Yes, this is a duplicate, keep it here
859 mfspr r6,hid0 ; Yes, this is a duplicate, keep it here
860 isync ; Make sure it is set
861
862 mtmsr r7 ; Enable for interrupts
863
864 bf-- pf64Bitb,mipowloop ; skip if 32-bit...
865
866 li r3,0x10 ; Fancy nap threashold is 0x10 ticks
867 mftb r8 ; Get the low half of the time base
868 mfdec r4 ; Get the decrementer ticks
869 cmplw r4,r3 ; Less than threashold?
870 blt mipowloop
871
872 mtdec r3 ; Load decrimenter with threshold
873 isync ; and make sure,
874 mfdec r3 ; really sure, it gets there
875
876 rlwinm r6,r5,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Clear out the EE bit
877 sync ; Make sure queues are clear
878 mtmsr r6 ; Set MSR with EE off but POW on
879 isync ; Make sure this takes before we proceed
880
881 mftb r9 ; Get the low half of the time base
882 sub r9,r9,r8 ; Get the number of ticks spent waiting
883 sub r4,r4,r9 ; Adjust the decrementer value
884
885 mtdec r4 ; Load decrimenter with the rest of the timeout
886 isync ; and make sure,
887 mfdec r4 ; really sure, it gets there
888
889 mipowloop:
890 sync ; Make sure queues are clear
891 mtmsr r5 ; Nap or doze, MSR with POW and EE set
892 isync ; Make sure this takes before we proceed
893 b mipowloop ; loop if POW does not take
894
895 ;
896 ; Note that the interrupt handler will turn off the nap/doze bits in the hid.
897 ; Also remember that the interrupt handler will force return to here whenever
898 ; the nap/doze bits are set.
899 ;
900 .globl EXT(machine_idle_ret)
901 LEXT(machine_idle_ret)
902 mtmsr r7 ; Make sure the MSR is what we want
903 isync ; In case we turn on translation
904
905 blr ; Return...
906
907 /* Put machine to sleep.
908 * This call never returns. We always exit sleep via a soft reset.
909 * All external interruptions must be drained at this point and disabled.
910 *
911 * void ml_ppc_sleep(void)
912 *
913 * We will use the PPC SLEEP for this.
914 *
915 * There is one bit of hackery in here: we need to enable for
916 * interruptions when we go to sleep and there may be a pending
917 * decrimenter rupt. So we make the decrimenter 0x7FFFFFFF and enable for
918 * interruptions. The decrimenter rupt vector recognizes this and returns
919 * directly back here.
920 *
921 */
922
923 ; Force a line boundry here
924 .align 5
925 .globl EXT(ml_ppc_sleep)
926
927 LEXT(ml_ppc_sleep)
928
929 #if 0
930 mfmsr r5 ; Hack to spin instead of sleep
931 rlwinm r5,r5,0,MSR_DR_BIT+1,MSR_IR_BIT-1 ; Turn off translation
932 rlwinm r5,r5,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Turn off interruptions
933 mtmsr r5 ; No talking
934 isync
935
936 deadsleep: addi r3,r3,1 ; Make analyzer happy
937 addi r3,r3,1
938 addi r3,r3,1
939 b deadsleep ; Die the death of 1000 joys...
940 #endif
941
942 mfsprg r12,0 ; Get the per_proc_info
943 mfspr r4,hid0 ; Get the current power-saving mode
944 eqv r10,r10,r10 ; Get all foxes
945 mfsprg r11,2 ; Get CPU specific features
946
947 rlwinm. r5,r11,0,pfNoL2PFNapb,pfNoL2PFNapb ; Turn off L2 Prefetch before sleep?
948 beq mpsL2PFok
949
950 mfspr r5,msscr0 ; Get currect MSSCR0 value
951 rlwinm r5,r5,0,0,l2pfes-1 ; Disable L2 Prefetch
952 mtspr msscr0,r5 ; Updates MSSCR0 value
953 sync
954 isync
955
956 mpsL2PFok:
957 rlwinm. r5,r11,0,pf64Bitb,pf64Bitb ; PM bits are shifted on 64bit systems.
958 bne mpsPF64bit
959
960 rlwinm r4,r4,0,sleep+1,doze-1 ; Clear all possible power-saving modes (not DPM though)
961 oris r4,r4,hi16(sleepm) ; Set sleep
962 b mpsClearDEC
963
964 mpsPF64bit:
965 lis r5, hi16(dozem|napm|sleepm) ; Clear all possible power-saving modes (not DPM though)
966 sldi r5, r5, 32
967 andc r4, r4, r5
968 lis r5, hi16(napm) ; Set sleep
969 sldi r5, r5, 32
970 or r4, r4, r5
971
972 mpsClearDEC:
973 mfmsr r5 ; Get the current MSR
974 rlwinm r10,r10,0,1,31 ; Make 0x7FFFFFFF
975 mtdec r10 ; Load decrimenter with 0x7FFFFFFF
976 isync ; and make sure,
977 mfdec r9 ; really sure, it gets there
978
979 mtcrf 0x07,r11 ; Get the cache flags, etc
980
981 rlwinm r5,r5,0,MSR_DR_BIT+1,MSR_IR_BIT-1 ; Turn off translation
982 ;
983 ; Note that we need translation off before we set the HID to sleep. Otherwise
984 ; we will ignore any PTE misses that occur and cause an infinite loop.
985 ;
986 bt pfNoMSRirb,mpsNoMSR ; No MSR...
987
988 mtmsr r5 ; Translation off
989 isync ; Toss prefetch
990 b mpsNoMSRx
991
992 mpsNoMSR:
993 li r0,loadMSR ; Get the MSR setter SC
994 mr r3,r5 ; Get new MSR
995 sc ; Set it
996 mpsNoMSRx:
997
998 ori r3,r5,lo16(MASK(MSR_EE)) ; Flip on EE
999 sync
1000 mtspr hid0,r4 ; Set up the HID to sleep
1001 mfspr r4,hid0 ; Yes, this is silly, keep it here
1002 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1003 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1004 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1005 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1006 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1007
1008 mtmsr r3 ; Enable for interrupts to drain decrimenter
1009
1010 add r6,r4,r5 ; Just waste time
1011 add r6,r6,r4 ; A bit more
1012 add r6,r6,r5 ; A bit more
1013
1014 mtmsr r5 ; Interruptions back off
1015 isync ; Toss prefetch
1016
1017 ;
1018 ; We are here with translation off, interrupts off, all possible
1019 ; interruptions drained off, and a decrimenter that will not pop.
1020 ;
1021
1022 bl EXT(cacheInit) ; Clear out the caches. This will leave them on
1023 bl EXT(cacheDisable) ; Turn off all caches
1024
1025 mfmsr r5 ; Get the current MSR
1026 oris r5,r5,hi16(MASK(MSR_POW)) ; Turn on power management in next MSR
1027 ; Leave EE off because power goes off shortly
1028 mfsprg r12,0 ; Get the per_proc_info
1029 li r10,PP_CPU_FLAGS
1030 lhz r11,PP_CPU_FLAGS(r12) ; Get the flags
1031 ori r11,r11,SleepState ; Marked SleepState
1032 sth r11,PP_CPU_FLAGS(r12) ; Set the flags
1033 dcbf r10,r12
1034
1035 mfsprg r11,2 ; Get CPU specific features
1036 rlwinm. r0,r11,0,pf64Bitb,pf64Bitb ; Test for 64 bit processor
1037 eqv r4,r4,r4 ; Get all foxes
1038 rlwinm r4,r4,0,1,31 ; Make 0x7FFFFFFF
1039 beq slSleepNow ; skip if 32-bit...
1040 li r3, 0x4000 ; Cause decrimenter to roll over soon
1041 mtdec r3 ; Load decrimenter with 0x00004000
1042 isync ; and make sure,
1043 mfdec r3 ; really sure, it gets there
1044
1045 slSleepNow:
1046 sync ; Sync it all up
1047 mtmsr r5 ; Do sleep with interruptions enabled
1048 isync ; Take a pill
1049 mtdec r4 ; Load decrimenter with 0x7FFFFFFF
1050 isync ; and make sure,
1051 mfdec r3 ; really sure, it gets there
1052 b slSleepNow ; Go back to sleep if we wake up...
1053
1054
1055
1056 /* Initialize all caches including the TLBs
1057 *
1058 * void cacheInit(void)
1059 *
1060 * This is used to force the caches to an initial clean state. First, we
1061 * check if the cache is on, if so, we need to flush the contents to memory.
1062 * Then we invalidate the L1. Next, we configure and invalidate the L2 etc.
1063 * Finally we turn on all of the caches
1064 *
1065 * Note that if translation is not disabled when this is called, the TLB will not
1066 * be completely clear after return.
1067 *
1068 */
1069
1070 ; Force a line boundry here
1071 .align 5
1072 .globl EXT(cacheInit)
1073
1074 LEXT(cacheInit)
1075
1076 mfsprg r12,0 ; Get the per_proc_info
1077 mfspr r9,hid0 ; Get the current power-saving mode
1078
1079 mfsprg r11,2 ; Get CPU specific features
1080 mfmsr r7 ; Get the current MSR
1081 rlwinm r7,r7,0,MSR_FP_BIT+1,MSR_FP_BIT-1 ; Force floating point off
1082 rlwinm r7,r7,0,MSR_VEC_BIT+1,MSR_VEC_BIT-1 ; Force vectors off
1083 rlwimi r11,r11,pfLClckb+1,31,31 ; Move pfLClck to another position (to keep from using non-volatile CRs)
1084 rlwinm r5,r7,0,MSR_DR_BIT+1,MSR_IR_BIT-1 ; Turn off translation
1085 rlwinm r5,r5,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Turn off interruptions
1086 mtcrf 0x87,r11 ; Get the feature flags
1087 lis r10,hi16(dozem|napm|sleepm|dpmm) ; Mask of power management bits
1088 bf-- pf64Bitb,cIniNSF1 ; Skip if 32-bit...
1089
1090 sldi r10,r10,32 ; Position the masks
1091
1092 cIniNSF1: andc r4,r9,r10 ; Clean up the old power bits
1093 mtspr hid0,r4 ; Set up the HID
1094 mfspr r4,hid0 ; Yes, this is silly, keep it here
1095 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1096 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1097 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1098 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1099 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1100
1101 bt pfNoMSRirb,ciNoMSR ; No MSR...
1102
1103 mtmsr r5 ; Translation and all off
1104 isync ; Toss prefetch
1105 b ciNoMSRx
1106
1107 ciNoMSR:
1108 li r0,loadMSR ; Get the MSR setter SC
1109 mr r3,r5 ; Get new MSR
1110 sc ; Set it
1111 ciNoMSRx:
1112
1113 bf pfAltivecb,cinoDSS ; No Altivec here...
1114
1115 dssall ; Stop streams
1116 sync
1117
1118 cinoDSS: li r5,tlbieLock ; Get the TLBIE lock
1119 li r0,128 ; Get number of TLB entries
1120
1121 li r6,0 ; Start at 0
1122 bf-- pf64Bitb,citlbhang ; Skip if 32-bit...
1123 li r0,1024 ; Get the number of TLB entries
1124
1125 citlbhang: lwarx r2,0,r5 ; Get the TLBIE lock
1126 mr. r2,r2 ; Is it locked?
1127 bne- citlbhang ; It is locked, go wait...
1128 stwcx. r0,0,r5 ; Try to get it
1129 bne- citlbhang ; We was beat...
1130
1131 mtctr r0 ; Set the CTR
1132
1133 cipurgeTLB: tlbie r6 ; Purge this entry
1134 addi r6,r6,4096 ; Next page
1135 bdnz cipurgeTLB ; Do them all...
1136
1137 mtcrf 0x80,r11 ; Set SMP capability
1138 sync ; Make sure all TLB purges are done
1139 eieio ; Order, order in the court
1140
1141 bf pfSMPcapb,cinoSMP ; SMP incapable...
1142
1143 tlbsync ; Sync all TLBs
1144 sync
1145 isync
1146
1147 bf-- pf64Bitb,cinoSMP ; Skip if 32-bit...
1148 ptesync ; Wait for quiet again
1149 sync
1150
1151 cinoSMP: stw r2,tlbieLock(0) ; Unlock TLBIE lock
1152
1153 bt++ pf64Bitb,cin64 ; Skip if 64-bit...
1154
1155 rlwinm. r0,r9,0,ice,dce ; Were either of the level 1s on?
1156 beq- cinoL1 ; No, no need to flush...
1157
1158 rlwinm. r0,r11,0,pfL1fab,pfL1fab ; do we have L1 flush assist?
1159 beq ciswdl1 ; If no hw flush assist, go do by software...
1160
1161 mfspr r8,msscr0 ; Get the memory system control register
1162 oris r8,r8,hi16(dl1hwfm) ; Turn on the hardware flush request
1163
1164 mtspr msscr0,r8 ; Start the flush operation
1165
1166 ciwdl1f: mfspr r8,msscr0 ; Get the control register again
1167
1168 rlwinm. r8,r8,0,dl1hwf,dl1hwf ; Has the flush request been reset yet?
1169 bne ciwdl1f ; No, flush is still in progress...
1170 b ciinvdl1 ; Go invalidate l1...
1171
1172 ;
1173 ; We need to either make this very complicated or to use ROM for
1174 ; the flush. The problem is that if during the following sequence a
1175 ; snoop occurs that invalidates one of the lines in the cache, the
1176 ; PLRU sequence will be altered making it possible to miss lines
1177 ; during the flush. So, we either need to dedicate an area of RAM
1178 ; to each processor, lock use of a RAM area, or use ROM. ROM is
1179 ; by far the easiest. Note that this is not an issue for machines
1180 ; that have harware flush assists.
1181 ;
1182
1183 ciswdl1: lwz r0,pfl1dSize(r12) ; Get the level 1 cache size
1184
1185 bf 31,cisnlck ; Skip if pfLClck not set...
1186
1187 mfspr r4,msscr0 ; ?
1188 rlwinm r6,r4,0,0,l2pfes-1 ; ?
1189 mtspr msscr0,r6 ; Set it
1190 sync
1191 isync
1192
1193 mfspr r8,ldstcr ; Save the LDSTCR
1194 li r2,1 ; Get a mask of 0x01
1195 lis r3,0xFFF0 ; Point to ROM
1196 rlwinm r11,r0,29,3,31 ; Get the amount of memory to handle all indexes
1197
1198 li r6,0 ; Start here
1199
1200 cisiniflsh: dcbf r6,r3 ; Flush each line of the range we use
1201 addi r6,r6,32 ; Bump to the next
1202 cmplw r6,r0 ; Have we reached the end?
1203 blt+ cisiniflsh ; Nope, continue initial flush...
1204
1205 sync ; Make sure it is done
1206
1207 addi r11,r11,-1 ; Get mask for index wrap
1208 li r6,0 ; Get starting offset
1209
1210 cislckit: not r5,r2 ; Lock all but 1 way
1211 rlwimi r5,r8,0,0,23 ; Build LDSTCR
1212 mtspr ldstcr,r5 ; Lock a way
1213 sync ; Clear out memory accesses
1214 isync ; Wait for all
1215
1216
1217 cistouch: lwzx r10,r3,r6 ; Pick up some trash
1218 addi r6,r6,32 ; Go to the next index
1219 and. r0,r6,r11 ; See if we are about to do next index
1220 bne+ cistouch ; Nope, do more...
1221
1222 sync ; Make sure it is all done
1223 isync
1224
1225 sub r6,r6,r11 ; Back up to start + 1
1226 addi r6,r6,-1 ; Get it right
1227
1228 cisflush: dcbf r3,r6 ; Flush everything out
1229 addi r6,r6,32 ; Go to the next index
1230 and. r0,r6,r11 ; See if we are about to do next index
1231 bne+ cisflush ; Nope, do more...
1232
1233 sync ; Make sure it is all done
1234 isync
1235
1236
1237 rlwinm. r2,r2,1,24,31 ; Shift to next way
1238 bne+ cislckit ; Do this for all ways...
1239
1240 mtspr ldstcr,r8 ; Slam back to original
1241 sync
1242 isync
1243
1244 mtspr msscr0,r4 ; ?
1245 sync
1246 isync
1247
1248 b cinoL1 ; Go on to level 2...
1249
1250
1251 cisnlck: rlwinm r2,r0,0,1,30 ; Double cache size
1252 add r0,r0,r2 ; Get 3 times cache size
1253 rlwinm r0,r0,26,6,31 ; Get 3/2 number of cache lines
1254 lis r3,0xFFF0 ; Dead recon ROM address for now
1255 mtctr r0 ; Number of lines to flush
1256
1257 ciswfldl1a: lwz r2,0(r3) ; Flush anything else
1258 addi r3,r3,32 ; Next line
1259 bdnz ciswfldl1a ; Flush the lot...
1260
1261 ciinvdl1: sync ; Make sure all flushes have been committed
1262
1263 mfspr r8,hid0 ; Get the HID0 bits
1264 rlwinm r8,r8,0,dce+1,ice-1 ; Clear cache enables
1265 mtspr hid0,r8 ; and turn off L1 cache
1266 sync ; Make sure all is done
1267 isync
1268
1269 ori r8,r8,lo16(icem|dcem|icfim|dcfim) ; Set the HID0 bits for enable, and invalidate
1270 sync
1271 isync
1272
1273 mtspr hid0,r8 ; Start the invalidate and turn on cache
1274 rlwinm r8,r8,0,dcfi+1,icfi-1 ; Turn off the invalidate bits
1275 mtspr hid0,r8 ; Turn off the invalidate (needed for some older machines)
1276 sync
1277
1278
1279 cinoL1:
1280 ;
1281 ; Flush and disable the level 2
1282 ;
1283 mfsprg r10,2 ; need to check 2 features we did not put in CR
1284 rlwinm. r0,r10,0,pfL2b,pfL2b ; do we have L2?
1285 beq cinol2 ; No level 2 cache to flush
1286
1287 mfspr r8,l2cr ; Get the L2CR
1288 lwz r3,pfl2cr(r12) ; Get the L2CR value
1289 rlwinm. r0,r8,0,l2e,l2e ; Was the L2 enabled?
1290 bne ciflushl2 ; Yes, force flush
1291 cmplwi r8, 0 ; Was the L2 all the way off?
1292 beq ciinvdl2 ; Yes, force invalidate
1293 lis r0,hi16(l2sizm|l2clkm|l2ramm|l2ohm) ; Get confiuration bits
1294 xor r2,r8,r3 ; Get changing bits?
1295 ori r0,r0,lo16(l2slm|l2dfm|l2bypm) ; More config bits
1296 and. r0,r0,r2 ; Did any change?
1297 bne- ciinvdl2 ; Yes, just invalidate and get PLL synced...
1298
1299 ciflushl2:
1300 rlwinm. r0,r10,0,pfL2fab,pfL2fab ; hardware-assisted L2 flush?
1301 beq ciswfl2 ; Flush not in hardware...
1302
1303 mr r10,r8 ; Take a copy now
1304
1305 bf 31,cinol2lck ; Skip if pfLClck not set...
1306
1307 oris r10,r10,hi16(l2ionlym|l2donlym) ; Set both instruction- and data-only
1308 sync
1309 mtspr l2cr,r10 ; Lock out the cache
1310 sync
1311 isync
1312
1313 cinol2lck: ori r10,r10,lo16(l2hwfm) ; Request flush
1314 sync ; Make sure everything is done
1315
1316 mtspr l2cr,r10 ; Request flush
1317
1318 cihwfl2: mfspr r10,l2cr ; Get back the L2CR
1319 rlwinm. r10,r10,0,l2hwf,l2hwf ; Is the flush over?
1320 bne+ cihwfl2 ; Nope, keep going...
1321 b ciinvdl2 ; Flush done, go invalidate L2...
1322
1323 ciswfl2:
1324 lwz r0,pfl2Size(r12) ; Get the L2 size
1325 oris r2,r8,hi16(l2dom) ; Set L2 to data only mode
1326
1327 b ciswfl2doa ; Branch to next line...
1328
1329 .align 5
1330 ciswfl2doc:
1331 mtspr l2cr,r2 ; Disable L2
1332 sync
1333 isync
1334 b ciswfl2dod ; It is off, go invalidate it...
1335
1336 ciswfl2doa:
1337 b ciswfl2dob ; Branch to next...
1338
1339 ciswfl2dob:
1340 sync ; Finish memory stuff
1341 isync ; Stop speculation
1342 b ciswfl2doc ; Jump back up and turn on data only...
1343 ciswfl2dod:
1344 rlwinm r0,r0,27,5,31 ; Get the number of lines
1345 lis r10,0xFFF0 ; Dead recon ROM for now
1346 mtctr r0 ; Set the number of lines
1347
1348 ciswfldl2a: lwz r0,0(r10) ; Load something to flush something
1349 addi r10,r10,32 ; Next line
1350 bdnz ciswfldl2a ; Do the lot...
1351
1352 ciinvdl2: rlwinm r8,r3,0,l2e+1,31 ; Clear the enable bit
1353 b cinla ; Branch to next line...
1354
1355 .align 5
1356 cinlc: mtspr l2cr,r8 ; Disable L2
1357 sync
1358 isync
1359 b ciinvl2 ; It is off, go invalidate it...
1360
1361 cinla: b cinlb ; Branch to next...
1362
1363 cinlb: sync ; Finish memory stuff
1364 isync ; Stop speculation
1365 b cinlc ; Jump back up and turn off cache...
1366
1367 ciinvl2: sync
1368 isync
1369
1370 cmplwi r3, 0 ; Should the L2 be all the way off?
1371 beq cinol2 ; Yes, done with L2
1372
1373 oris r2,r8,hi16(l2im) ; Get the invalidate flag set
1374
1375 mtspr l2cr,r2 ; Start the invalidate
1376 sync
1377 isync
1378 ciinvdl2a: mfspr r2,l2cr ; Get the L2CR
1379 mfsprg r0,2 ; need to check a feature in "non-volatile" set
1380 rlwinm. r0,r0,0,pfL2ib,pfL2ib ; flush in HW?
1381 beq ciinvdl2b ; Flush not in hardware...
1382 rlwinm. r2,r2,0,l2i,l2i ; Is the invalidate still going?
1383 bne+ ciinvdl2a ; Assume so, this will take a looong time...
1384 sync
1385 b cinol2 ; No level 2 cache to flush
1386 ciinvdl2b:
1387 rlwinm. r2,r2,0,l2ip,l2ip ; Is the invalidate still going?
1388 bne+ ciinvdl2a ; Assume so, this will take a looong time...
1389 sync
1390 mtspr l2cr,r8 ; Turn off the invalidate request
1391
1392 cinol2:
1393
1394 ;
1395 ; Flush and enable the level 3
1396 ;
1397 bf pfL3b,cinol3 ; No level 3 cache to flush
1398
1399 mfspr r8,l3cr ; Get the L3CR
1400 lwz r3,pfl3cr(r12) ; Get the L3CR value
1401 rlwinm. r0,r8,0,l3e,l3e ; Was the L3 enabled?
1402 bne ciflushl3 ; Yes, force flush
1403 cmplwi r8, 0 ; Was the L3 all the way off?
1404 beq ciinvdl3 ; Yes, force invalidate
1405 lis r0,hi16(l3pem|l3sizm|l3dxm|l3clkm|l3spom|l3ckspm) ; Get configuration bits
1406 xor r2,r8,r3 ; Get changing bits?
1407 ori r0,r0,lo16(l3pspm|l3repm|l3rtm|l3cyam|l3dmemm|l3dmsizm) ; More config bits
1408 and. r0,r0,r2 ; Did any change?
1409 bne- ciinvdl3 ; Yes, just invalidate and get PLL synced...
1410
1411 ciflushl3:
1412 sync ; 7450 book says do this even though not needed
1413 mr r10,r8 ; Take a copy now
1414
1415 bf 31,cinol3lck ; Skip if pfL23lck not set...
1416
1417 oris r10,r10,hi16(l3iom) ; Set instruction-only
1418 ori r10,r10,lo16(l3donlym) ; Set data-only
1419 sync
1420 mtspr l3cr,r10 ; Lock out the cache
1421 sync
1422 isync
1423
1424 cinol3lck: ori r10,r10,lo16(l3hwfm) ; Request flush
1425 sync ; Make sure everything is done
1426
1427 mtspr l3cr,r10 ; Request flush
1428
1429 cihwfl3: mfspr r10,l3cr ; Get back the L3CR
1430 rlwinm. r10,r10,0,l3hwf,l3hwf ; Is the flush over?
1431 bne+ cihwfl3 ; Nope, keep going...
1432
1433 ciinvdl3: rlwinm r8,r3,0,l3e+1,31 ; Clear the enable bit
1434 sync ; Make sure of life, liberty, and justice
1435 mtspr l3cr,r8 ; Disable L3
1436 sync
1437
1438 cmplwi r3, 0 ; Should the L3 be all the way off?
1439 beq cinol3 ; Yes, done with L3
1440
1441 ori r8,r8,lo16(l3im) ; Get the invalidate flag set
1442
1443 mtspr l3cr,r8 ; Start the invalidate
1444
1445 ciinvdl3b: mfspr r8,l3cr ; Get the L3CR
1446 rlwinm. r8,r8,0,l3i,l3i ; Is the invalidate still going?
1447 bne+ ciinvdl3b ; Assume so...
1448 sync
1449
1450 lwz r10, pfBootConfig(r12) ; ?
1451 rlwinm. r10, r10, 24, 28, 31 ; ?
1452 beq ciinvdl3nopdet ; ?
1453
1454 mfspr r8,l3pdet ; ?
1455 srw r2, r8, r10 ; ?
1456 rlwimi r2, r8, 0, 24, 31 ; ?
1457 subfic r10, r10, 32 ; ?
1458 li r8, -1 ; ?
1459 ori r2, r2, 0x0080 ; ?
1460 slw r8, r8, r10 ; ?
1461 or r8, r2, r8 ; ?
1462 mtspr l3pdet, r8 ; ?
1463 isync
1464
1465 ciinvdl3nopdet:
1466 mfspr r8,l3cr ; Get the L3CR
1467 rlwinm r8,r8,0,l3clken+1,l3clken-1 ; Clear the clock enable bit
1468 mtspr l3cr,r8 ; Disable the clock
1469
1470 li r2,128 ; ?
1471 ciinvdl3c: addi r2,r2,-1 ; ?
1472 cmplwi r2,0 ; ?
1473 bne+ ciinvdl3c
1474
1475 mfspr r10,msssr0 ; ?
1476 rlwinm r10,r10,0,vgL3TAG+1,vgL3TAG-1 ; ?
1477 mtspr msssr0,r10 ; ?
1478 sync
1479
1480 mtspr l3cr,r3 ; Enable it as desired
1481 sync
1482 cinol3:
1483 mfsprg r0,2 ; need to check a feature in "non-volatile" set
1484 rlwinm. r0,r0,0,pfL2b,pfL2b ; is there an L2 cache?
1485 beq cinol2a ; No level 2 cache to enable
1486
1487 lwz r3,pfl2cr(r12) ; Get the L2CR value
1488 cmplwi r3, 0 ; Should the L2 be all the way off?
1489 beq cinol2a : Yes, done with L2
1490 mtspr l2cr,r3 ; Enable it as desired
1491 sync
1492
1493 ;
1494 ; Invalidate and turn on L1s
1495 ;
1496
1497 cinol2a:
1498 bt 31,cinoexit ; Skip if pfLClck set...
1499
1500 rlwinm r8,r9,0,dce+1,ice-1 ; Clear the I- and D- cache enables
1501 mtspr hid0,r8 ; Turn off dem caches
1502 sync
1503
1504 ori r8,r9,lo16(icem|dcem|icfim|dcfim) ; Set the HID0 bits for enable, and invalidate
1505 rlwinm r9,r8,0,dcfi+1,icfi-1 ; Turn off the invalidate bits
1506 sync
1507 isync
1508
1509 mtspr hid0,r8 ; Start the invalidate and turn on L1 cache
1510
1511 cinoexit: mtspr hid0,r9 ; Turn off the invalidate (needed for some older machines) and restore entry conditions
1512 sync
1513 mtmsr r7 ; Restore MSR to entry
1514 isync
1515 blr ; Return...
1516
1517
1518 ;
1519 ; Handle 64-bit architecture
1520 ; This processor can not run without caches, so we just push everything out
1521 ; and flush. It will be relativily clean afterwards
1522 ;
1523
1524 .align 5
1525
1526 cin64:
1527 mfspr r10,hid1 ; Save hid1
1528 mfspr r4,hid4 ; Save hid4
1529 mr r12,r10 ; Really save hid1
1530 mr r11,r4 ; Get a working copy of hid4
1531
1532 li r0,0 ; Get a 0
1533 eqv r2,r2,r2 ; Get all foxes
1534
1535 rldimi r10,r0,55,7 ; Clear I$ prefetch bits (7:8)
1536
1537 isync
1538 mtspr hid1,r10 ; Stick it
1539 mtspr hid1,r10 ; Stick it again
1540 isync
1541
1542 rldimi r11,r2,38,25 ; Disable D$ prefetch (25:25)
1543
1544 sync
1545 mtspr hid4,r11 ; Stick it
1546 isync
1547
1548 li r3,8 ; Set bit 28+32
1549 sldi r3,r3,32 ; Make it bit 28
1550 or r3,r3,r11 ; Turn on the flash invalidate L1D$
1551
1552 oris r5,r11,0x0600 ; Set disable L1D$ bits
1553 sync
1554 mtspr hid4,r3 ; Invalidate
1555 isync
1556
1557 mtspr hid4,r5 ; Un-invalidate and disable L1D$
1558 isync
1559
1560 lis r8,GUSModeReg ; Get the GUS mode ring address
1561 mfsprg r0,2 ; Get the feature flags
1562 ori r8,r8,0x8000 ; Set to read data
1563 rlwinm. r0,r0,pfSCOMFixUpb+1,31,31 ; Set shift if we need a fix me up
1564
1565 sync
1566
1567 mtspr scomc,r8 ; Request the GUS mode
1568 mfspr r11,scomd ; Get the GUS mode
1569 mfspr r8,scomc ; Get back the status (we just ignore it)
1570 sync
1571 isync
1572
1573 sld r11,r11,r0 ; Fix up if needed
1574
1575 ori r6,r11,lo16(GUSMdmapen) ; Set the bit that means direct L2 cache address
1576 lis r8,GUSModeReg ; Get GUS mode register address
1577
1578 sync
1579
1580 mtspr scomd,r6 ; Set that we want direct L2 mode
1581 mtspr scomc,r8 ; Tell GUS we want direct L2 mode
1582 mfspr r3,scomc ; Get back the status
1583 sync
1584 isync
1585
1586 li r3,0 ; Clear start point
1587
1588 cflushlp: lis r6,0x0040 ; Pick 4MB line as our target
1589 or r6,r6,r3 ; Put in the line offset
1590 lwz r5,0(r6) ; Load a line
1591 addis r6,r6,8 ; Roll bit 42:44
1592 lwz r5,0(r6) ; Load a line
1593 addis r6,r6,8 ; Roll bit 42:44
1594 lwz r5,0(r6) ; Load a line
1595 addis r6,r6,8 ; Roll bit 42:44
1596 lwz r5,0(r6) ; Load a line
1597 addis r6,r6,8 ; Roll bit 42:44
1598 lwz r5,0(r6) ; Load a line
1599 addis r6,r6,8 ; Roll bit 42:44
1600 lwz r5,0(r6) ; Load a line
1601 addis r6,r6,8 ; Roll bit 42:44
1602 lwz r5,0(r6) ; Load a line
1603 addis r6,r6,8 ; Roll bit 42:44
1604 lwz r5,0(r6) ; Load a line
1605
1606 addi r3,r3,128 ; Next line
1607 andis. r5,r3,8 ; Have we done enough?
1608 beq++ cflushlp ; Not yet...
1609
1610 sync
1611
1612 lis r6,0x0040 ; Pick 4MB line as our target
1613
1614 cflushx: dcbf 0,r6 ; Flush line and invalidate
1615 addi r6,r6,128 ; Next line
1616 andis. r5,r6,0x0080 ; Have we done enough?
1617 beq++ cflushx ; Keep on flushing...
1618
1619 mr r3,r10 ; Copy current hid1
1620 rldimi r3,r2,54,9 ; Set force icbi match mode
1621
1622 li r6,0 ; Set start if ICBI range
1623 isync
1624 mtspr hid1,r3 ; Stick it
1625 mtspr hid1,r3 ; Stick it again
1626 isync
1627
1628 cflicbi: icbi 0,r6 ; Kill I$
1629 addi r6,r6,128 ; Next line
1630 andis. r5,r6,1 ; Have we done them all?
1631 beq++ cflicbi ; Not yet...
1632
1633 lis r8,GUSModeReg ; Get GUS mode register address
1634
1635 sync
1636
1637 mtspr scomd,r11 ; Set that we do not want direct mode
1638 mtspr scomc,r8 ; Tell GUS we do not want direct mode
1639 mfspr r3,scomc ; Get back the status
1640 sync
1641 isync
1642
1643 isync
1644 mtspr hid0,r9 ; Restore entry hid0
1645 mfspr r9,hid0 ; Yes, this is silly, keep it here
1646 mfspr r9,hid0 ; Yes, this is a duplicate, keep it here
1647 mfspr r9,hid0 ; Yes, this is a duplicate, keep it here
1648 mfspr r9,hid0 ; Yes, this is a duplicate, keep it here
1649 mfspr r9,hid0 ; Yes, this is a duplicate, keep it here
1650 mfspr r9,hid0 ; Yes, this is a duplicate, keep it here
1651 isync
1652
1653 isync
1654 mtspr hid1,r12 ; Restore entry hid1
1655 mtspr hid1,r12 ; Stick it again
1656 isync
1657
1658 sync
1659 mtspr hid4,r4 ; Restore entry hid4
1660 isync
1661
1662 sync
1663 mtmsr r7 ; Restore MSR to entry
1664 isync
1665 blr ; Return...
1666
1667
1668
1669 /* Disables all caches
1670 *
1671 * void cacheDisable(void)
1672 *
1673 * Turns off all caches on the processor. They are not flushed.
1674 *
1675 */
1676
1677 ; Force a line boundry here
1678 .align 5
1679 .globl EXT(cacheDisable)
1680
1681 LEXT(cacheDisable)
1682
1683 mfsprg r11,2 ; Get CPU specific features
1684 mtcrf 0x83,r11 ; Set feature flags
1685
1686 bf pfAltivecb,cdNoAlt ; No vectors...
1687
1688 dssall ; Stop streams
1689
1690 cdNoAlt: sync
1691
1692 btlr pf64Bitb ; No way to disable a 64-bit machine...
1693
1694 mfspr r5,hid0 ; Get the hid
1695 rlwinm r5,r5,0,dce+1,ice-1 ; Clear the I- and D- cache enables
1696 mtspr hid0,r5 ; Turn off dem caches
1697 sync
1698
1699 rlwinm. r0,r11,0,pfL2b,pfL2b ; is there an L2?
1700 beq cdNoL2 ; Skip if no L2...
1701
1702 mfspr r5,l2cr ; Get the L2
1703 rlwinm r5,r5,0,l2e+1,31 ; Turn off enable bit
1704
1705 b cinlaa ; Branch to next line...
1706
1707 .align 5
1708 cinlcc: mtspr l2cr,r5 ; Disable L2
1709 sync
1710 isync
1711 b cdNoL2 ; It is off, we are done...
1712
1713 cinlaa: b cinlbb ; Branch to next...
1714
1715 cinlbb: sync ; Finish memory stuff
1716 isync ; Stop speculation
1717 b cinlcc ; Jump back up and turn off cache...
1718
1719 cdNoL2:
1720
1721 bf pfL3b,cdNoL3 ; Skip down if no L3...
1722
1723 mfspr r5,l3cr ; Get the L3
1724 rlwinm r5,r5,0,l3e+1,31 ; Turn off enable bit
1725 rlwinm r5,r5,0,l3clken+1,l3clken-1 ; Turn off cache enable bit
1726 mtspr l3cr,r5 ; Disable the caches
1727 sync
1728
1729 cdNoL3:
1730 blr ; Leave...
1731
1732
1733 /* Initialize processor thermal monitoring
1734 * void ml_thrm_init(void)
1735 *
1736 * Obsolete, deprecated and will be removed.
1737 */
1738
1739 ; Force a line boundry here
1740 .align 5
1741 .globl EXT(ml_thrm_init)
1742
1743 LEXT(ml_thrm_init)
1744 blr
1745
1746 /* Set thermal monitor bounds
1747 * void ml_thrm_set(unsigned int low, unsigned int high)
1748 *
1749 * Obsolete, deprecated and will be removed.
1750 */
1751
1752 ; Force a line boundry here
1753 .align 5
1754 .globl EXT(ml_thrm_set)
1755
1756 LEXT(ml_thrm_set)
1757 blr
1758
1759 /* Read processor temprature
1760 * unsigned int ml_read_temp(void)
1761 *
1762 * Obsolete, deprecated and will be removed.
1763 */
1764
1765 ; Force a line boundry here
1766 .align 5
1767 .globl EXT(ml_read_temp)
1768
1769 LEXT(ml_read_temp)
1770 li r3,-1
1771 blr
1772
1773 /* Throttle processor speed up or down
1774 * unsigned int ml_throttle(unsigned int step)
1775 *
1776 * Returns old speed and sets new. Both step and return are values from 0 to
1777 * 255 that define number of throttle steps, 0 being off and "ictcfim" is max * 2.
1778 *
1779 * Obsolete, deprecated and will be removed.
1780 */
1781
1782 ; Force a line boundry here
1783 .align 5
1784 .globl EXT(ml_throttle)
1785
1786 LEXT(ml_throttle)
1787 li r3,0
1788 blr
1789
1790 /*
1791 ** ml_get_timebase()
1792 **
1793 ** Entry - R3 contains pointer to 64 bit structure.
1794 **
1795 ** Exit - 64 bit structure filled in.
1796 **
1797 */
1798 ; Force a line boundry here
1799 .align 5
1800 .globl EXT(ml_get_timebase)
1801
1802 LEXT(ml_get_timebase)
1803
1804 loop:
1805 mftbu r4
1806 mftb r5
1807 mftbu r6
1808 cmpw r6, r4
1809 bne- loop
1810
1811 stw r4, 0(r3)
1812 stw r5, 4(r3)
1813
1814 blr
1815
1816 /*
1817 * unsigned int cpu_number(void)
1818 *
1819 * Returns the current cpu number.
1820 */
1821
1822 .align 5
1823 .globl EXT(cpu_number)
1824
1825 LEXT(cpu_number)
1826 mfsprg r4,0 ; Get per-proc block
1827 lhz r3,PP_CPU_NUMBER(r4) ; Get CPU number
1828 blr ; Return...
1829
1830
1831 /*
1832 * void set_machine_current_act(thread_act_t)
1833 *
1834 * Set the current activation
1835 */
1836 .align 5
1837 .globl EXT(set_machine_current_act)
1838
1839 LEXT(set_machine_current_act)
1840
1841 mtsprg 1,r3 ; Set spr1 with the active thread
1842 blr ; Return...
1843
1844 /*
1845 * thread_t current_act(void)
1846 * thread_t current_thread(void)
1847 *
1848 *
1849 * Return the current thread for outside components.
1850 */
1851 .align 5
1852 .globl EXT(current_act)
1853 .globl EXT(current_thread)
1854
1855 LEXT(current_act)
1856 LEXT(current_thread)
1857
1858 mfsprg r3,1
1859 blr
1860
1861 .align 5
1862 .globl EXT(clock_get_uptime)
1863 LEXT(clock_get_uptime)
1864 1: mftbu r9
1865 mftb r0
1866 mftbu r11
1867 cmpw r11,r9
1868 bne- 1b
1869 stw r0,4(r3)
1870 stw r9,0(r3)
1871 blr
1872
1873
1874 .align 5
1875 .globl EXT(mach_absolute_time)
1876 LEXT(mach_absolute_time)
1877 1: mftbu r3
1878 mftb r4
1879 mftbu r0
1880 cmpw r0,r3
1881 bne- 1b
1882 blr
1883
1884 /*
1885 ** ml_sense_nmi()
1886 **
1887 */
1888 ; Force a line boundry here
1889 .align 5
1890 .globl EXT(ml_sense_nmi)
1891
1892 LEXT(ml_sense_nmi)
1893
1894 blr ; Leave...
1895
1896 /*
1897 ** ml_set_processor_speed()
1898 **
1899 */
1900 ; Force a line boundry here
1901 .align 5
1902 .globl EXT(ml_set_processor_speed)
1903
1904 LEXT(ml_set_processor_speed)
1905 mflr r0 ; Save the link register
1906 stwu r1, -(FM_ALIGN(4*4)+FM_SIZE)(r1) ; Make some space on the stack
1907 stw r28, FM_ARG0+0x00(r1) ; Save a register
1908 stw r29, FM_ARG0+0x04(r1) ; Save a register
1909 stw r30, FM_ARG0+0x08(r1) ; Save a register
1910 stw r31, FM_ARG0+0x0C(r1) ; Save a register
1911 stw r0, (FM_ALIGN(4*4)+FM_SIZE+FM_LR_SAVE)(r1) ; Save the return
1912
1913 mfsprg r31, 0 ; Get the per_proc_info
1914
1915 lwz r30, pfPowerModes(r31) ; Get the supported power modes
1916
1917 rlwinm. r0, r30, 0, pmDualPLLb, pmDualPLLb ; Is DualPLL supported?
1918 bne spsDPLL
1919
1920 rlwinm. r0, r30, 0, pmDFSb, pmDFSb ; Is DFS supported?
1921 bne spsDFS
1922
1923 rlwinm. r0, r30, 0, pmPowerTuneb, pmPowerTuneb ; Is PowerTune supported?
1924 bne spsPowerTune
1925
1926 b spsDone ; No supported power modes
1927
1928 spsDPLL:
1929 cmpli cr0, r3, 0 ; Turn off BTIC before low speed
1930 beq spsDPLL1
1931 mfspr r4, hid0 ; Get the current hid0 value
1932 rlwinm r4, r4, 0, btic+1, btic-1 ; Clear the BTIC bit
1933 sync
1934 mtspr hid0, r4 ; Set the new hid0 value
1935 isync
1936 sync
1937
1938 spsDPLL1:
1939 mfspr r4, hid1 ; Get the current PLL settings
1940 rlwimi r4, r3, 31-hid1ps, hid1ps, hid1ps ; Copy the PLL Select bit
1941 stw r4, pfHID1(r31) ; Save the new hid1 value
1942 mtspr hid1, r4 ; Select desired PLL
1943
1944 cmpli cr0, r3, 0 ; Restore BTIC after high speed
1945 bne spsDone
1946 lwz r4, pfHID0(r31) ; Load the hid0 value
1947 sync
1948 mtspr hid0, r4 ; Set the hid0 value
1949 isync
1950 sync
1951 b spsDone
1952
1953 spsDFS:
1954 cmplwi r3, 0 ; full speed?
1955 mfspr r3, hid1 ; Get the current HID1
1956 rlwinm r3, r3, 0, hid1dfs1+1, hid1dfs0-1 ; assume full speed, clear dfs bits
1957 beq spsDFS1
1958 oris r3, r3, hi16(hid1dfs1m) ; slow, set half speed dfs1 bit
1959
1960 spsDFS1:
1961 stw r3, pfHID1(r31) ; Save the new hid1 value
1962 sync
1963 mtspr hid1, r3 ; Set the new HID1
1964 sync
1965 isync
1966 b spsDone
1967
1968 spsPowerTune:
1969 rlwinm r28, r3, 31-dnap, dnap, dnap ; Shift the 1 bit to the dnap+32 bit
1970 rlwinm r3, r3, 2, 29, 29 ; Shift the 1 to a 4 and mask
1971 addi r3, r3, pfPowerTune0 ; Add in the pfPowerTune0 offset
1972 lwzx r29, r31, r3 ; Load the PowerTune number 0 or 1
1973
1974 sldi r28, r28, 32 ; Shift to the top half
1975 ld r3, pfHID0(r31) ; Load the saved hid0 value
1976 and r28, r28, r3 ; Save the dnap bit
1977 lis r4, hi16(dnapm) ; Make a mask for the dnap bit
1978 sldi r4, r4, 32 ; Shift to the top half
1979 andc r3, r3, r4 ; Clear the dnap bit
1980 or r28, r28, r3 ; Insert the dnap bit as needed for later
1981
1982 sync
1983 mtspr hid0, r3 ; Turn off dnap in hid0
1984 mfspr r3, hid0 ; Yes, this is silly, keep it here
1985 mfspr r3, hid0 ; Yes, this is a duplicate, keep it here
1986 mfspr r3, hid0 ; Yes, this is a duplicate, keep it here
1987 mfspr r3, hid0 ; Yes, this is a duplicate, keep it here
1988 mfspr r3, hid0 ; Yes, this is a duplicate, keep it here
1989 mfspr r3, hid0 ; Yes, this is a duplicate, keep it here
1990 isync ; Make sure it is set
1991
1992 lis r3, hi16(PowerTuneControlReg) ; Write zero to the PCR
1993 ori r3, r3, lo16(PowerTuneControlReg)
1994 li r4, 0
1995 li r5, 0
1996 bl _ml_scom_write
1997
1998 lis r3, hi16(PowerTuneControlReg) ; Write the PowerTune value to the PCR
1999 ori r3, r3, lo16(PowerTuneControlReg)
2000 li r4, 0
2001 mr r5, r29
2002 bl _ml_scom_write
2003
2004 rlwinm r29, r29, 13-6, 6, 7 ; Move to PSR speed location and isolate the requested speed
2005 spsPowerTuneLoop:
2006 lis r3, hi16(PowerTuneStatusReg) ; Read the status from the PSR
2007 ori r3, r3, lo16(PowerTuneStatusReg)
2008 li r4, 0
2009 bl _ml_scom_read
2010 srdi r5, r5, 32
2011 rlwinm r0, r5, 0, 6, 7 ; Isolate the current speed
2012 rlwimi r0, r5, 0, 2, 2 ; Copy in the change in progress bit
2013 cmpw r0, r29 ; Compare the requested and current speeds
2014 beq spsPowerTuneDone
2015 rlwinm. r0, r5, 0, 3, 3
2016 beq spsPowerTuneLoop
2017
2018 spsPowerTuneDone:
2019 sync
2020 mtspr hid0, r28 ; Turn on dnap in hid0 if needed
2021 mfspr r28, hid0 ; Yes, this is silly, keep it here
2022 mfspr r28, hid0 ; Yes, this is a duplicate, keep it here
2023 mfspr r28, hid0 ; Yes, this is a duplicate, keep it here
2024 mfspr r28, hid0 ; Yes, this is a duplicate, keep it here
2025 mfspr r28, hid0 ; Yes, this is a duplicate, keep it here
2026 mfspr r28, hid0 ; Yes, this is a duplicate, keep it here
2027 isync ; Make sure it is set
2028
2029 b spsDone
2030
2031 spsDone:
2032 lwz r0, (FM_ALIGN(4*4)+FM_SIZE+FM_LR_SAVE)(r1) ; Get the return
2033 lwz r28, FM_ARG0+0x00(r1) ; Restore a register
2034 lwz r29, FM_ARG0+0x04(r1) ; Restore a register
2035 lwz r30, FM_ARG0+0x08(r1) ; Restore a register
2036 lwz r31, FM_ARG0+0x0C(r1) ; Restore a register
2037 lwz r1, FM_BACKPTR(r1) ; Pop the stack
2038 mtlr r0
2039 blr
2040
2041 /*
2042 ** ml_set_processor_voltage()
2043 **
2044 */
2045 ; Force a line boundry here
2046 .align 5
2047 .globl EXT(ml_set_processor_voltage)
2048
2049 LEXT(ml_set_processor_voltage)
2050 mfsprg r5, 0 ; Get the per_proc_info
2051
2052 lwz r6, pfPowerModes(r5) ; Get the supported power modes
2053
2054 rlwinm. r0, r6, 0, pmDPLLVminb, pmDPLLVminb ; Is DPLL Vmin supported
2055 beq spvDone
2056
2057 mfspr r4, hid2 ; Get HID2 value
2058 rlwimi r4, r3, 31-hid2vmin, hid2vmin, hid2vmin ; Insert the voltage mode bit
2059 mtspr hid2, r4 ; Set the voltage mode
2060 sync ; Make sure it is done
2061
2062 spvDone:
2063 blr
2064
2065
2066 ;
2067 ; unsigned int ml_scom_write(unsigned int reg, unsigned long long data)
2068 ; 64-bit machines only
2069 ; returns status
2070 ;
2071
2072 .align 5
2073 .globl EXT(ml_scom_write)
2074
2075 LEXT(ml_scom_write)
2076
2077 rldicr r3,r3,8,47 ; Align register it correctly
2078 rldimi r5,r4,32,0 ; Merge the high part of data
2079 sync ; Clean up everything
2080
2081 mtspr scomd,r5 ; Stick in the data
2082 mtspr scomc,r3 ; Set write to register
2083 sync
2084 isync
2085
2086 mfspr r3,scomc ; Read back status
2087 blr ; leave....
2088
2089 ;
2090 ; unsigned int ml_read_scom(unsigned int reg, unsigned long long *data)
2091 ; 64-bit machines only
2092 ; returns status
2093 ; ASM Callers: data (r4) can be zero and the 64 bit data will be returned in r5
2094 ;
2095
2096 .align 5
2097 .globl EXT(ml_scom_read)
2098
2099 LEXT(ml_scom_read)
2100
2101 mfsprg r0,2 ; Get the feature flags
2102 rldicr r3,r3,8,47 ; Align register it correctly
2103 rlwinm r0,r0,pfSCOMFixUpb+1,31,31 ; Set shift if we need a fix me up
2104
2105 ori r3,r3,0x8000 ; Set to read data
2106 sync
2107
2108 mtspr scomc,r3 ; Request the register
2109 mfspr r5,scomd ; Get the register contents
2110 mfspr r3,scomc ; Get back the status
2111 sync
2112 isync
2113
2114 sld r5,r5,r0 ; Fix up if needed
2115
2116 cmplwi r4, 0 ; If data pointer is null, just return
2117 beqlr ; the received data in r5
2118 std r5,0(r4) ; Pass back the received data
2119 blr ; Leave...