Subject: Questions regarding MIPS platforms boot process

From: Thomas Petazzoni <[email-masked]>
Date: Wed, 15 Sep 2004 09:23:37 +0200

Hello,

I'm currently trying to port Linux 2.6 to a MIPS platform which is very
similar to the Jaguar ATX platform, so I started from this code. I have
a few questions concerning this code.

1) Wired TLB entries and ioremap()

In the file arch/mips/momentum/jaguar_atx/setup.c, the
momenco_jaguar_atx_setup() function calls the wire_stupidity_into_tlb()
function to hard-wire entries into the TLB. These entries allows to
access the Marvell registers space (at 0xf4000000). So, this is done in
the early stages of the initialization.

Then, later, the per_cpu_mappings() function is called, through the
arch_initcall mecanism. This function calls ioremap() to map in virtual
memory the Marvell registers space.

At the beginning, I did not understand why both (hard-wired TLB entry
+ mapping in virtual space through ioremap()) were needed, but after
reflexion and discussion with collegues, we found out a possible
explanation. I just wanted to know if it was true or not.

At the very first stages of the initialization (during the
momenco_jaguar_atx_setup() function for example), paging is not
initialized, so we cannot use ioremap(). But we still want to be able to
talk with the Marvell, so the only solution is to wire an entry in the
TLB.

Then, later on, once everything has been set up (including paging), we
do not need anymore this wired entry, which is deleted in the
per_cpu_mappings() function through the call of the
local_flush_tlb_all() function. The Marvell registers space is then
ioremap'ed in the address, and so is still accessible (because paging is
now enabled).

Is it the right explanation ?

2) Mips_hpt_frequency

I'm not sure whether my board_time_init() function should set
mips_hpt_frequency or not. In arch/mips/kernel/time.c, it is said that :

 *      b) (optional) calibrate and set the mips_hpt_frequency
 *	    (only needed if you intended to use fixed_rate_gettimeoffset
 *	     or use cpu counter as timer interrupt source)

So it doesn't seem to be mandatory, but actually I do not understand
clearly the two cases for which setting mips_hpt_frequency is mandatory.
I don't think I want to use fixed_rate_gettimeoffset, but I'm not sure
with the second usage.

When I read the code of arch/mips/kernel/time.c, function time_init()
around line 701, I can see that if no value has been set to
mips_hpt_frequency, then it is computed by the calibrate_hpt(). So, when
is it needed to set it ?

FYI, the platform I'm working on doesn't have any external timer source.

What's the exact use of the mips_hpt_frequency ? Should I set it or not
?

Thanks,

Thomas
-- 
PETAZZONI Thomas - [email-masked] 
http://thomas.enix.org - Jabber: [email-masked]
KOS: http://kos.enix.org/ - Lolut: http://lolut.utbm.info
Fingerprint : 0BE1 4CF3 CEA4 AC9D CC6E  1624 F653 CB30 98D3 F7A7

---

From: "Maciej W. Rozycki" <[email-masked]>
Date: Tue, 28 Sep 2004 21:57:04 +0100 (BST)

> I don't think I want to use fixed_rate_gettimeoffset, but I'm not sure

 If you want to use a HPT at all, then you do want to use
fixed_rate_gettimeoffset().  The calibrate_div32_gettimeoffset() and
calibrate_div64_gettimeoffset() backends are considered obsolete and will
be removed.  That's the first case.

 The other is when you use the CP0's internal timer as a source of timer 
interrupts.

> mips_hpt_frequency, then it is computed by the calibrate_hpt(). So, when

 You only need to set mips_hpt_frequency manually if there's no way do
determine the timer's frequency automatically.  This is usually the case,
when there is no reference timer in the system, e.g. you only have the
CP0's internal timer, but you know the timer's frequency.  But you are
free do that even if you have a reference timer, but using the generic 
calibration code would be too complicated to set up.

 Otherwise, you need to set the mips_timer_state function pointer to make
the code set up mips_hpt_frequency automagically.  The function has to
report a the state of the timer in such a way, that there are HZ 0 to 1
transitions per second with equal intervals.  Typically it would just read 
the state of an interrupt output from the device providing timer 
interrupts, but actually it's up to you how you implement it.

> FYI, the platform I'm working on doesn't have any external timer source.

 You need to set mips_hpt_frequency somehow, then.  If your CPU's clock is
fixed for all devices, then you can simply hardcode the frequency.  If the
clock varies and there's absolutely no way to determine it, you may ask
the user to enter the value valid for his system during kernel
configuration.

> What's the exact use of the mips_hpt_frequency ? Should I set it or not

 If you use the CP0's internal timer, then mips_hpt_frequency is used to
setup the timer's interval.  The resulting interval is expected to be 1/HZ
and it is the base of the system time, both for scheduling and for
timekeeping.

 If you don't use the CP0's internal timer, and you have an external timer
device (such as an RTC chip), then mips_hpt_frequency is optional,
although still recommended.  It's used to provide a finer granularity for 
timekeeping (gettimeofday() and friends).

  Maciej