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