Calculating virtual address from physical address
I'm using a Virtex II Pro-based board with a PPC405. The board is hanging somewhere very early in the kernel boot process. I believe it may be dying at the point where the MMU is enabled. In order to determine the exact point at which my board hangs, I'm blinking two LEDs in the assembly code found in arch/ppc/kernel/head_4xx.S, . Currently I am only able to successfully access the LEDs before the MMU is turned on, but I can't be sure that I'm calculating the virtual address properly when I try to access the LED after the MMU is turned on.
My LEDs are at address 0x4F600000 and my CONFIG_KERNEL_START is 0xC0000000. If this address were low enough, I would just add 0xC0000000 to the address to get the virtual address, but since my LED address is so high, the sum will be well past the 32-bit maximum address value. How is a virtual address calculated for a high address like 0x4F600000?
BTW, he is the assembly code that I'm working with (from arch/ppc/kernel/head_4xx.S):
.text_GLOBAL(_stext)_GLOBAL(_start)
/* Save parameters we are passed.
*/
mr r31,r3 mr r30,r4 mr r29,r5 mr r28,r6 mr r27,r7
/* CRD: set LED state here */
lis r26,0x4F600000@h
ori r26,r26,0x4F600000@l
li r25,LED_STATE_0
stw r25,0(r26)
/* We have to turn on the MMU right away so we get cache modes
* set correctly.
*/
bl initial_mmu
/* CRD: set LED state here */
lis r26,0x4F600000@h
ori r26,r26,0x4F600000@l
li r25,LED_STATE_1
stw r25,0(r26)
/* We now have the lower 16 Meg mapped into TLB entries, and the caches
* ready to work.
*/turn_on_mmu:
lis r0,MSR_KERNEL@h
ori r0,r0,MSR_KERNEL@l
mtspr SPRN_SRR1,r0
lis r0,start_here@h
ori r0,r0,start_here@l
mtspr SPRN_SRR0,r0
SYNC
/* CRD: set LED state here */
lis r26,0x4F600000@h
ori r26,r26,0x4F600000@l
li r25,LED_STATE_2
stw r25,0(r26)
rfi /* enables MMU */
/* CRD: set LED state here */
/* This address should be a virtual address */
lis r26,0x4F600000@h
ori r26,r26,0x4F600000@l
li r25,LED_STATE_3
stw r25,0(r26)
b . /* prevent prefetch past rfi */
Regards,
Chris Dumoulin
Signature · 15 lines
*--Christopher Dumoulin--* Software Team Leader <http://ics-ltd.com/> <http://ics-ltd.com/> Interactive Circuits and Systems Ltd. 5430 Canotek Road Ottawa, ON K1J 9G2 (613)749-9241 1-800-267-9794 (USA only) ------------------------------------------------------------------------ This e-mail is private and confidential and is for the addressee only. If misdirected, please notify us by telephone and confirm that it has been deleted from your system and any hard copies destroyed. You are strictly prohibited from using, printing, distributing or disseminating it or any information contained in it save to the intended recipient.
Quoted 8 lines · Chris Dumoulin
I'm using a Virtex II Pro-based board with a PPC405. The board is hanging somewhere very early in the kernel boot process. I believe it may be dying at the point where the MMU is enabled. In order to determine the exact point at which my board hangs, I'm blinking two LEDs in the assembly code found in
arch/ppc/kernel/head_4xx.S, . Currently I am only able to successfully access the LEDs before the MMU is turned on, but I can't be sure that I'm calculating the virtual address properly when I try to access the LED after the MMU is turned on.
Typical when trying to bring up board ...
Once the MMU is turned on, you leds register are most likely ... nowhere ... i.e.
if you don't create a mapping your self there is just no virtual address that will
access your leds physical address.
What I did on some ppc work was tu use a quick BAT mapping to map some leds. It's pretty easy to setup. Be aware though that this mapping will get wiped out when
the kernel sets up the BAT for itself.
Sylvain
Quoted 18 lines · Sylvain Munaut
Quoted 8 lines · Chris Dumoulin
I'm using a Virtex II Pro-based board with a PPC405. The board is hanging somewhere very early in the kernel boot process. I believe it may be dying at the point where the MMU is enabled. In order to determine the exact point at which my board hangs, I'm blinking two LEDs in the assembly code found in
arch/ppc/kernel/head_4xx.S, . Currently I am only able to successfully access the LEDs before the MMU is turned on, but I can't be sure that I'm calculating the virtual address properly when I try to access the LED after the MMU is turned on.Typical when trying to bring up board ...
Once the MMU is turned on, you leds register are most likely ... nowhere ... i.e.
if you don't create a mapping your self there is just no virtual address that will
access your leds physical address.
Quoted 4 lines
What I did on some ppc work was tu use a quick BAT mapping to map some leds. It's pretty easy to setup. Be aware though that this mapping will get wiped out when
the kernel sets up the BAT for itself.
There are no BATs on 4xx. However, the same conceptual thing can be done by wiring a fixed TLB entry to cover those LEDs temporarily during bringup debug. The temporary TLB entry will be wiped out by normal tlb misses after things are running whenever the fixed entry is clobbered by the round robin replacement.
-Matt
Quoted 6 lines · Matt Porter
There are no BATs on 4xx. However, the same conceptual thing can be done by wiring a fixed TLB entry to cover those LEDs temporarily during bringup debug. The temporary TLB entry will be wiped out by normal tlb misses after things are running whenever the fixed entry is clobbered by the round robin replacement.
At which point you should be able to call ioremap to generate a virtual address inside a device driver or board file.
josh
Quoted 6 lines · Chris Dumoulin
My LEDs are at address
0x4F600000and myCONFIG_KERNEL_STARTis0xC0000000. If this address were low enough, I would just add0xC0000000to the address to get the virtual address, but since my LED address is so high, the sum will be well past the 32-bit maximum address value. How is a virtual address calculated for a high address like0x4F600000?
There are macros tophys and tovirt that convert addresses between
physical and virtual. There are use example in the head_4xx.S file you are already in.
If you are going to use a port for debugging you need to create a
tlb entry for it.
Same file in initial_mmu the code inside the ifdefined(CONFIG_SERIAL_TEXT_DEBUG) should provide an example how to do that.
Be forwarned that any entries you create now will eventually
disappear (took 2 weeks to figure that out once), but that may not happen intil after /init starts.
Also with a little of jiggering arround the bits in MSR_KERNEL you
can enable Data address translation independently of instruction address translation as well as disable or enable a variety of
checks. It took me three weeks to get a new Xilinx V4 board through
the rfi and to start_here in the same turn_on_mmu code you are working on.
Eventually I ended up enabling the MSR bits one at a time until I
discovered that enabling the Machine Check sent me to space.
Regardless, once I relialized I could test the code with the MSR
bits enabled one at a time isolating the problem became easier.
The two issues I addressed above which relate specifically to your
efforts with the ml300, constituted more than 80% of my effort to get a Xilinx Virtex 4 running.
Finally, I started prior to grants platform bus changes. I have been
adapting my V4 code to fit with Grants changes (the client has what they want so they do not care)
I have not put alot of effort into this, but I currently get
waylayed much later in new platform bus specific initialization code.
I had no problem with the older board specific initialization code.
If you are running on a real ml300 I am surprised you are having any
problems though I do not have an ml300 to check that.
But if you are running on a custom V2Pro board you have to get the
board specific initalization right and therefore could trip over the issue I am currently having migrating from old to new.
Quoted 64 lines
BTW, he is the assembly code that I'm working with (from
arch/ppc/kernel/head_4xx.S):.text
_GLOBAL(_stext)_GLOBAL(_start)/* Save parameters we are passed. */ mr r31,r3 mr r30,r4 mr r29,r5 mr r28,r6 mr r27,r7 /* CRD: set LED state here */ lis r26,0x4F600000@h ori r26,r26,0x4F600000@l li r25,LED_STATE_0 stw r25,0(r26) /* We have to turn on the MMU right away so we get cache modes * set correctly. */ bl initial_mmu /* CRD: set LED state here */ lis r26,0x4F600000@h ori r26,r26,0x4F600000@l li r25,LED_STATE_1 stw r25,0(r26)/* We now have the lower 16 Meg mapped into TLB entries, and the caches
* ready to work.
*/turn_on_mmu:lis r0,MSR_KERNEL@h ori r0,r0,MSR_KERNEL@l mtspr SPRN_SRR1,r0 lis r0,start_here@h ori r0,r0,start_here@l mtspr SPRN_SRR0,r0 SYNC /* CRD: set LED state here */ lis r26,0x4F600000@h ori r26,r26,0x4F600000@l li r25,LED_STATE_2 stw r25,0(r26) rfi /* enables MMU */ /* CRD: set LED state here */ /* This address should be a virtual address */ lis r26,0x4F600000@h ori r26,r26,0x4F600000@l li r25,LED_STATE_3 stw r25,0(r26) b . /* prevent prefetch past rfi */Regards,
Chris Dumoulin
Signature · 8 lines
Dave Lynch DLA Systems Software Development: Embedded Linux 717.627.3770 [email protected] http://www.dlasys.net fax: 1.253.369.9244 Cell: 1.717.587.7774 Over 25 years' experience in platforms, languages, and technologies too numerous to list. "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction." Albert Einstein