]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/Diagnostics.c
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 * @OSF_FREE_COPYRIGHT@
26 * @APPLE_FREE_COPYRIGHT@
30 * Author: Bill Angell, Apple
37 #include <kern/machine.h>
38 #include <kern/processor.h>
39 #include <mach/machine.h>
40 #include <mach/processor_info.h>
41 #include <mach/mach_types.h>
42 #include <mach/boolean.h>
43 #include <kern/thread.h>
44 #include <kern/task.h>
45 #include <mach/vm_param.h>
46 #include <vm/vm_kern.h>
47 #include <vm/vm_map.h>
48 #include <vm/vm_page.h>
50 #include <ppc/exception.h>
51 #include <ppc/Firmware.h>
52 #include <ppc/low_trace.h>
53 #include <ppc/db_low_trace.h>
54 #include <ppc/mappings.h>
57 #include <ppc/savearea.h>
58 #include <ppc/Diagnostics.h>
59 #include <ppc/machine_cpu.h>
60 #include <pexpert/pexpert.h>
61 #include <console/video_console.h>
64 extern struct vc_info vinfo
;
66 kern_return_t
testPerfTrap(int trapno
, struct savearea
*ss
,
67 unsigned int dsisr
, addr64_t dar
);
69 int diagCall(struct savearea
*save
) {
72 unsigned long long tbase
;
75 natural_t tbu
, tbu2
, tbl
;
76 struct per_proc_info
*per_proc
; /* Area for my per_proc address */
78 unsigned int tstrt
, tend
, temp
, temp2
;
80 uint64_t scom
, hid1
, hid4
, srrwrk
, stat
;
83 if(!(dgWork
.dgFlags
& enaDiagSCs
)) return 0; /* If not enabled, cause an exception */
85 switch(save
->save_r3
) { /* Select the routine */
88 * Adjust the timebase for drift recovery testing
90 case dgAdjTB
: /* Adjust the timebase */
92 adj
.tb
[0] = 0; /* Clear high part */
93 adj
.tb
[1] = save
->save_r4
; /* Set low order */
94 if(adj
.tb
[1] & 0x80000000) adj
.tb
[0] = 0xFFFFFFFF; /* Propagate sign bit */
96 do { /* Read current time */
97 asm volatile(" mftbu %0" : "=r" (tbu
));
98 asm volatile(" mftb %0" : "=r" (tbl
));
99 asm volatile(" mftbu %0" : "=r" (tbu2
));
100 } while (tbu
!= tbu2
);
102 ttt
.tb
[0] = tbu
; /* Set high */
103 ttt
.tb
[1] = tbl
; /* Set low */
105 ttt
.tbase
= ttt
.tbase
+ adj
.tbase
; /* Increment or decrement the TB */
107 tbu
= ttt
.tb
[0]; /* Save in regular variable */
108 tbl
= ttt
.tb
[1]; /* Save in regular variable */
110 mttb(0); /* Set low to keep from ticking */
111 mttbu(tbu
); /* Set adjusted high */
112 mttb(tbl
); /* Set adjusted low */
114 return -1; /* Return no AST checking... */
117 * Return physical address of a page
121 save
->save_r3
= pmap_find_phys(current_act()->map
->pmap
, save
->save_r4
); /* Get read address */
123 return -1; /* Return no AST checking... */
126 * Copy physical to virtual
132 src
= (save
->save_r4
<< 32) | (0x00000000FFFFFFFFULL
& save
->save_r5
); /* Merge into 64-bit */
133 snk
= (save
->save_r6
<< 32) | (0x00000000FFFFFFFFULL
& save
->save_r7
); /* Merge into 64-bit */
134 save
->save_r3
= copypv(src
, snk
, save
->save_r8
, save
->save_r9
); /* Copy the physical page */
136 return 1; /* Return and check for ASTs... */
139 * Read/Write physical memory
143 src
= (save
->save_r5
<< 32) | (0x00000000FFFFFFFFULL
& save
->save_r6
); /* Merge into 64-bit */
145 switch(save
->save_r4
) { /* Select the actual function */
148 save
->save_r3
= (uint64_t)ml_phys_read_byte((unsigned int)src
);
152 save
->save_r3
= (uint64_t)ml_phys_read_byte_64(src
);
156 save
->save_r3
= (uint64_t)ml_phys_read((unsigned int)src
);
160 save
->save_r3
= (uint64_t)ml_phys_read_64(src
);
164 ml_phys_write_byte((unsigned int)src
, (unsigned int)save
->save_r7
);
168 ml_phys_write_byte_64(src
, (unsigned int)save
->save_r7
);
172 ml_phys_write((unsigned int)src
, (unsigned int)save
->save_r7
);
176 ml_phys_write_64(src
, (unsigned int)save
->save_r7
);
180 return 1; /* Return and check for ASTs... */
184 * Soft reset processor
188 cpu
= save
->save_r4
; /* Get the requested CPU number */
190 if(cpu
>= NCPUS
) { /* Check for bogus cpu */
191 save
->save_r3
= KERN_FAILURE
; /* Set failure */
195 if(!machine_slot
[cpu
].running
) return KERN_FAILURE
; /* It is not running */
197 per_proc
= &per_proc_info
[cpu
]; /* Point to the processor */
199 (void)PE_cpu_start(per_proc
->cpu_id
,
200 per_proc
->start_paddr
, (vm_offset_t
)per_proc
);
202 save
->save_r3
= KERN_SUCCESS
; /* Set scuuess */
204 return 1; /* Return and check for ASTs... */
211 cacheInit(); /* Blow cache */
212 return 1; /* Return and check for ASTs... */
219 if(save
->save_r4
) perfTrapHook
= testPerfTrap
;
220 else perfTrapHook
= 0;
222 return 1; /* Return and check for ASTs... */
227 * Create a physical block map into the current task
228 * Don't bother to check for any errors.
229 * parms - vaddr, paddr, size, prot, attributes
233 pmap_map_block(current_act()->map
->pmap
, (addr64_t
)save
->save_r4
, /* Map in the block */
234 save
->save_r5
, save
->save_r6
, save
->save_r7
, save
->save_r8
, 0);
236 return 1; /* Return and check for ASTs... */
240 * Remove any mapping from the current task
241 * Don't bother to check for any errors.
246 (void)mapping_remove(current_act()->map
->pmap
, save
->save_r4
); /* Remove mapping */
247 return 1; /* Return and check for ASTs... */
251 * Allows direct control of alignment handling.
253 * The bottom bit of the parameter is used to set the control bit, enaNotifyEM.
257 temp
= dgWork
.dgFlags
; /* Save the old values */
259 temp2
= (save
->save_r4
& 1) << (31 - enaNotifyEMb
); /* Move parms into flag format */
260 dgWork
.dgFlags
= (temp
& ~enaNotifyEM
) | temp2
; /* Set the flag */
262 save
->save_r3
= (temp
>> (31 - enaNotifyEMb
)) & 1; /* Return the original */
264 return 1; /* Return and check for ASTs... */
267 * Return info for boot screen
271 ml_set_interrupts_enabled(1);
272 (void)copyout((char *)&vinfo
, CAST_DOWN(char *, save
->save_r4
), sizeof(struct vc_info
)); /* Copy out the video info */
273 ml_set_interrupts_enabled(0);
274 return 1; /* Return and check for ASTs... */
277 * Don't return info for boot screen
281 ml_set_interrupts_enabled(1);
282 (void)copyout((char *)&vinfo
, CAST_DOWN(char *, save
->save_r4
), 0); /* Copy out nothing */
283 ml_set_interrupts_enabled(0);
284 return 1; /* Return and check for ASTs... */
287 * Test machine check handler - only on 64-bit machines
290 if(!(per_proc_info
[0].pf
.Available
& pf64Bit
)) return 0; /* Leave if not correct machine */
292 fwEmMck(save
->save_r4
, save
->save_r5
, save
->save_r6
, save
->save_r7
, save
->save_r8
, save
->save_r9
); /* Start injecting */
294 return -1; /* Return and don't check for ASTs... */
297 * Set 64-bit on or off - only on 64-bit machines
300 if(!(per_proc_info
[0].pf
.Available
& pf64Bit
)) return 0; /* Leave if not correct machine */
302 srrwrk
= save
->save_srr1
>> 63; /* Save the old 64-bit bit */
304 save
->save_srr1
= (save
->save_srr1
& 0x7FFFFFFFFFFFFFFFULL
) | (save
->save_r4
<< 63); /* Set the requested mode */
305 save
->save_r3
= srrwrk
; /* Return the old value */
307 return -1; /* Return and don't check for ASTs... */
310 * Test the probe read function
315 src
= (save
->save_r4
<< 32) | (0x00000000FFFFFFFFULL
& save
->save_r5
); /* Merge into 64-bit */
316 save
->save_r3
= ml_probe_read_64(src
, &temp
); /* Try the address */
317 save
->save_r4
= temp
; /* Return the data */
318 return -1; /* Regurn and don't check for ASTs */
321 * Do perf monitor stuff
326 setPmon(save
->save_r4
, save
->save_r5
); /* Go load up MMCR0 and MMCR1 */
327 return -1; /* Regurn and don't check for ASTs */
331 * Don't bother to check for any errors.
332 * parms - vaddr, paddr, prot, attributes
336 (void)mapping_map(current_act()->map
->pmap
, /* Map in the page */
337 (addr64_t
)(((save
->save_r5
& 0xFFFFFFFF) << 32) | (save
->save_r5
& 0xFFFFFFFF)), save
->save_r6
, 0, 1, VM_PROT_READ
|VM_PROT_WRITE
);
339 return -1; /* Return and check for ASTs... */
343 * parms - pointer to scomcomm
347 ret
= copyin((unsigned int)(save
->save_r4
), &sarea
, sizeof(scomcomm
)); /* Get the data */
348 if(ret
) return 0; /* Copyin failed - return an exception */
350 sarea
.scomstat
= 0xFFFFFFFFFFFFFFFFULL
; /* Clear status */
351 cpu
= cpu_number(); /* Get us */
353 if((sarea
.scomcpu
< NCPUS
) && machine_slot
[sarea
.scomcpu
].running
) {
354 if(sarea
.scomcpu
== cpu
) { /* Is it us? */
355 if(sarea
.scomfunc
) { /* Are we writing */
356 sarea
.scomstat
= ml_scom_write(sarea
.scomreg
, sarea
.scomdata
); /* Write scom */
359 sarea
.scomstat
= ml_scom_read(sarea
.scomreg
, &sarea
.scomdata
); /* Read scom */
362 else { /* Otherwise, tell the other processor */
363 (void)cpu_signal(sarea
.scomcpu
, SIGPcpureq
, CPRQscom
,(unsigned int)&sarea
); /* Ask him to do this */
364 (void)hw_cpu_sync((unsigned long)&sarea
.scomstat
, LockTimeOut
); /* Wait for the other processor to get its temperature */
368 ret
= copyout(&sarea
, (unsigned int)(save
->save_r4
), sizeof(scomcomm
)); /* Get the data */
369 if(ret
) return 0; /* Copyin failed - return an exception */
371 return -1; /* Return and check for ASTs... */
374 default: /* Handle invalid ones */
375 return 0; /* Return an exception */
381 kern_return_t
testPerfTrap(int trapno
, struct savearea
*ss
,
382 unsigned int dsisr
, addr64_t dar
) {
384 if(trapno
!= T_ALIGNMENT
) return KERN_FAILURE
;
386 kprintf("alignment exception at %08X, srr1 = %08X, dsisr = %08X, dar = %08X\n", ss
->save_srr0
,
387 ss
->save_srr1
, dsisr
, dar
);