1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/init.h>
7 #include <asm/pgtable.h>
8 #include <asm/olpc_ofw.h>
10 /* address of OFW callback interface; will be NULL if OFW isn't found */
11 static int (*olpc_ofw_cif
)(int *);
13 /* page dir entry containing OFW's pgdir table; filled in by head_32.S */
14 u32 olpc_ofw_pgd __initdata
;
16 static DEFINE_SPINLOCK(ofw_lock
);
20 void __init
setup_olpc_ofw_pgd(void)
22 pgd_t
*base
, *ofw_pde
;
28 base
= early_ioremap(olpc_ofw_pgd
, sizeof(olpc_ofw_pgd
) * PTRS_PER_PGD
);
30 printk(KERN_ERR
"failed to remap OFW's pgd - disabling OFW!\n");
34 ofw_pde
= &base
[OLPC_OFW_PDE_NR
];
36 /* install OFW's PDE permanently into the kernel's pgtable */
37 set_pgd(&swapper_pg_dir
[OLPC_OFW_PDE_NR
], *ofw_pde
);
38 /* implicit optimization barrier here due to uninline function return */
40 early_iounmap(base
, sizeof(olpc_ofw_pgd
) * PTRS_PER_PGD
);
43 int __olpc_ofw(const char *name
, int nr_args
, const void **args
, int nr_res
,
46 int ofw_args
[MAXARGS
+ 3];
50 BUG_ON(nr_args
+ nr_res
> MAXARGS
);
55 ofw_args
[0] = (int)name
;
56 ofw_args
[1] = nr_args
;
60 for (i
= 0; i
< nr_args
; i
++, p
++)
64 spin_lock_irqsave(&ofw_lock
, flags
);
65 ret
= olpc_ofw_cif(ofw_args
);
66 spin_unlock_irqrestore(&ofw_lock
, flags
);
69 for (i
= 0; i
< nr_res
; i
++, p
++)
70 *((int *)res
[i
]) = *p
;
75 EXPORT_SYMBOL_GPL(__olpc_ofw
);
77 bool olpc_ofw_present(void)
79 return olpc_ofw_cif
!= NULL
;
81 EXPORT_SYMBOL_GPL(olpc_ofw_present
);
83 /* OFW cif _should_ be above this address */
84 #define OFW_MIN 0xff000000
86 /* OFW starts on a 1MB boundary */
87 #define OFW_BOUND (1<<20)
89 void __init
olpc_ofw_detect(void)
91 struct olpc_ofw_header
*hdr
= &boot_params
.olpc_ofw_header
;
94 /* ensure OFW booted us by checking for "OFW " string */
95 if (hdr
->ofw_magic
!= OLPC_OFW_SIG
)
98 olpc_ofw_cif
= (int (*)(int *))hdr
->cif_handler
;
100 if ((unsigned long)olpc_ofw_cif
< OFW_MIN
) {
101 printk(KERN_ERR
"OFW detected, but cif has invalid address 0x%lx - disabling.\n",
102 (unsigned long)olpc_ofw_cif
);
107 /* determine where OFW starts in memory */
108 start
= round_down((unsigned long)olpc_ofw_cif
, OFW_BOUND
);
109 printk(KERN_INFO
"OFW detected in memory, cif @ 0x%lx (reserving top %ldMB)\n",
110 (unsigned long)olpc_ofw_cif
, (-start
) >> 20);
111 reserve_top_address(-start
);
114 bool __init
olpc_ofw_is_installed(void)
116 return olpc_ofw_cif
!= NULL
;