login
Header Space

 
 

Re: [PATCH 1/2] OLPC: Add support for calling into Open Firmware

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: H. Peter Anvin <hpa@...>
Cc: Andres Salomon <dilinger@...>, Yinghai Lu <yhlu.kernel@...>, Eric W. Biederman <ebiederm@...>, Ingo Molnar <mingo@...>, Andrew Morton <akpm@...>, Joseph Fannin <jfannin@...>, <linux-kernel@...>, <jordan.crouse@...>
Date: Sunday, April 20, 2008 - 11:39 pm

H. Peter Anvin wrote:

Fair enough...

To get the second subquestion out of the way:  At the present time, on 
the x86 architecture, "all OF implementations" and "OLPC" are 
effectively the same.  I am unaware of any other x86 OFW deployments in 
current use.  There have been some in the past, on bespoke systems such 
as Network Appliance servers and at least one settop box, but those have 
fallen by the wayside as those companies have shifted over to commodity 
PC hardware.  The current market status quo is that x86 boards are 
primarily designed for Windows, and thus must run legacy BIOS, with some 
recent migration to EFI, neither of which are open source in the strong 
sense.  While I would like to see more OFW penetration into the larger 
x86 market, I don't really expect it.  x86 motherboard manufacturing is 
becoming more and more difficult as signal speeds increase, leading to a 
decline in the number of manufacturers.  The existing manufacturers 
depend on Windows for sales volume and their internal procedures and 
working knowledge are based on legacy BIOS.

Once upon a time, we had an OFW "binding" document that stipulated the 
interface conditions, with the intention of making that "standard" 
across all OFW-on-x86 systems.  However, by the time OLPC came around, 
there were no other systems to consider, so I felt free to make some 
changes in the interface.  I ended up choosing an ABI that resulted in a 
simple (in the sense of not much code, and no complex state transitions) 
interface with 2.6 Linux kernels.

The interface defined below is not inherently OLPC-specific - it would 
be suitable for any ia32 system that used OFW.  (At a higher level, the 
set of OFW callback functions is architecture-neutral; in this message I 
am focusing on the very low-level details of the ia32 ABI)

The system conditions for the OFW to Linux kernel transition are as follows:

a) OFW can load the Linux kernel from either bzimage format or ELF 
format (either uncompressed or zlib-compressed.)  If the kernel is in 
ELF format with symbols, OFW can do symbolic kernel debugging.  Further 
discussion will focus on bzimage format, as that is what OLPC uses and 
is also the "greased path" for kernel builds.

b) OFW loads the bzimage kernel at 0x100000 and the ramdisk image, if 
any, at 0x800000.

c) OFW runs in 32-bit protected mode with paging enabled.  There are two 
reasons for this.  First, it lets OFW locate itself at the top of both 
physical memory space and virtual address space, the only places that 
are truly "out of the way".  It also lets Linux call back into OFW with 
a minimum of bother (similarly helping with the OFW-debugs-Linux scenario).

d) OFW itself lives at the top of the virtual address space, just below 
the ROM.  (The ROM is mapped virtual=physical  for convenience)  OFW 
uses RAM allocated from the top of physical memory, mapped at the 
aforementioned high virtual addresses.  One page directory entry - the 
next to last one - is used for that RAM mapping and also for mapping 
additional miscellaneous I/O devices.  The 8MB frame buffer requires 2 
additional PDEs, just below.  When Linux takes over the display, OFW no 
longer needs the frame buffer mapping, but it is convenient to preserve 
that mapping temporarily while using OFW as a debugger.

e) Low memory - everything except the ~1Meg that OFW lives in - is 
mapped virtual=physical.

f) The code, data, and stack segment descriptors are all for 32-bit 4GB 
linear segments.  (For debugging convenience, OFW initially uses the 
same segment numbers as the Linux kernel, but that is not an ABI 
requirement - callbacks into OFW will work from any 32-bit segments that 
encompass the kernel and OFW virtual address space.)

g) OFW sets up a boot parameter block at 0x90000, with the format as 
defined in include/asm-x86/bootparam.h  .  The block includes the 
cmdline, memory layout information, screen info, and address/length of 
the ramdisk.

h) OFW also includes in the boot parameter block an additional 
information block at OFW_INFO_OFFSET.  That info block contains:
    "OFW " - 4-byte signature string ('O' at byte offset 0, etc)
    __u32 version  - 1
    __u32 callback  - (actually a 32-bit function pointer) address of 
callback function
    __u32 idt    - address of OFW's interrupt descriptor table, in case 
Linux wants to preserve the breakpoint vector

i) OFW transfers control to the bzimage with the processor in the 
following state:
    * interrupts masked off at the interrupt controller and in the flags 
