2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 #include <ppc/proc_reg.h>
26 #include <mach/ppc/vm_param.h>
27 #include <ppc/exception.h>
31 * ml_set_physical() -- turn off DR and (if 64-bit) turn SF on
32 * it is assumed that pf64Bit is already in cr6
33 * ml_set_physical_get_ffs() -- turn DR off, SF on, and get feature flags
34 * ml_set_physical_disabled() -- turn DR and EE off, SF on, get feature flags
35 * ml_set_translation_off() -- turn DR, IR, and EE off, SF on, get feature flags
37 * Callable only from assembler, these return:
40 * r10 -- feature flags (pf64Bit etc, ie SPRG 2)
41 * cr6 -- feature flags 24-27, ie pf64Bit, pf128Byte, and pf32Byte
43 * Uses r0 and r2. ml_set_translation_off also uses r3 and cr5.
47 .globl EXT(ml_set_translation_off)
48 LEXT(ml_set_translation_off)
49 mfsprg r10,2 // get feature flags
51 mtcrf 0x02,r10 // move pf64Bit etc to cr6
52 ori r0,r0,lo16(MASK(MSR_EE)+MASK(MSR_FP)+MASK(MSR_IR)+MASK(MSR_DR)) // turn off all 4
54 oris r0,r0,hi16(MASK(MSR_VEC)) // Turn off vector too
55 mtcrf 0x04,r10 // move pfNoMSRir etc to cr5
56 andc r2,r11,r0 // turn off EE, IR, and DR
57 bt++ pf64Bitb,ml_set_physical_64 // skip if 64-bit (only they take the hint)
58 bf pfNoMSRirb,ml_set_physical_32 // skip if we can load MSR directly
59 li r0,loadMSR // Get the MSR setter SC
60 mr r3,r2 // copy new MSR to r2
65 .globl EXT(ml_set_physical_disabled)
67 LEXT(ml_set_physical_disabled)
69 mfsprg r10,2 // get feature flags
70 ori r0,r0,lo16(MASK(MSR_EE)) // turn EE and fp off
71 mtcrf 0x02,r10 // move pf64Bit etc to cr6
72 b ml_set_physical_join
75 .globl EXT(ml_set_physical_get_ffs)
77 LEXT(ml_set_physical_get_ffs)
78 mfsprg r10,2 // get feature flags
79 mtcrf 0x02,r10 // move pf64Bit etc to cr6
81 .globl EXT(ml_set_physical)
84 li r0,0 // do not turn off interrupts
87 oris r0,r0,hi16(MASK(MSR_VEC)) // Always gonna turn of vectors
89 ori r0,r0,lo16(MASK(MSR_DR)+MASK(MSR_FP)) // always turn off DR and FP bit
90 andc r2,r11,r0 // turn off DR and maybe EE
91 bt++ pf64Bitb,ml_set_physical_64 // skip if 64-bit (only they take the hint)
93 mtmsr r2 // turn off translation
98 li r0,1 // get a 1 to slam into SF
99 rldimi r2,r0,63,MSR_SF_BIT // set SF bit (bit 0)
100 mtmsrd r2 // set 64-bit mode, turn off data relocation
106 * ml_restore(old_MSR)
108 * Callable only from assembler, restores the MSR in r11 saved by ml_set_physical.
109 * We assume cr6 and r11 are as set by ml_set_physical, ie:
110 * cr6 - pf64Bit flag (feature flags 24-27)
115 .globl EXT(ml_restore)
118 bt++ pf64Bitb,ml_restore_64 // handle 64-bit cpus (only they take the hint)
119 mtmsr r11 // restore a 32-bit MSR
124 mtmsrd r11 // restore a 64-bit MSR
129 /* PCI config cycle probing
131 * boolean_t ml_probe_read(vm_offset_t paddr, unsigned int *val)
133 * Read the memory location at physical address paddr.
134 * This is a part of a device probe, so there is a good chance we will
135 * have a machine check here. So we have to be able to handle that.
136 * We assume that machine checks are enabled both in MSR and HIDs
139 ; Force a line boundry here
141 .globl EXT(ml_probe_read)
145 mfsprg r9,2 ; Get feature flags
147 rlwinm. r0,r9,0,pf64Bitb,pf64Bitb ; Are we on a 64-bit machine?
148 rlwinm r3,r3,0,0,31 ; Clean up for 64-bit machines
149 bne++ mpr64bit ; Go do this the 64-bit way...
151 mpr32bit: lis r8,hi16(MASK(MSR_VEC)) ; Get the vector flag
152 mfmsr r0 ; Save the current MSR
153 ori r8,r8,lo16(MASK(MSR_FP)) ; Add the FP flag
155 neg r10,r3 ; Number of bytes to end of page
156 andc r0,r0,r8 ; Clear VEC and FP
157 rlwinm. r10,r10,0,20,31 ; Clear excess junk and test for page bndry
158 ori r8,r8,lo16(MASK(MSR_EE)|MASK(MSR_IR)|MASK(MSR_DR)) ; Drop EE, IR, and DR
159 mr r12,r3 ; Save the load address
160 andc r2,r0,r8 ; Clear VEC, FP, and EE
161 mtcrf 0x04,r9 ; Set the features
162 cmplwi cr1,r10,4 ; At least 4 bytes left in page?
163 beq- mprdoit ; We are right on the boundary...
165 bltlr- cr1 ; No, just return failure...
169 bt pfNoMSRirb,mprNoMSR ; No MSR...
171 mtmsr r2 ; Translation and all off
172 isync ; Toss prefetch
177 li r0,loadMSR ; Get the MSR setter SC
178 mr r3,r2 ; Get new MSR
184 mfspr r6, hid0 ; Get a copy of hid0
186 rlwinm. r5, r9, 0, pfNoMuMMCKb, pfNoMuMMCKb ; Check for NoMuMMCK
189 rlwinm r5, r6, 0, ice+1, ice-1 ; Turn off L1 I-Cache
191 isync ; Wait for I-Cache off
192 rlwinm r5, r6, 0, mum+1, mum-1 ; Turn off MuM w/ I-Cache on
197 ; We need to insure that there is no more than 1 BAT register that
198 ; can get a hit. There could be repercussions beyond the ken
199 ; of mortal man. It is best not to tempt fate.
202 ; Note: we will reload these from the shadow BATs later
204 li r10,0 ; Clear a register
206 sync ; Make sure all is well
208 mtdbatu 1,r10 ; Invalidate DBAT 1
209 mtdbatu 2,r10 ; Invalidate DBAT 2
210 mtdbatu 3,r10 ; Invalidate DBAT 3
212 rlwinm r10,r12,0,0,14 ; Round down to a 128k boundary
213 ori r11,r10,0x32 ; Set uncached, coherent, R/W
214 ori r10,r10,2 ; Make the upper half (128k, valid supervisor)
215 mtdbatl 0,r11 ; Set lower BAT first
216 mtdbatu 0,r10 ; Now the upper
217 sync ; Just make sure
219 dcbf 0,r12 ; Make sure we kill the cache to avoid paradoxes
222 ori r11,r2,lo16(MASK(MSR_DR)) ; Turn on data translation
223 mtmsr r11 ; Do it for real
224 isync ; Make sure of it
226 eieio ; Make sure of all previous accesses
227 sync ; Make sure it is all caught up
229 lwz r11,0(r12) ; Get it and maybe machine check here
231 eieio ; Make sure of ordering again
232 sync ; Get caught up yet again
233 isync ; Do not go further till we are here
235 mtmsr r2 ; Turn translation back off
238 lis r10,hi16(EXT(shadow_BAT)+shdDBAT) ; Get shadow address
239 ori r10,r10,lo16(EXT(shadow_BAT)+shdDBAT) ; Get shadow address
241 lwz r5,0(r10) ; Pick up DBAT 0 high
242 lwz r6,4(r10) ; Pick up DBAT 0 low
243 lwz r7,8(r10) ; Pick up DBAT 1 high
244 lwz r8,16(r10) ; Pick up DBAT 2 high
245 lwz r9,24(r10) ; Pick up DBAT 3 high
247 mtdbatu 0,r5 ; Restore DBAT 0 high
248 mtdbatl 0,r6 ; Restore DBAT 0 low
249 mtdbatu 1,r7 ; Restore DBAT 1 high
250 mtdbatu 2,r8 ; Restore DBAT 2 high
251 mtdbatu 3,r9 ; Restore DBAT 3 high
256 mtmsr r0 ; Restore translation and exceptions
257 isync ; Toss speculations
259 stw r11,0(r4) ; Save the loaded value
262 ; Force a line boundry here. This means we will be able to check addresses better
264 .globl EXT(ml_probe_read_mck)
265 LEXT(ml_probe_read_mck)
268 /* PCI config cycle probing - 64-bit
270 * boolean_t ml_probe_read_64(addr64_t paddr, unsigned int *val)
272 * Read the memory location at physical address paddr.
273 * This is a part of a device probe, so there is a good chance we will
274 * have a machine check here. So we have to be able to handle that.
275 * We assume that machine checks are enabled both in MSR and HIDs
278 ; Force a line boundry here
280 .globl EXT(ml_probe_read_64)
282 LEXT(ml_probe_read_64)
284 mfsprg r9,2 ; Get feature flags
285 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
286 rlwinm. r0,r9,0,pf64Bitb,pf64Bitb ; Are we on a 64-bit machine?
287 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
289 mr r4,r5 ; Move result to common register
290 beq-- mpr32bit ; Go do this the 32-bit way...
292 mpr64bit: andi. r0,r3,3 ; Check if we are on a word boundary
293 li r0,0 ; Clear the EE bit (and everything else for that matter)
294 bne-- mprFail ; Boundary not good...
295 mfmsr r11 ; Get the MSR
296 mtmsrd r0,1 ; Set the EE bit only (do not care about RI)
297 rlwinm r11,r11,0,MSR_EE_BIT,MSR_EE_BIT ; Isolate just the EE bit
298 mfmsr r10 ; Refresh our view of the MSR (VMX/FP may have changed)
299 or r12,r10,r11 ; Turn on EE if on before we turned it off
300 ori r0,r0,lo16(MASK(MSR_IR)|MASK(MSR_DR)) ; Get the IR and DR bits
302 sldi r2,r2,63 ; Get the 64-bit bit
303 andc r10,r10,r0 ; Clear IR and DR
304 or r10,r10,r2 ; Set 64-bit
307 mtmsrd r10 ; Translation and EE off, 64-bit on
310 sldi r0,r0,32+8 ; Get the right bit to inhibit caching
312 mfspr r8,hid4 ; Get HID4
313 or r2,r8,r0 ; Set bit to make real accesses cache-inhibited
315 mtspr hid4,r2 ; Make real accesses cache-inhibited
316 isync ; Toss prefetches
318 lis r7,0xE000 ; Get the unlikeliest ESID possible
319 srdi r7,r7,1 ; Make 0x7FFFFFFFF0000000
320 slbie r7 ; Make sure the ERAT is cleared
325 eieio ; Make sure of all previous accesses
327 lwz r11,0(r3) ; Get it and maybe machine check here
329 eieio ; Make sure of ordering again
330 sync ; Get caught up yet again
331 isync ; Do not go further till we are here
334 mtspr hid4,r8 ; Make real accesses not cache-inhibited
335 isync ; Toss prefetches
337 lis r7,0xE000 ; Get the unlikeliest ESID possible
338 srdi r7,r7,1 ; Make 0x7FFFFFFFF0000000
339 slbie r7 ; Make sure the ERAT is cleared
341 mtmsrd r12 ; Restore entry MSR
344 stw r11,0(r4) ; Pass back the result
345 li r3,1 ; Indicate success
348 mprFail: li r3,0 ; Set failure
351 ; Force a line boundry here. This means we will be able to check addresses better
353 .globl EXT(ml_probe_read_mck_64)
354 LEXT(ml_probe_read_mck_64)
357 /* Read physical address byte
359 * unsigned int ml_phys_read_byte(vm_offset_t paddr)
360 * unsigned int ml_phys_read_byte_64(addr64_t paddr)
362 * Read the byte at physical address paddr. Memory should not be cache inhibited.
365 ; Force a line boundry here
368 .globl EXT(ml_phys_read_byte_64)
370 LEXT(ml_phys_read_byte_64)
372 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
373 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
374 b ml_phys_read_byte_join
376 .globl EXT(ml_phys_read_byte)
378 LEXT(ml_phys_read_byte)
379 rlwinm r3,r3,0,0,31 ; truncate address to 32-bits
380 ml_phys_read_byte_join: ; r3 = address to read (reg64_t)
381 mflr r11 ; Save the return
382 bl rdwrpre ; Get set up, translation/interrupts off, 64-bit on, etc.
384 lbz r3,0(r3) ; Get the byte
385 b rdwrpost ; Clean up and leave...
388 /* Read physical address half word
390 * unsigned int ml_phys_read_half(vm_offset_t paddr)
391 * unsigned int ml_phys_read_half_64(addr64_t paddr)
393 * Read the half word at physical address paddr. Memory should not be cache inhibited.
396 ; Force a line boundry here
399 .globl EXT(ml_phys_read_half_64)
401 LEXT(ml_phys_read_half_64)
403 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
404 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
405 b ml_phys_read_half_join
407 .globl EXT(ml_phys_read_half)
409 LEXT(ml_phys_read_half)
410 rlwinm r3,r3,0,0,31 ; truncate address to 32-bits
411 ml_phys_read_half_join: ; r3 = address to read (reg64_t)
412 mflr r11 ; Save the return
413 bl rdwrpre ; Get set up, translation/interrupts off, 64-bit on, etc.
415 lhz r3,0(r3) ; Get the half word
416 b rdwrpost ; Clean up and leave...
419 /* Read physical address word
421 * unsigned int ml_phys_read(vm_offset_t paddr)
422 * unsigned int ml_phys_read_64(addr64_t paddr)
423 * unsigned int ml_phys_read_word(vm_offset_t paddr)
424 * unsigned int ml_phys_read_word_64(addr64_t paddr)
426 * Read the word at physical address paddr. Memory should not be cache inhibited.
429 ; Force a line boundry here
432 .globl EXT(ml_phys_read_64)
433 .globl EXT(ml_phys_read_word_64)
435 LEXT(ml_phys_read_64)
436 LEXT(ml_phys_read_word_64)
438 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
439 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
440 b ml_phys_read_word_join
442 .globl EXT(ml_phys_read)
443 .globl EXT(ml_phys_read_word)
446 LEXT(ml_phys_read_word)
447 rlwinm r3,r3,0,0,31 ; truncate address to 32-bits
448 ml_phys_read_word_join: ; r3 = address to read (reg64_t)
449 mflr r11 ; Save the return
450 bl rdwrpre ; Get set up, translation/interrupts off, 64-bit on, etc.
452 lwz r3,0(r3) ; Get the word
453 b rdwrpost ; Clean up and leave...
456 /* Read physical address double word
458 * unsigned long long ml_phys_read_double(vm_offset_t paddr)
459 * unsigned long long ml_phys_read_double_64(addr64_t paddr)
461 * Read the double word at physical address paddr. Memory should not be cache inhibited.
464 ; Force a line boundry here
467 .globl EXT(ml_phys_read_double_64)
469 LEXT(ml_phys_read_double_64)
471 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
472 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
473 b ml_phys_read_double_join
475 .globl EXT(ml_phys_read_double)
477 LEXT(ml_phys_read_double)
478 rlwinm r3,r3,0,0,31 ; truncate address to 32-bits
479 ml_phys_read_double_join: ; r3 = address to read (reg64_t)
480 mflr r11 ; Save the return
481 bl rdwrpre ; Get set up, translation/interrupts off, 64-bit on, etc.
483 lwz r4,4(r3) ; Get the low word
484 lwz r3,0(r3) ; Get the high word
485 b rdwrpost ; Clean up and leave...
488 /* Write physical address byte
490 * void ml_phys_write_byte(vm_offset_t paddr, unsigned int data)
491 * void ml_phys_write_byte_64(addr64_t paddr, unsigned int data)
493 * Write the byte at physical address paddr. Memory should not be cache inhibited.
497 .globl EXT(ml_phys_write_byte_64)
499 LEXT(ml_phys_write_byte_64)
501 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
502 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
503 mr r4,r5 ; Copy over the data
504 b ml_phys_write_byte_join
506 .globl EXT(ml_phys_write_byte)
508 LEXT(ml_phys_write_byte)
509 rlwinm r3,r3,0,0,31 ; truncate address to 32-bits
510 ml_phys_write_byte_join: ; r3 = address to write (reg64_t), r4 = data
511 mflr r11 ; Save the return
512 bl rdwrpre ; Get set up, translation/interrupts off, 64-bit on, etc.
514 stb r4,0(r3) ; Set the byte
515 b rdwrpost ; Clean up and leave...
518 /* Write physical address half word
520 * void ml_phys_write_half(vm_offset_t paddr, unsigned int data)
521 * void ml_phys_write_half_64(addr64_t paddr, unsigned int data)
523 * Write the half word at physical address paddr. Memory should not be cache inhibited.
527 .globl EXT(ml_phys_write_half_64)
529 LEXT(ml_phys_write_half_64)
531 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
532 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
533 mr r4,r5 ; Copy over the data
534 b ml_phys_write_half_join
536 .globl EXT(ml_phys_write_half)
538 LEXT(ml_phys_write_half)
539 rlwinm r3,r3,0,0,31 ; truncate address to 32-bits
540 ml_phys_write_half_join: ; r3 = address to write (reg64_t), r4 = data
541 mflr r11 ; Save the return
542 bl rdwrpre ; Get set up, translation/interrupts off, 64-bit on, etc.
544 sth r4,0(r3) ; Set the half word
545 b rdwrpost ; Clean up and leave...
548 /* Write physical address word
550 * void ml_phys_write(vm_offset_t paddr, unsigned int data)
551 * void ml_phys_write_64(addr64_t paddr, unsigned int data)
552 * void ml_phys_write_word(vm_offset_t paddr, unsigned int data)
553 * void ml_phys_write_word_64(addr64_t paddr, unsigned int data)
555 * Write the word at physical address paddr. Memory should not be cache inhibited.
559 .globl EXT(ml_phys_write_64)
560 .globl EXT(ml_phys_write_word_64)
562 LEXT(ml_phys_write_64)
563 LEXT(ml_phys_write_word_64)
565 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
566 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
567 mr r4,r5 ; Copy over the data
568 b ml_phys_write_word_join
570 .globl EXT(ml_phys_write)
571 .globl EXT(ml_phys_write_word)
574 LEXT(ml_phys_write_word)
575 rlwinm r3,r3,0,0,31 ; truncate address to 32-bits
576 ml_phys_write_word_join: ; r3 = address to write (reg64_t), r4 = data
577 mflr r11 ; Save the return
578 bl rdwrpre ; Get set up, translation/interrupts off, 64-bit on, etc.
580 stw r4,0(r3) ; Set the word
581 b rdwrpost ; Clean up and leave...
584 /* Write physical address double word
586 * void ml_phys_write_double(vm_offset_t paddr, unsigned long long data)
587 * void ml_phys_write_double_64(addr64_t paddr, unsigned long long data)
589 * Write the double word at physical address paddr. Memory should not be cache inhibited.
593 .globl EXT(ml_phys_write_double_64)
595 LEXT(ml_phys_write_double_64)
597 rlwinm r3,r3,0,1,0 ; Copy low 32 bits to top 32
598 rlwimi r3,r4,0,0,31 ; Insert low part of 64-bit address in bottom 32 bits
599 mr r4,r5 ; Copy over the high data
600 mr r5,r6 ; Copy over the low data
601 b ml_phys_write_double_join
603 .globl EXT(ml_phys_write_double)
605 LEXT(ml_phys_write_double)
606 rlwinm r3,r3,0,0,31 ; truncate address to 32-bits
607 ml_phys_write_double_join: ; r3 = address to write (reg64_t), r4,r5 = data (long long)
608 mflr r11 ; Save the return
609 bl rdwrpre ; Get set up, translation/interrupts off, 64-bit on, etc.
611 stw r4,0(r3) ; Set the high word
612 stw r5,4(r3) ; Set the low word
613 b rdwrpost ; Clean up and leave...
618 rdwrpre: mfsprg r12,2 ; Get feature flags
619 lis r8,hi16(MASK(MSR_VEC)) ; Get the vector flag
620 mfmsr r10 ; Save the MSR
621 ori r8,r8,lo16(MASK(MSR_FP)) ; Add the FP flag
622 mtcrf 0x02,r12 ; move pf64Bit
623 andc r10,r10,r8 ; Clear VEC and FP
624 ori r9,r8,lo16(MASK(MSR_EE)|MASK(MSR_IR)|MASK(MSR_DR)) ; Drop EE, DR, and IR
625 li r2,1 ; Prepare for 64 bit
626 andc r9,r10,r9 ; Clear VEC, FP, DR, and EE
627 bf-- pf64Bitb,rdwrpre32 ; Join 32-bit code...
629 srdi r7,r3,31 ; Get a 1 if address is in I/O memory
630 rldimi r9,r2,63,MSR_SF_BIT ; set SF bit (bit 0)
631 cmpldi cr7,r7,1 ; Is source in I/O memory?
632 mtmsrd r9 ; set 64-bit mode, turn off EE, DR, and IR
635 sldi r0,r2,32+8 ; Get the right bit to turn off caching
637 bnelr++ cr7 ; We are not in the I/O area, all ready...
639 mfspr r8,hid4 ; Get HID4
640 or r2,r8,r0 ; Set bit to make real accesses cache-inhibited
642 mtspr hid4,r2 ; Make real accesses cache-inhibited
643 isync ; Toss prefetches
645 lis r7,0xE000 ; Get the unlikeliest ESID possible
646 srdi r7,r7,1 ; Make 0x7FFFFFFFF0000000
647 slbie r7 ; Make sure the ERAT is cleared
651 blr ; Finally, all ready...
655 rdwrpre32: rlwimi r9,r10,0,MSR_IR_BIT,MSR_IR_BIT ; Leave the IR bit unchanged
656 mtmsr r9 ; Drop EE, DR, and leave IR unchanged
658 blr ; All set up, leave...
662 rdwrpost: mtlr r11 ; Restore the return
663 bt++ pf64Bitb,rdwrpost64 ; Join 64-bit code...
665 mtmsr r10 ; Restore entry MSR (sans FP and VEC)
669 rdwrpost64: bne++ cr7,rdwrpcok ; Skip enabling real mode caching if we did not change it...
672 mtspr hid4,r8 ; Make real accesses not cache-inhibited
673 isync ; Toss prefetches
675 lis r7,0xE000 ; Get the unlikeliest ESID possible
676 srdi r7,r7,1 ; Make 0x7FFFFFFFF0000000
677 slbie r7 ; Make sure the ERAT is cleared
679 rdwrpcok: mtmsrd r10 ; Restore entry MSR (sans FP and VEC)
684 /* set interrupts enabled or disabled
686 * boolean_t set_interrupts_enabled(boolean_t enable)
688 * Set EE bit to "enable" and return old value as boolean
691 ; Force a line boundry here
693 .globl EXT(ml_set_interrupts_enabled)
695 LEXT(ml_set_interrupts_enabled)
697 andi. r4,r3,1 ; Are we turning interruptions on?
698 lis r0,hi16(MASK(MSR_VEC)) ; Get vector enable
699 mfmsr r5 ; Get the current MSR
700 ori r0,r0,lo16(MASK(MSR_EE)|MASK(MSR_FP)) ; Get float enable and EE enable
701 rlwinm r3,r5,17,31,31 ; Set return value
702 andc r5,r5,r0 ; Force VEC and FP off
703 bne CheckPreemption ; Interrupts going on, check ASTs...
705 mtmsr r5 ; Slam diable (always going disabled here)
706 isync ; Need this because FP/Vec might go off
712 mfsprg r9,1 ; Get current activation
713 lwz r7,ACT_PER_PROC(r9) ; Get the per_proc block
714 ori r5,r5,lo16(MASK(MSR_EE)) ; Turn on the enable
715 lwz r8,PP_PENDING_AST(r7) ; Get pending AST mask
716 li r6,AST_URGENT ; Get the type we will preempt for
717 lwz r7,ACT_PREEMPT_CNT(r9) ; Get preemption count
718 lis r0,hi16(DoPreemptCall) ; High part of Preempt FW call
719 cmpwi cr1,r7,0 ; Are preemptions masked off?
720 and. r8,r8,r6 ; Are we urgent?
721 crorc cr1_eq,cr0_eq,cr1_eq ; Remember if preemptions are masked or not urgent
722 ori r0,r0,lo16(DoPreemptCall) ; Bottome of FW call
724 mtmsr r5 ; Restore the MSR now, before we can preempt
725 isync ; Need this because FP/Vec might go off
727 beqlr++ cr1 ; Return if no premption...
731 ; Force a line boundry here
733 .globl EXT(timer_update)
736 stw r4,TIMER_HIGHCHK(r3)
740 stw r4,TIMER_HIGH(r3)
743 ; Force a line boundry here
745 .globl EXT(timer_grab)
748 0: lwz r11,TIMER_HIGH(r3)
751 lwz r9,TIMER_HIGHCHK(r3)
757 ; Force a line boundry here
759 .globl EXT(timer_event)
762 mfsprg r10,1 ; Get the current activation
763 lwz r10,ACT_PER_PROC(r10) ; Get the per_proc block
764 addi r10,r10,PP_PROCESSOR
765 lwz r11,CURRENT_TIMER(r10)
767 lwz r9,TIMER_LOW(r11)
768 lwz r2,TIMER_TSTAMP(r11)
774 lwz r6,TIMER_HIGH(r11)
776 stw r6,TIMER_HIGHCHK(r11)
778 stw r5,TIMER_LOW(r11)
780 stw r6,TIMER_HIGH(r11)
783 0: stw r5,TIMER_LOW(r11)
785 1: stw r4,CURRENT_TIMER(r10)
786 stw r3,TIMER_TSTAMP(r4)
789 /* Set machine into idle power-saving mode.
791 * void machine_idle(void)
793 * We will use the PPC NAP or DOZE for this.
794 * This call always returns. Must be called with spllo (i.e., interruptions
799 ; Force a line boundry here
801 .globl EXT(machine_idle)
805 mfsprg r12,1 ; Get the current activation
806 lwz r12,ACT_PER_PROC(r12) ; Get the per_proc block
807 lhz r10,PP_CPU_FLAGS(r12) ; Get the flags
808 lwz r11,PP_INTS_ENABLED(r12) ; Get interrupt enabled state
809 andi. r10,r10,SignalReady ; Are Signal ready?
810 cmpwi cr1,r11,0 ; Are interrupt disabled?
811 cror cr0_eq, cr1_eq, cr0_eq ; Interrupt disabled or Signal not ready?
812 mfmsr r3 ; Save the MSR
814 beq-- nonap ; Yes, return after re-enabling interrupts
815 lis r0,hi16(MASK(MSR_VEC)) ; Get the vector flag
816 ori r0,r0,lo16(MASK(MSR_FP)) ; Add the FP flag
817 andc r3,r3,r0 ; Clear VEC and FP
818 ori r0,r0,lo16(MASK(MSR_EE)) ; Drop EE also
819 andc r5,r3,r0 ; Clear VEC, FP, DR, and EE
821 mtmsr r5 ; Hold up interruptions for now
822 isync ; May have messed with fp/vec
823 mfsprg r11,2 ; Get CPU specific features
824 mfspr r6,hid0 ; Get the current power-saving mode
825 mtcrf 0xC7,r11 ; Get the facility flags
827 lis r4,hi16(napm) ; Assume we can nap
828 bt pfWillNapb,yesnap ; Yeah, nap is ok...
830 lis r4,hi16(dozem) ; Assume we can doze
831 bt pfCanDozeb,yesnap ; We can sleep or doze one this machine...
833 nonap: ori r3,r3,lo16(MASK(MSR_EE)) ; Flip on EE
835 mtmsr r3 ; Turn interruptions back on
838 yesnap: mftbu r9 ; Get the upper timebase
839 mftb r7 ; Get the lower timebase
840 mftbu r8 ; Get the upper one again
841 cmplw r9,r8 ; Did the top tick?
842 bne-- yesnap ; Yeah, need to get it again...
843 stw r8,napStamp(r12) ; Set high order time stamp
844 stw r7,napStamp+4(r12) ; Set low order nap stamp
846 rlwinm. r0,r11,0,pfAltivecb,pfAltivecb ; Do we have altivec?
847 beq-- minovec ; No...
848 dssall ; Stop the streams before we nap/doze
850 lwz r8,napStamp(r12) ; Reload high order time stamp
856 minovec: rlwinm. r7,r11,0,pfNoL2PFNapb,pfNoL2PFNapb ; Turn off L2 Prefetch before nap?
859 mfspr r7,msscr0 ; Get currect MSSCR0 value
860 rlwinm r7,r7,0,0,l2pfes-1 ; Disable L2 Prefetch
861 mtspr msscr0,r7 ; Updates MSSCR0 value
866 rlwinm. r7,r11,0,pfSlowNapb,pfSlowNapb ; Should nap at slow speed?
869 mfspr r7,hid1 ; Get current HID1 value
870 oris r7,r7,hi16(hid1psm) ; Select PLL1
871 mtspr hid1,r7 ; Update HID1 value
875 ; We have to open up interruptions here because book 4 says that we should
876 ; turn on only the POW bit and that we should have interrupts enabled.
877 ; The interrupt handler will detect that nap or doze is set if an interrupt
878 ; is taken and set everything up to return directly to machine_idle_ret.
879 ; So, make sure everything we need there is already set up...
883 lis r10,hi16(dozem|napm|sleepm) ; Mask of power management bits
885 bf-- pf64Bitb,mipNSF1 ; skip if 32-bit...
887 sldi r4,r4,32 ; Position the flags
888 sldi r10,r10,32 ; Position the masks
890 mipNSF1: li r2,lo16(MASK(MSR_DR)|MASK(MSR_IR)) ; Get the translation mask
891 andc r6,r6,r10 ; Clean up the old power bits
892 ori r7,r5,lo16(MASK(MSR_EE)) ; Flip on EE to make exit msr
893 andc r5,r5,r2 ; Clear IR and DR from current MSR
894 or r6,r6,r4 ; Set nap or doze
895 ori r5,r5,lo16(MASK(MSR_EE)) ; Flip on EE to make nap msr
896 oris r2,r5,hi16(MASK(MSR_POW)) ; Turn on power management in next MSR
899 mtspr hid0,r6 ; Set up the HID for nap/doze
900 mfspr r6,hid0 ; Yes, this is silly, keep it here
901 mfspr r6,hid0 ; Yes, this is a duplicate, keep it here
902 mfspr r6,hid0 ; Yes, this is a duplicate, keep it here
903 mfspr r6,hid0 ; Yes, this is a duplicate, keep it here
904 mfspr r6,hid0 ; Yes, this is a duplicate, keep it here
905 mfspr r6,hid0 ; Yes, this is a duplicate, keep it here
906 isync ; Make sure it is set
910 ; Turn translation off to nap
913 bt pfNoMSRirb,miNoMSR ; Jump if we need to use SC for this...
914 mtmsr r5 ; Turn translation off, interrupts on
916 b miNoMSRx ; Jump back in line...
918 miNoMSR: mr r3,r5 ; Pass in the new MSR value
919 li r0,loadMSR ; MSR setter ultrafast
920 sc ; Do it to it like you never done before...
922 miNoMSRx: bf-- pf64Bitb,mipowloop ; skip if 32-bit...
924 li r3,0x10 ; Fancy nap threshold is 0x10 ticks
925 mftb r8 ; Get the low half of the time base
926 mfdec r4 ; Get the decrementer ticks
927 cmplw r4,r3 ; Less than threshold?
930 mtdec r3 ; Load decrementer with threshold
931 isync ; and make sure,
932 mfdec r3 ; really sure, it gets there
934 rlwinm r6,r2,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Clear out the EE bit
935 sync ; Make sure queues are clear
936 mtmsr r6 ; Set MSR with EE off but POW on
937 isync ; Make sure this takes before we proceed
939 mftb r9 ; Get the low half of the time base
940 sub r9,r9,r8 ; Get the number of ticks spent waiting
941 sub r4,r4,r9 ; Adjust the decrementer value
943 mtdec r4 ; Load decrementer with the rest of the timeout
944 isync ; and make sure,
945 mfdec r4 ; really sure, it gets there
948 sync ; Make sure queues are clear
949 mtmsr r2 ; Nap or doze, MSR with POW, EE set, translation off
950 isync ; Make sure this takes before we proceed
951 b mipowloop ; loop if POW does not take
954 ; Note that the interrupt handler will turn off the nap/doze bits in the hid.
955 ; Also remember that the interrupt handler will force return to here whenever
956 ; the nap/doze bits are set.
958 .globl EXT(machine_idle_ret)
959 LEXT(machine_idle_ret)
960 mtmsr r7 ; Make sure the MSR is what we want
961 isync ; In case we turn on translation
963 ; Protect against a lost decrementer trap if the current decrementer value is negative
964 ; by more than 10 ticks, re-arm it since it is unlikely to fire at this point...
965 ; A hardware interrupt got us out of machine_idle and may also be contributing to this state
967 mfdec r6 ; Get decrementer
968 cmpwi cr0,r6,-10 ; Compare decrementer with -10
969 bgelr++ ; Return if greater
971 mtdec r0 ; Set decrementer to 1
974 /* Put machine to sleep.
975 * This call never returns. We always exit sleep via a soft reset.
976 * All external interruptions must be drained at this point and disabled.
978 * void ml_ppc_do_sleep(void)
980 * We will use the PPC SLEEP for this.
982 * There is one bit of hackery in here: we need to enable for
983 * interruptions when we go to sleep and there may be a pending
984 * decrimenter rupt. So we make the decrimenter 0x7FFFFFFF and enable for
985 * interruptions. The decrimenter rupt vector recognizes this and returns
986 * directly back here.
990 ; Force a line boundry here
992 .globl EXT(ml_ppc_sleep)
995 .globl EXT(ml_ppc_do_sleep)
996 LEXT(ml_ppc_do_sleep)
999 mfmsr r5 ; Hack to spin instead of sleep
1000 rlwinm r5,r5,0,MSR_DR_BIT+1,MSR_IR_BIT-1 ; Turn off translation
1001 rlwinm r5,r5,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Turn off interruptions
1002 mtmsr r5 ; No talking
1005 deadsleep: addi r3,r3,1 ; Make analyzer happy
1008 b deadsleep ; Die the death of 1000 joys...
1011 mfsprg r12,1 ; Get the current activation
1012 lwz r12,ACT_PER_PROC(r12) ; Get the per_proc block
1013 mfsprg r11,2 ; Get CPU specific features
1014 eqv r10,r10,r10 ; Get all foxes
1015 mtcrf 0x04,r11 ; move pfNoMSRirb to cr5
1016 mfspr r4,hid0 ; Get the current power-saving mode
1017 mtcrf 0x02,r11 ; move pf64Bit to cr6
1019 rlwinm. r5,r11,0,pfNoL2PFNapb,pfNoL2PFNapb ; Turn off L2 Prefetch before sleep?
1022 mfspr r5,msscr0 ; Get currect MSSCR0 value
1023 rlwinm r5,r5,0,0,l2pfes-1 ; Disable L2 Prefetch
1024 mtspr msscr0,r5 ; Updates MSSCR0 value
1029 bt++ pf64Bitb,mpsPF64bit ; PM bits are shifted on 64bit systems.
1031 rlwinm r4,r4,0,sleep+1,doze-1 ; Clear all possible power-saving modes (not DPM though)
1032 oris r4,r4,hi16(sleepm) ; Set sleep
1036 lis r5, hi16(dozem|napm|sleepm) ; Clear all possible power-saving modes (not DPM though)
1039 lis r5, hi16(napm) ; Set sleep
1044 mfmsr r5 ; Get the current MSR
1045 rlwinm r10,r10,0,1,31 ; Make 0x7FFFFFFF
1046 mtdec r10 ; Load decrimenter with 0x7FFFFFFF
1047 isync ; and make sure,
1048 mfdec r9 ; really sure, it gets there
1050 li r2,1 ; Prepare for 64 bit
1051 rlwinm r5,r5,0,MSR_DR_BIT+1,MSR_IR_BIT-1 ; Turn off translation
1053 ; Note that we need translation off before we set the HID to sleep. Otherwise
1054 ; we will ignore any PTE misses that occur and cause an infinite loop.
1056 bf++ pf64Bitb,mpsCheckMSR ; check 64-bit processor
1057 rldimi r5,r2,63,MSR_SF_BIT ; set SF bit (bit 0)
1058 mtmsrd r5 ; set 64-bit mode, turn off EE, DR, and IR
1059 isync ; Toss prefetch
1063 bt pfNoMSRirb,mpsNoMSR ; No MSR...
1065 mtmsr r5 ; Translation off
1066 isync ; Toss prefetch
1070 li r0,loadMSR ; Get the MSR setter SC
1071 mr r3,r5 ; Get new MSR
1075 ori r3,r5,lo16(MASK(MSR_EE)) ; Flip on EE
1077 mtspr hid0,r4 ; Set up the HID to sleep
1078 mfspr r4,hid0 ; Yes, this is silly, keep it here
1079 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1080 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1081 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1082 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1083 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1085 mtmsr r3 ; Enable for interrupts to drain decrimenter
1087 add r6,r4,r5 ; Just waste time
1088 add r6,r6,r4 ; A bit more
1089 add r6,r6,r5 ; A bit more
1091 mtmsr r5 ; Interruptions back off
1092 isync ; Toss prefetch
1095 ; We are here with translation off, interrupts off, all possible
1096 ; interruptions drained off, and a decrimenter that will not pop.
1099 bl EXT(cacheInit) ; Clear out the caches. This will leave them on
1100 bl EXT(cacheDisable) ; Turn off all caches
1102 mfmsr r5 ; Get the current MSR
1103 oris r5,r5,hi16(MASK(MSR_POW)) ; Turn on power management in next MSR
1104 ; Leave EE off because power goes off shortly
1105 mfsprg r12,0 ; Get the per_proc_info
1107 lhz r11,PP_CPU_FLAGS(r12) ; Get the flags
1108 ori r11,r11,SleepState ; Marked SleepState
1109 sth r11,PP_CPU_FLAGS(r12) ; Set the flags
1112 mfsprg r11,2 ; Get CPU specific features
1113 rlwinm. r0,r11,0,pf64Bitb,pf64Bitb ; Test for 64 bit processor
1114 eqv r4,r4,r4 ; Get all foxes
1115 rlwinm r4,r4,0,1,31 ; Make 0x7FFFFFFF
1116 beq slSleepNow ; skip if 32-bit...
1117 li r3, 0x4000 ; Cause decrimenter to roll over soon
1118 mtdec r3 ; Load decrimenter with 0x00004000
1119 isync ; and make sure,
1120 mfdec r3 ; really sure, it gets there
1123 sync ; Sync it all up
1124 mtmsr r5 ; Do sleep with interruptions enabled
1126 mtdec r4 ; Load decrimenter with 0x7FFFFFFF
1127 isync ; and make sure,
1128 mfdec r3 ; really sure, it gets there
1129 b slSleepNow ; Go back to sleep if we wake up...
1133 /* Initialize all caches including the TLBs
1135 * void cacheInit(void)
1137 * This is used to force the caches to an initial clean state. First, we
1138 * check if the cache is on, if so, we need to flush the contents to memory.
1139 * Then we invalidate the L1. Next, we configure and invalidate the L2 etc.
1140 * Finally we turn on all of the caches
1142 * Note that if translation is not disabled when this is called, the TLB will not
1143 * be completely clear after return.
1147 ; Force a line boundry here
1149 .globl EXT(cacheInit)
1153 mfsprg r12,0 ; Get the per_proc_info
1154 mfspr r9,hid0 ; Get the current power-saving mode
1156 mfsprg r11,2 ; Get CPU specific features
1157 mfmsr r7 ; Get the current MSR
1158 rlwinm r7,r7,0,MSR_FP_BIT+1,MSR_FP_BIT-1 ; Force floating point off
1159 rlwinm r7,r7,0,MSR_VEC_BIT+1,MSR_VEC_BIT-1 ; Force vectors off
1160 rlwimi r11,r11,pfLClckb+1,31,31 ; Move pfLClck to another position (to keep from using non-volatile CRs)
1161 rlwinm r5,r7,0,MSR_DR_BIT+1,MSR_IR_BIT-1 ; Turn off translation
1162 rlwinm r5,r5,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Turn off interruptions
1163 mtcrf 0x87,r11 ; Get the feature flags
1164 lis r10,hi16(dozem|napm|sleepm|dpmm) ; Mask of power management bits
1165 bf-- pf64Bitb,cIniNSF1 ; Skip if 32-bit...
1167 sldi r10,r10,32 ; Position the masks
1169 cIniNSF1: andc r4,r9,r10 ; Clean up the old power bits
1170 mtspr hid0,r4 ; Set up the HID
1171 mfspr r4,hid0 ; Yes, this is silly, keep it here
1172 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1173 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1174 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1175 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1176 mfspr r4,hid0 ; Yes, this is a duplicate, keep it here
1178 bt pfNoMSRirb,ciNoMSR ; No MSR...
1180 mtmsr r5 ; Translation and all off
1181 isync ; Toss prefetch
1185 li r0,loadMSR ; Get the MSR setter SC
1186 mr r3,r5 ; Get new MSR
1190 bf pfAltivecb,cinoDSS ; No Altivec here...
1192 dssall ; Stop streams
1195 cinoDSS: li r5,tlbieLock ; Get the TLBIE lock
1196 li r0,128 ; Get number of TLB entries
1198 li r6,0 ; Start at 0
1199 bf-- pf64Bitb,citlbhang ; Skip if 32-bit...
1200 li r0,1024 ; Get the number of TLB entries
1202 citlbhang: lwarx r2,0,r5 ; Get the TLBIE lock
1203 mr. r2,r2 ; Is it locked?
1204 bne- citlbhang ; It is locked, go wait...
1205 stwcx. r0,0,r5 ; Try to get it
1206 bne- citlbhang ; We was beat...
1208 mtctr r0 ; Set the CTR
1210 cipurgeTLB: tlbie r6 ; Purge this entry
1211 addi r6,r6,4096 ; Next page
1212 bdnz cipurgeTLB ; Do them all...
1214 mtcrf 0x80,r11 ; Set SMP capability
1215 sync ; Make sure all TLB purges are done
1216 eieio ; Order, order in the court
1218 bf pfSMPcapb,cinoSMP ; SMP incapable...
1220 tlbsync ; Sync all TLBs
1224 bf-- pf64Bitb,cinoSMP ; Skip if 32-bit...
1225 ptesync ; Wait for quiet again
1228 cinoSMP: stw r2,tlbieLock(0) ; Unlock TLBIE lock
1230 bt++ pf64Bitb,cin64 ; Skip if 64-bit...
1232 rlwinm. r0,r9,0,ice,dce ; Were either of the level 1s on?
1233 beq- cinoL1 ; No, no need to flush...
1235 rlwinm. r0,r11,0,pfL1fab,pfL1fab ; do we have L1 flush assist?
1236 beq ciswdl1 ; If no hw flush assist, go do by software...
1238 mfspr r8,msscr0 ; Get the memory system control register
1239 oris r8,r8,hi16(dl1hwfm) ; Turn on the hardware flush request
1241 mtspr msscr0,r8 ; Start the flush operation
1243 ciwdl1f: mfspr r8,msscr0 ; Get the control register again
1245 rlwinm. r8,r8,0,dl1hwf,dl1hwf ; Has the flush request been reset yet?
1246 bne ciwdl1f ; No, flush is still in progress...
1247 b ciinvdl1 ; Go invalidate l1...
1250 ; We need to either make this very complicated or to use ROM for
1251 ; the flush. The problem is that if during the following sequence a
1252 ; snoop occurs that invalidates one of the lines in the cache, the
1253 ; PLRU sequence will be altered making it possible to miss lines
1254 ; during the flush. So, we either need to dedicate an area of RAM
1255 ; to each processor, lock use of a RAM area, or use ROM. ROM is
1256 ; by far the easiest. Note that this is not an issue for machines
1257 ; that have harware flush assists.
1260 ciswdl1: lwz r0,pfl1dSize(r12) ; Get the level 1 cache size
1262 bf 31,cisnlck ; Skip if pfLClck not set...
1265 rlwinm r6,r4,0,0,l2pfes-1 ; ?
1266 mtspr msscr0,r6 ; Set it
1270 mfspr r8,ldstcr ; Save the LDSTCR
1271 li r2,1 ; Get a mask of 0x01
1272 lis r3,0xFFF0 ; Point to ROM
1273 rlwinm r11,r0,29,3,31 ; Get the amount of memory to handle all indexes
1275 li r6,0 ; Start here
1277 cisiniflsh: dcbf r6,r3 ; Flush each line of the range we use
1278 addi r6,r6,32 ; Bump to the next
1279 cmplw r6,r0 ; Have we reached the end?
1280 blt+ cisiniflsh ; Nope, continue initial flush...
1282 sync ; Make sure it is done
1284 addi r11,r11,-1 ; Get mask for index wrap
1285 li r6,0 ; Get starting offset
1287 cislckit: not r5,r2 ; Lock all but 1 way
1288 rlwimi r5,r8,0,0,23 ; Build LDSTCR
1289 mtspr ldstcr,r5 ; Lock a way
1290 sync ; Clear out memory accesses
1291 isync ; Wait for all
1294 cistouch: lwzx r10,r3,r6 ; Pick up some trash
1295 addi r6,r6,32 ; Go to the next index
1296 and. r0,r6,r11 ; See if we are about to do next index
1297 bne+ cistouch ; Nope, do more...
1299 sync ; Make sure it is all done
1302 sub r6,r6,r11 ; Back up to start + 1
1303 addi r6,r6,-1 ; Get it right
1305 cisflush: dcbf r3,r6 ; Flush everything out
1306 addi r6,r6,32 ; Go to the next index
1307 and. r0,r6,r11 ; See if we are about to do next index
1308 bne+ cisflush ; Nope, do more...
1310 sync ; Make sure it is all done
1314 rlwinm. r2,r2,1,24,31 ; Shift to next way
1315 bne+ cislckit ; Do this for all ways...
1317 mtspr ldstcr,r8 ; Slam back to original
1325 b cinoL1 ; Go on to level 2...
1328 cisnlck: rlwinm r2,r0,0,1,30 ; Double cache size
1329 add r0,r0,r2 ; Get 3 times cache size
1330 rlwinm r0,r0,26,6,31 ; Get 3/2 number of cache lines
1331 lis r3,0xFFF0 ; Dead recon ROM address for now
1332 mtctr r0 ; Number of lines to flush
1334 ciswfldl1a: lwz r2,0(r3) ; Flush anything else
1335 addi r3,r3,32 ; Next line
1336 bdnz ciswfldl1a ; Flush the lot...
1338 ciinvdl1: sync ; Make sure all flushes have been committed
1340 mfspr r8,hid0 ; Get the HID0 bits
1341 rlwinm r8,r8,0,dce+1,ice-1 ; Clear cache enables
1342 mtspr hid0,r8 ; and turn off L1 cache
1343 sync ; Make sure all is done
1346 ori r8,r8,lo16(icem|dcem|icfim|dcfim) ; Set the HID0 bits for enable, and invalidate
1350 mtspr hid0,r8 ; Start the invalidate and turn on cache
1351 rlwinm r8,r8,0,dcfi+1,icfi-1 ; Turn off the invalidate bits
1352 mtspr hid0,r8 ; Turn off the invalidate (needed for some older machines)
1358 ; Flush and disable the level 2
1360 mfsprg r10,2 ; need to check 2 features we did not put in CR
1361 rlwinm. r0,r10,0,pfL2b,pfL2b ; do we have L2?
1362 beq cinol2 ; No level 2 cache to flush
1364 mfspr r8,l2cr ; Get the L2CR
1365 lwz r3,pfl2cr(r12) ; Get the L2CR value
1366 rlwinm. r0,r8,0,l2e,l2e ; Was the L2 enabled?
1367 bne ciflushl2 ; Yes, force flush
1368 cmplwi r8, 0 ; Was the L2 all the way off?
1369 beq ciinvdl2 ; Yes, force invalidate
1370 lis r0,hi16(l2sizm|l2clkm|l2ramm|l2ohm) ; Get confiuration bits
1371 xor r2,r8,r3 ; Get changing bits?
1372 ori r0,r0,lo16(l2slm|l2dfm|l2bypm) ; More config bits
1373 and. r0,r0,r2 ; Did any change?
1374 bne- ciinvdl2 ; Yes, just invalidate and get PLL synced...
1377 rlwinm. r0,r10,0,pfL2fab,pfL2fab ; hardware-assisted L2 flush?
1378 beq ciswfl2 ; Flush not in hardware...
1380 mr r10,r8 ; Take a copy now
1382 bf 31,cinol2lck ; Skip if pfLClck not set...
1384 oris r10,r10,hi16(l2ionlym|l2donlym) ; Set both instruction- and data-only
1386 mtspr l2cr,r10 ; Lock out the cache
1390 cinol2lck: ori r10,r10,lo16(l2hwfm) ; Request flush
1391 sync ; Make sure everything is done
1393 mtspr l2cr,r10 ; Request flush
1395 cihwfl2: mfspr r10,l2cr ; Get back the L2CR
1396 rlwinm. r10,r10,0,l2hwf,l2hwf ; Is the flush over?
1397 bne+ cihwfl2 ; Nope, keep going...
1398 b ciinvdl2 ; Flush done, go invalidate L2...
1401 lwz r0,pfl2Size(r12) ; Get the L2 size
1402 oris r2,r8,hi16(l2dom) ; Set L2 to data only mode
1404 b ciswfl2doa ; Branch to next line...
1408 mtspr l2cr,r2 ; Disable L2
1411 b ciswfl2dod ; It is off, go invalidate it...
1414 b ciswfl2dob ; Branch to next...
1417 sync ; Finish memory stuff
1418 isync ; Stop speculation
1419 b ciswfl2doc ; Jump back up and turn on data only...
1421 rlwinm r0,r0,27,5,31 ; Get the number of lines
1422 lis r10,0xFFF0 ; Dead recon ROM for now
1423 mtctr r0 ; Set the number of lines
1425 ciswfldl2a: lwz r0,0(r10) ; Load something to flush something
1426 addi r10,r10,32 ; Next line
1427 bdnz ciswfldl2a ; Do the lot...
1429 ciinvdl2: rlwinm r8,r3,0,l2e+1,31 ; Clear the enable bit
1430 b cinla ; Branch to next line...
1433 cinlc: mtspr l2cr,r8 ; Disable L2
1436 b ciinvl2 ; It is off, go invalidate it...
1438 cinla: b cinlb ; Branch to next...
1440 cinlb: sync ; Finish memory stuff
1441 isync ; Stop speculation
1442 b cinlc ; Jump back up and turn off cache...
1447 cmplwi r3, 0 ; Should the L2 be all the way off?
1448 beq cinol2 ; Yes, done with L2
1450 oris r2,r8,hi16(l2im) ; Get the invalidate flag set
1452 mtspr l2cr,r2 ; Start the invalidate
1455 ciinvdl2a: mfspr r2,l2cr ; Get the L2CR
1456 mfsprg r0,2 ; need to check a feature in "non-volatile" set
1457 rlwinm. r0,r0,0,pfL2ib,pfL2ib ; flush in HW?
1458 beq ciinvdl2b ; Flush not in hardware...
1459 rlwinm. r2,r2,0,l2i,l2i ; Is the invalidate still going?
1460 bne+ ciinvdl2a ; Assume so, this will take a looong time...
1462 b cinol2 ; No level 2 cache to flush
1464 rlwinm. r2,r2,0,l2ip,l2ip ; Is the invalidate still going?
1465 bne+ ciinvdl2a ; Assume so, this will take a looong time...
1467 mtspr l2cr,r8 ; Turn off the invalidate request
1472 ; Flush and enable the level 3
1474 bf pfL3b,cinol3 ; No level 3 cache to flush
1476 mfspr r8,l3cr ; Get the L3CR
1477 lwz r3,pfl3cr(r12) ; Get the L3CR value
1478 rlwinm. r0,r8,0,l3e,l3e ; Was the L3 enabled?
1479 bne ciflushl3 ; Yes, force flush
1480 cmplwi r8, 0 ; Was the L3 all the way off?
1481 beq ciinvdl3 ; Yes, force invalidate
1482 lis r0,hi16(l3pem|l3sizm|l3dxm|l3clkm|l3spom|l3ckspm) ; Get configuration bits
1483 xor r2,r8,r3 ; Get changing bits?
1484 ori r0,r0,lo16(l3pspm|l3repm|l3rtm|l3cyam|l3dmemm|l3dmsizm) ; More config bits
1485 and. r0,r0,r2 ; Did any change?
1486 bne- ciinvdl3 ; Yes, just invalidate and get PLL synced...
1489 sync ; 7450 book says do this even though not needed
1490 mr r10,r8 ; Take a copy now
1492 bf 31,cinol3lck ; Skip if pfL23lck not set...
1494 oris r10,r10,hi16(l3iom) ; Set instruction-only
1495 ori r10,r10,lo16(l3donlym) ; Set data-only
1497 mtspr l3cr,r10 ; Lock out the cache
1501 cinol3lck: ori r10,r10,lo16(l3hwfm) ; Request flush
1502 sync ; Make sure everything is done
1504 mtspr l3cr,r10 ; Request flush
1506 cihwfl3: mfspr r10,l3cr ; Get back the L3CR
1507 rlwinm. r10,r10,0,l3hwf,l3hwf ; Is the flush over?
1508 bne+ cihwfl3 ; Nope, keep going...
1510 ciinvdl3: rlwinm r8,r3,0,l3e+1,31 ; Clear the enable bit
1511 sync ; Make sure of life, liberty, and justice
1512 mtspr l3cr,r8 ; Disable L3
1515 cmplwi r3, 0 ; Should the L3 be all the way off?
1516 beq cinol3 ; Yes, done with L3
1518 ori r8,r8,lo16(l3im) ; Get the invalidate flag set
1520 mtspr l3cr,r8 ; Start the invalidate
1522 ciinvdl3b: mfspr r8,l3cr ; Get the L3CR
1523 rlwinm. r8,r8,0,l3i,l3i ; Is the invalidate still going?
1524 bne+ ciinvdl3b ; Assume so...
1527 lwz r10, pfBootConfig(r12) ; ?
1528 rlwinm. r10, r10, 24, 28, 31 ; ?
1529 beq ciinvdl3nopdet ; ?
1533 rlwimi r2, r8, 0, 24, 31 ; ?
1534 subfic r10, r10, 32 ; ?
1536 ori r2, r2, 0x0080 ; ?
1539 mtspr l3pdet, r8 ; ?
1543 mfspr r8,l3cr ; Get the L3CR
1544 rlwinm r8,r8,0,l3clken+1,l3clken-1 ; Clear the clock enable bit
1545 mtspr l3cr,r8 ; Disable the clock
1548 ciinvdl3c: addi r2,r2,-1 ; ?
1552 mfspr r10,msssr0 ; ?
1553 rlwinm r10,r10,0,vgL3TAG+1,vgL3TAG-1 ; ?
1554 mtspr msssr0,r10 ; ?
1557 mtspr l3cr,r3 ; Enable it as desired
1560 mfsprg r0,2 ; need to check a feature in "non-volatile" set
1561 rlwinm. r0,r0,0,pfL2b,pfL2b ; is there an L2 cache?
1562 beq cinol2a ; No level 2 cache to enable
1564 lwz r3,pfl2cr(r12) ; Get the L2CR value
1565 cmplwi r3, 0 ; Should the L2 be all the way off?
1566 beq cinol2a : Yes, done with L2
1567 mtspr l2cr,r3 ; Enable it as desired
1571 ; Invalidate and turn on L1s
1575 bt 31,cinoexit ; Skip if pfLClck set...
1577 rlwinm r8,r9,0,dce+1,ice-1 ; Clear the I- and D- cache enables
1578 mtspr hid0,r8 ; Turn off dem caches
1581 ori r8,r9,lo16(icem|dcem|icfim|dcfim) ; Set the HID0 bits for enable, and invalidate
1582 rlwinm r9,r8,0,dcfi+1,icfi-1 ; Turn off the invalidate bits
1586 mtspr hid0,r8 ; Start the invalidate and turn on L1 cache
1588 cinoexit: mtspr hid0,r9 ; Turn off the invalidate (needed for some older machines) and restore entry conditions
1590 mtmsr r7 ; Restore MSR to entry
1596 ; Handle 64-bit architecture
1597 ; This processor can not run without caches, so we just push everything out
1598 ; and flush. It will be relativily clean afterwards
1604 mfspr r10,hid1 ; Save hid1
1605 mfspr r4,hid4 ; Save hid4
1606 mr r12,r10 ; Really save hid1
1607 mr r11,r4 ; Get a working copy of hid4
1610 eqv r2,r2,r2 ; Get all foxes
1612 rldimi r10,r0,55,7 ; Clear I$ prefetch bits (7:8)
1615 mtspr hid1,r10 ; Stick it
1616 mtspr hid1,r10 ; Stick it again
1619 rldimi r11,r2,38,25 ; Disable D$ prefetch (25:25)
1622 mtspr hid4,r11 ; Stick it
1625 li r3,8 ; Set bit 28+32
1626 sldi r3,r3,32 ; Make it bit 28
1627 or r3,r3,r11 ; Turn on the flash invalidate L1D$
1629 oris r5,r11,0x0600 ; Set disable L1D$ bits
1631 mtspr hid4,r3 ; Invalidate
1634 mtspr hid4,r5 ; Un-invalidate and disable L1D$
1637 lis r8,GUSModeReg ; Get the GUS mode ring address
1638 mfsprg r0,2 ; Get the feature flags
1639 ori r8,r8,0x8000 ; Set to read data
1640 rlwinm. r0,r0,pfSCOMFixUpb+1,31,31 ; Set shift if we need a fix me up
1644 mtspr scomc,r8 ; Request the GUS mode
1645 mfspr r11,scomd ; Get the GUS mode
1646 mfspr r8,scomc ; Get back the status (we just ignore it)
1650 sld r11,r11,r0 ; Fix up if needed
1652 ori r6,r11,lo16(GUSMdmapen) ; Set the bit that means direct L2 cache address
1653 lis r8,GUSModeReg ; Get GUS mode register address
1657 mtspr scomd,r6 ; Set that we want direct L2 mode
1658 mtspr scomc,r8 ; Tell GUS we want direct L2 mode
1659 mfspr r3,scomc ; Get back the status
1663 li r3,0 ; Clear start point
1665 cflushlp: lis r6,0x0040 ; Pick 4MB line as our target
1666 or r6,r6,r3 ; Put in the line offset
1667 lwz r5,0(r6) ; Load a line
1668 addis r6,r6,8 ; Roll bit 42:44
1669 lwz r5,0(r6) ; Load a line
1670 addis r6,r6,8 ; Roll bit 42:44
1671 lwz r5,0(r6) ; Load a line
1672 addis r6,r6,8 ; Roll bit 42:44
1673 lwz r5,0(r6) ; Load a line
1674 addis r6,r6,8 ; Roll bit 42:44
1675 lwz r5,0(r6) ; Load a line
1676 addis r6,r6,8 ; Roll bit 42:44
1677 lwz r5,0(r6) ; Load a line
1678 addis r6,r6,8 ; Roll bit 42:44
1679 lwz r5,0(r6) ; Load a line
1680 addis r6,r6,8 ; Roll bit 42:44
1681 lwz r5,0(r6) ; Load a line
1683 addi r3,r3,128 ; Next line
1684 andis. r5,r3,8 ; Have we done enough?
1685 beq++ cflushlp ; Not yet...
1689 lis r6,0x0040 ; Pick 4MB line as our target
1691 cflushx: dcbf 0,r6 ; Flush line and invalidate
1692 addi r6,r6,128 ; Next line
1693 andis. r5,r6,0x0080 ; Have we done enough?
1694 beq++ cflushx ; Keep on flushing...
1696 mr r3,r10 ; Copy current hid1
1697 rldimi r3,r2,54,9 ; Set force icbi match mode
1699 li r6,0 ; Set start if ICBI range
1701 mtspr hid1,r3 ; Stick it
1702 mtspr hid1,r3 ; Stick it again
1705 cflicbi: icbi 0,r6 ; Kill I$
1706 addi r6,r6,128 ; Next line
1707 andis. r5,r6,1 ; Have we done them all?
1708 beq++ cflicbi ; Not yet...
1710 lis r8,GUSModeReg ; Get GUS mode register address
1714 mtspr scomd,r11 ; Set that we do not want direct mode
1715 mtspr scomc,r8 ; Tell GUS we do not want direct mode
1716 mfspr r3,scomc ; Get back the status
1721 mtspr hid0,r9 ; Restore entry hid0
1722 mfspr r9,hid0 ; Yes, this is silly, keep it here
1723 mfspr r9,hid0 ; Yes, this is a duplicate, keep it here
1724 mfspr r9,hid0 ; Yes, this is a duplicate, keep it here
1725 mfspr r9,hid0 ; Yes, this is a duplicate, keep it here
1726 mfspr r9,hid0 ; Yes, this is a duplicate, keep it here
1727 mfspr r9,hid0 ; Yes, this is a duplicate, keep it here
1731 mtspr hid1,r12 ; Restore entry hid1
1732 mtspr hid1,r12 ; Stick it again
1736 mtspr hid4,r4 ; Restore entry hid4
1740 mtmsr r7 ; Restore MSR to entry
1746 /* Disables all caches
1748 * void cacheDisable(void)
1750 * Turns off all caches on the processor. They are not flushed.
1754 ; Force a line boundry here
1756 .globl EXT(cacheDisable)
1760 mfsprg r11,2 ; Get CPU specific features
1761 mtcrf 0x83,r11 ; Set feature flags
1763 bf pfAltivecb,cdNoAlt ; No vectors...
1765 dssall ; Stop streams
1769 btlr pf64Bitb ; No way to disable a 64-bit machine...
1771 mfspr r5,hid0 ; Get the hid
1772 rlwinm r5,r5,0,dce+1,ice-1 ; Clear the I- and D- cache enables
1773 mtspr hid0,r5 ; Turn off dem caches
1776 rlwinm. r0,r11,0,pfL2b,pfL2b ; is there an L2?
1777 beq cdNoL2 ; Skip if no L2...
1779 mfspr r5,l2cr ; Get the L2
1780 rlwinm r5,r5,0,l2e+1,31 ; Turn off enable bit
1782 b cinlaa ; Branch to next line...
1785 cinlcc: mtspr l2cr,r5 ; Disable L2
1788 b cdNoL2 ; It is off, we are done...
1790 cinlaa: b cinlbb ; Branch to next...
1792 cinlbb: sync ; Finish memory stuff
1793 isync ; Stop speculation
1794 b cinlcc ; Jump back up and turn off cache...
1798 bf pfL3b,cdNoL3 ; Skip down if no L3...
1800 mfspr r5,l3cr ; Get the L3
1801 rlwinm r5,r5,0,l3e+1,31 ; Turn off enable bit
1802 rlwinm r5,r5,0,l3clken+1,l3clken-1 ; Turn off cache enable bit
1803 mtspr l3cr,r5 ; Disable the caches
1810 /* Initialize processor thermal monitoring
1811 * void ml_thrm_init(void)
1813 * Obsolete, deprecated and will be removed.
1816 ; Force a line boundry here
1818 .globl EXT(ml_thrm_init)
1823 /* Set thermal monitor bounds
1824 * void ml_thrm_set(unsigned int low, unsigned int high)
1826 * Obsolete, deprecated and will be removed.
1829 ; Force a line boundry here
1831 .globl EXT(ml_thrm_set)
1836 /* Read processor temprature
1837 * unsigned int ml_read_temp(void)
1839 * Obsolete, deprecated and will be removed.
1842 ; Force a line boundry here
1844 .globl EXT(ml_read_temp)
1850 /* Throttle processor speed up or down
1851 * unsigned int ml_throttle(unsigned int step)
1853 * Returns old speed and sets new. Both step and return are values from 0 to
1854 * 255 that define number of throttle steps, 0 being off and "ictcfim" is max * 2.
1856 * Obsolete, deprecated and will be removed.
1859 ; Force a line boundry here
1861 .globl EXT(ml_throttle)
1868 ** ml_get_timebase()
1870 ** Entry - R3 contains pointer to 64 bit structure.
1872 ** Exit - 64 bit structure filled in.
1875 ; Force a line boundry here
1877 .globl EXT(ml_get_timebase)
1879 LEXT(ml_get_timebase)
1894 * unsigned int cpu_number(void)
1896 * Returns the current cpu number.
1900 .globl EXT(cpu_number)
1903 mfsprg r4,1 ; Get the current activation
1904 lwz r4,ACT_PER_PROC(r4) ; Get the per_proc block
1905 lhz r3,PP_CPU_NUMBER(r4) ; Get CPU number
1909 * processor_t current_processor(void)
1911 * Returns the current processor.
1915 .globl EXT(current_processor)
1917 LEXT(current_processor)
1918 mfsprg r3,1 ; Get the current activation
1919 lwz r3,ACT_PER_PROC(r3) ; Get the per_proc block
1920 addi r3,r3,PP_PROCESSOR
1923 #if PROCESSOR_SIZE > PP_PROCESSOR_SIZE
1924 #error processor overflows per_proc
1928 * ast_t *ast_pending(void)
1930 * Returns the address of the pending AST mask for the current processor.
1934 .globl EXT(ast_pending)
1937 mfsprg r3,1 ; Get the current activation
1938 lwz r3,ACT_PER_PROC(r3) ; Get the per_proc block
1939 addi r3,r3,PP_PENDING_AST
1943 * void machine_set_current_thread(thread_t)
1945 * Set the current thread
1948 .globl EXT(machine_set_current_thread)
1950 LEXT(machine_set_current_thread)
1952 mfsprg r4,1 ; Get spr1
1953 lwz r5,ACT_PER_PROC(r4) ; Get the PerProc from the previous active thread
1954 stw r5,ACT_PER_PROC(r3) ; Set the PerProc in the active thread
1955 mtsprg 1,r3 ; Set spr1 with the active thread
1959 * thread_t current_thread(void)
1960 * thread_t current_act(void)
1963 * Return the current thread for outside components.
1966 .globl EXT(current_thread)
1967 .globl EXT(current_act)
1969 LEXT(current_thread)
1976 .globl EXT(clock_get_uptime)
1977 LEXT(clock_get_uptime)
1989 .globl EXT(mach_absolute_time)
1990 LEXT(mach_absolute_time)
2002 ; Force a line boundry here
2004 .globl EXT(ml_sense_nmi)
2011 ** ml_set_processor_speed_powertune()
2014 ; Force a line boundry here
2016 .globl EXT(ml_set_processor_speed_powertune)
2018 LEXT(ml_set_processor_speed_powertune)
2019 mflr r0 ; Save the link register
2020 stwu r1, -(FM_ALIGN(4*4)+FM_SIZE)(r1) ; Make some space on the stack
2021 stw r28, FM_ARG0+0x00(r1) ; Save a register
2022 stw r29, FM_ARG0+0x04(r1) ; Save a register
2023 stw r30, FM_ARG0+0x08(r1) ; Save a register
2024 stw r31, FM_ARG0+0x0C(r1) ; Save a register
2025 stw r0, (FM_ALIGN(4*4)+FM_SIZE+FM_LR_SAVE)(r1) ; Save the return
2027 mfsprg r31,1 ; Get the current activation
2028 lwz r31,ACT_PER_PROC(r31) ; Get the per_proc block
2030 lwz r30, pfPowerModes(r31) ; Get the supported power modes
2032 rlwinm r28, r3, 31-dnap, dnap, dnap ; Shift the 1 bit to the dnap+32 bit
2033 rlwinm r3, r3, 2, 29, 29 ; Shift the 1 to a 4 and mask
2034 addi r3, r3, pfPowerTune0 ; Add in the pfPowerTune0 offset
2035 lwzx r29, r31, r3 ; Load the PowerTune number 0 or 1
2037 sldi r28, r28, 32 ; Shift to the top half
2038 ld r3, pfHID0(r31) ; Load the saved hid0 value
2039 and r28, r28, r3 ; Save the dnap bit
2040 lis r4, hi16(dnapm) ; Make a mask for the dnap bit
2041 sldi r4, r4, 32 ; Shift to the top half
2042 andc r3, r3, r4 ; Clear the dnap bit
2043 or r28, r28, r3 ; Insert the dnap bit as needed for later
2046 mtspr hid0, r3 ; Turn off dnap in hid0
2047 mfspr r3, hid0 ; Yes, this is silly, keep it here
2048 mfspr r3, hid0 ; Yes, this is a duplicate, keep it here
2049 mfspr r3, hid0 ; Yes, this is a duplicate, keep it here
2050 mfspr r3, hid0 ; Yes, this is a duplicate, keep it here
2051 mfspr r3, hid0 ; Yes, this is a duplicate, keep it here
2052 mfspr r3, hid0 ; Yes, this is a duplicate, keep it here
2053 isync ; Make sure it is set
2055 lis r3, hi16(PowerTuneControlReg) ; Write zero to the PCR
2056 ori r3, r3, lo16(PowerTuneControlReg)
2061 lis r3, hi16(PowerTuneControlReg) ; Write the PowerTune value to the PCR
2062 ori r3, r3, lo16(PowerTuneControlReg)
2067 rlwinm r29, r29, 13-6, 6, 7 ; Move to PSR speed location and isolate the requested speed
2069 lis r3, hi16(PowerTuneStatusReg) ; Read the status from the PSR
2070 ori r3, r3, lo16(PowerTuneStatusReg)
2074 rlwinm r0, r5, 0, 6, 7 ; Isolate the current speed
2075 rlwimi r0, r5, 0, 2, 2 ; Copy in the change in progress bit
2076 cmpw r0, r29 ; Compare the requested and current speeds
2077 beq spsPowerTuneDone
2078 rlwinm. r0, r5, 0, 3, 3
2079 beq spsPowerTuneLoop
2083 mtspr hid0, r28 ; Turn on dnap in hid0 if needed
2084 mfspr r28, hid0 ; Yes, this is silly, keep it here
2085 mfspr r28, hid0 ; Yes, this is a duplicate, keep it here
2086 mfspr r28, hid0 ; Yes, this is a duplicate, keep it here
2087 mfspr r28, hid0 ; Yes, this is a duplicate, keep it here
2088 mfspr r28, hid0 ; Yes, this is a duplicate, keep it here
2089 mfspr r28, hid0 ; Yes, this is a duplicate, keep it here
2090 isync ; Make sure it is set
2092 lwz r0, (FM_ALIGN(4*4)+FM_SIZE+FM_LR_SAVE)(r1) ; Get the return
2093 lwz r28, FM_ARG0+0x00(r1) ; Restore a register
2094 lwz r29, FM_ARG0+0x04(r1) ; Restore a register
2095 lwz r30, FM_ARG0+0x08(r1) ; Restore a register
2096 lwz r31, FM_ARG0+0x0C(r1) ; Restore a register
2097 lwz r1, FM_BACKPTR(r1) ; Pop the stack
2102 ** ml_set_processor_speed_dpll()
2105 ; Force a line boundry here
2107 .globl EXT(ml_set_processor_speed_dpll)
2109 LEXT(ml_set_processor_speed_dpll)
2110 mfsprg r5,1 ; Get the current activation
2111 lwz r5,ACT_PER_PROC(r5) ; Get the per_proc block
2113 cmplwi r3, 0 ; Turn off BTIC before low speed
2115 mfspr r4, hid0 ; Get the current hid0 value
2116 rlwinm r4, r4, 0, btic+1, btic-1 ; Clear the BTIC bit
2118 mtspr hid0, r4 ; Set the new hid0 value
2123 mfspr r4, hid1 ; Get the current PLL settings
2124 rlwimi r4, r3, 31-hid1ps, hid1ps, hid1ps ; Copy the PLL Select bit
2125 stw r4, pfHID1(r5) ; Save the new hid1 value
2126 mtspr hid1, r4 ; Select desired PLL
2128 cmplwi r3, 0 ; Restore BTIC after high speed
2130 lwz r4, pfHID0(r5) ; Load the hid0 value
2132 mtspr hid0, r4 ; Set the hid0 value
2140 ** ml_set_processor_speed_dfs()
2143 ; Force a line boundry here
2145 .globl EXT(ml_set_processor_speed_dfs)
2147 LEXT(ml_set_processor_speed_dfs)
2148 mfsprg r5,1 ; Get the current activation
2149 lwz r5,ACT_PER_PROC(r5) ; Get the per_proc block
2151 cmplwi r3, 0 ; full speed?
2152 mfspr r3, hid1 ; Get the current HID1
2153 rlwinm r3, r3, 0, hid1dfs1+1, hid1dfs0-1 ; assume full speed, clear dfs bits
2155 oris r3, r3, hi16(hid1dfs1m) ; slow, set half speed dfs1 bit
2158 stw r3, pfHID1(r5) ; Save the new hid1 value
2160 mtspr hid1, r3 ; Set the new HID1
2167 ** ml_set_processor_voltage()
2170 ; Force a line boundry here
2172 .globl EXT(ml_set_processor_voltage)
2174 LEXT(ml_set_processor_voltage)
2175 mfsprg r5,1 ; Get the current activation
2176 lwz r5,ACT_PER_PROC(r5) ; Get the per_proc block
2178 lwz r6, pfPowerModes(r5) ; Get the supported power modes
2180 rlwinm. r0, r6, 0, pmDPLLVminb, pmDPLLVminb ; Is DPLL Vmin supported
2183 mfspr r4, hid2 ; Get HID2 value
2184 rlwimi r4, r3, 31-hid2vmin, hid2vmin, hid2vmin ; Insert the voltage mode bit
2185 mtspr hid2, r4 ; Set the voltage mode
2186 sync ; Make sure it is done
2193 ; unsigned int ml_scom_write(unsigned int reg, unsigned long long data)
2194 ; 64-bit machines only
2199 .globl EXT(ml_scom_write)
2203 rldicr r3,r3,8,47 ; Align register it correctly
2204 rldimi r5,r4,32,0 ; Merge the high part of data
2205 sync ; Clean up everything
2207 mtspr scomd,r5 ; Stick in the data
2208 mtspr scomc,r3 ; Set write to register
2212 mfspr r3,scomc ; Read back status
2216 ; unsigned int ml_read_scom(unsigned int reg, unsigned long long *data)
2217 ; 64-bit machines only
2219 ; ASM Callers: data (r4) can be zero and the 64 bit data will be returned in r5
2223 .globl EXT(ml_scom_read)
2227 mfsprg r0,2 ; Get the feature flags
2228 rldicr r3,r3,8,47 ; Align register it correctly
2229 rlwinm r0,r0,pfSCOMFixUpb+1,31,31 ; Set shift if we need a fix me up
2231 ori r3,r3,0x8000 ; Set to read data
2234 mtspr scomc,r3 ; Request the register
2235 mfspr r5,scomd ; Get the register contents
2236 mfspr r3,scomc ; Get back the status
2240 sld r5,r5,r0 ; Fix up if needed
2242 cmplwi r4, 0 ; If data pointer is null, just return
2243 beqlr ; the received data in r5
2244 std r5,0(r4) ; Pass back the received data
2248 ; Calculates the hdec to dec ratio
2252 .globl EXT(ml_hdec_ratio)
2256 li r0,0 ; Clear the EE bit (and everything else for that matter)
2257 mfmsr r11 ; Get the MSR
2258 mtmsrd r0,1 ; Set the EE bit only (do not care about RI)
2259 rlwinm r11,r11,0,MSR_EE_BIT,MSR_EE_BIT ; Isolate just the EE bit
2260 mfmsr r10 ; Refresh our view of the MSR (VMX/FP may have changed)
2261 or r12,r10,r11 ; Turn on EE if on before we turned it off
2263 mftb r9 ; Get time now
2264 mfspr r2,hdec ; Save hdec
2266 mhrcalc: mftb r8 ; Get time now
2267 sub r8,r8,r9 ; How many ticks?
2268 cmplwi r8,10000 ; 10000 yet?
2269 blt mhrcalc ; Nope...
2271 mfspr r9,hdec ; Get hdec now
2272 sub r3,r2,r9 ; How many ticks?
2273 mtmsrd r12,1 ; Flip EE on if needed