register
    * 32-bit protected mode, CS=0x60, DS=ES=FS=GS=SS=0x68
    * ebx=ecx=edx=ebp=edi=0
    * eax = &callback_function
    * esi = 0x90000 (boot parameter block)
    * esp = 0x90000 (short-lived initial stack starts below boot 
parameter block)
    * eip = 0x100000 (entry address of bzimage)
    * paging enabled, with V=P mapping of physical memory and one high 
pde for OFW, as in (d) and (e) above

j) Linux must save the following information during early startup:
  1) The callback function address - either from the initial value of 
eax or from the OFW info block.
  2) The the next-to-last page directory entry - just the pointer to the 
page table.  The page table itself lives in OFW's reserved memory.

k) When calling back into OFW, Linux must:
  1) Establish a page directory that contains OFW's PDE (saved in j2 
above) and that maps the client interface argument array, including any 
buffer pointers.
  2) Call callback_function with the address of the argument array in 
eax.  (Ordinary 32-bit near call).

For all of the OLPC kernel's current callbacks into OFW, the 
requirements (j2) and (k1) are easily satisfied by "priming" 
swapper_pg_dir with the contents of the current page directory (as 
pointed to by the CR3 register).



--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
2.6.25-mm1, Andrew Morton, (Fri Apr 18, 4:47 am)
[Was: 2.6.25-mm1], Jiri Slaby, (Mon Apr 21, 4:31 am)
Re: [Was: 2.6.25-mm1], Al Viro, (Mon Apr 21, 5:06 am)
fault in __d_lookup [Was: 2.6.25-mm1], Jiri Slaby, (Mon Apr 21, 5:37 am)
Re: fault in __d_lookup [Was: 2.6.25-mm1], Al Viro, (Mon Apr 21, 5:45 am)
Re: fault in __d_lookup [Was: 2.6.25-mm1], Jiri Slaby, (Mon Apr 21, 5:59 am)
Re: fault in __d_lookup [Was: 2.6.25-mm1], Matthew Wilcox, (Mon Apr 21, 1:23 pm)
Re: fault in __d_lookup [Was: 2.6.25-mm1], Rafael J. Wysocki, (Mon Apr 21, 9:42 am)
internal compiler error: SIGSEGV [Was: 2.6.25-mm1], Jiri Slaby, (Sun Apr 20, 7:29 am)
Re: 2.6.25-mm1, Joseph Fannin, (Fri Apr 18, 11:10 pm)
Re: 2.6.25-mm1, Andrew Morton, (Fri Apr 18, 11:29 pm)
Re: 2.6.25-mm1, Arjan van de Ven, (Sat Apr 19, 2:21 pm)
Re: 2.6.25-mm1, Andres Salomon, (Sat Apr 19, 9:25 am)
Re: 2.6.25-mm1, Andrew Morton, (Sat Apr 19, 1:38 pm)
Re: 2.6.25-mm1, Andres Salomon, (Sat Apr 19, 1:50 pm)
Re: 2.6.25-mm1, Jordan Crouse, (Mon Apr 21, 10:56 am)
Re: 2.6.25-mm1, Andres Salomon, (Mon Apr 21, 11:05 am)
Re: 2.6.25-mm1, Jordan Crouse, (Mon Apr 21, 11:12 am)
[PATCH 2/2] OLPC: drop pre-OpenFirmware workarounds, Andres Salomon, (Sat Apr 19, 1:39 pm)
Re: OLPC: only check for OFW signature on VSA-less Geodes, Jordan Crouse, (Mon Apr 21, 5:17 pm)
Re: [PATCH 1/2] OLPC: Add support for calling into Open Firm..., Mitch Bradley, (Sun Apr 20, 11:39 pm)
Re: OLPC: Add support for calling into Open Firmware, Jordan Crouse, (Mon Apr 21, 11:05 am)
Re: OLPC: Add support for calling into Open Firmware, H. Peter Anvin, (Mon Apr 21, 10:58 am)
Re: 2.6.25-mm1, Joseph Fannin, (Fri Apr 18, 10:25 pm)
Re: 2.6.25-mm1, Andrew Morton, (Fri Apr 18, 11:08 pm)
Re: 2.6.25-mm1, Joseph Fannin, (Fri Apr 18, 10:13 pm)
Re: 2.6.25-mm1, Andrew Morton, (Fri Apr 18, 11:02 pm)
Re: 2.6.25-mm1, Dmitry Torokhov, (Sat Apr 19, 12:14 am)
Re: 2.6.25-mm1, Andrew Morton, (Sat Apr 19, 12:29 am)
Re: 2.6.25-mm1, Takashi Iwai, (Mon Apr 21, 10:06 am)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Stas Sergeev, (Mon Apr 21, 1:55 pm)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Takashi Iwai, (Tue Apr 22, 6:13 am)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Stas Sergeev, (Tue Apr 22, 2:31 pm)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Takashi Iwai, (Wed Apr 23, 4:49 am)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Stas Sergeev, (Wed Apr 23, 4:02 pm)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Takashi Iwai, (Thu Apr 24, 5:40 am)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Stas Sergeev, (Thu Apr 24, 11:51 pm)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Takashi Iwai, (Fri Apr 25, 2:28 am)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Stas Sergeev, (Fri Apr 25, 12:45 pm)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Dmitry Torokhov, (Fri Apr 25, 2:09 pm)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Stas Sergeev, (Fri Apr 25, 2:31 pm)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Dmitry Torokhov, (Fri Apr 25, 2:37 pm)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Takashi Iwai, (Fri Apr 25, 12:51 pm)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Takashi Iwai, (Fri May 2, 12:44 pm)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Stas Sergeev, (Fri May 2, 12:57 pm)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Takashi Iwai, (Tue May 6, 6:20 am)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Stas Sergeev, (Tue May 6, 12:51 pm)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Stas Sergeev, (Fri Apr 25, 1:25 pm)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Takashi Iwai, (Wed Apr 23, 10:18 am)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Dmitry Torokhov, (Tue Apr 22, 10:01 am)
Re: 2.6.25-mm1 (snd-pcsp doesn't like DEBUG_PAGEALLOC), Stas Sergeev, (Tue Apr 22, 12:42 pm)
Re: 2.6.25-mm1, Takashi Iwai, (Mon Apr 21, 7:07 am)
Re: 2.6.25-mm1, Stas Sergeev, (Mon Apr 21, 3:45 pm)
Re: 2.6.25-mm1 (snd-pcsp causes driver conflict), Stas Sergeev, (Mon Apr 21, 1:44 pm)
Re: 2.6.25-mm1 (snd-pcsp causes driver conflict), Takashi Iwai, (Tue Apr 22, 6:09 am)
Re: 2.6.25-mm1 (snd-pcsp causes driver conflict), Stas Sergeev, (Tue Apr 22, 1:54 pm)
Re: 2.6.25-mm1 (snd-pcsp causes driver conflict), Takashi Iwai, (Wed Apr 23, 4:55 am)
Re: 2.6.25-mm1 (snd-pcsp causes driver conflict), Takashi Iwai, (Wed Apr 23, 10:14 am)
Re: 2.6.25-mm1, Joseph Fannin, (Sat Apr 19, 2:33 am)
2.6.25-mm1: orphaned files after build, Alexey Dobriyan, (Fri Apr 18, 7:09 pm)
Re: 2.6.25-mm1, , (Fri Apr 18, 4:14 pm)
Re: 2.6.25-mm1 (build error: trace selftest), Randy Dunlap, (Fri Apr 18, 12:45 pm)
Re: 2.6.25-mm1 (build error: driver core), Randy Dunlap, (Fri Apr 18, 12:40 pm)
Re: 2.6.25-mm1 (build error: driver core), Greg KH, (Fri Apr 18, 12:56 pm)
Re: 2.6.25-mm1 (build error: driver core), Dan Williams, (Fri Apr 18, 2:38 pm)
StackProtector Oopses - Re: 2.6.25-mm1, Reuben Farrelly, (Fri Apr 18, 9:02 am)
Re: StackProtector Oopses - Re: 2.6.25-mm1, Ingo Molnar, (Fri Apr 18, 9:36 am)
Re: StackProtector Oopses - Re: 2.6.25-mm1, Reuben Farrelly, (Fri Apr 18, 10:49 am)
Re: StackProtector Oopses - Re: 2.6.25-mm1, Ingo Molnar, (Mon Apr 21, 11:06 am)
Re: StackProtector Oopses - Re: 2.6.25-mm1, Arjan van de Ven, (Mon Apr 21, 9:48 pm)
Re: StackProtector Oopses - Re: 2.6.25-mm1, Ingo Molnar, (Tue Apr 22, 4:34 am)
Re: StackProtector Oopses - Re: 2.6.25-mm1, Arjan van de Ven, (Tue Apr 22, 10:29 am)
Re: StackProtector Oopses - Re: 2.6.25-mm1, Arjan van de Ven, (Fri Apr 18, 9:51 am)
Re: StackProtector Oopses - Re: 2.6.25-mm1, Reuben Farrelly, (Fri Apr 18, 10:41 am)
speck-geostationary