1 #include <linux/kernel.h>
2 #include <linux/export.h>
3 #include <linux/spinlock_types.h>
4 #include <linux/init.h>
8 #include <asm/cpufeature.h>
9 #include <asm/special_insns.h>
10 #include <asm/pgtable.h>
11 #include <asm/olpc_ofw.h>
13 /* address of OFW callback interface; will be NULL if OFW isn't found */
14 static int (*olpc_ofw_cif
)(int *);
16 /* page dir entry containing OFW's pgdir table; filled in by head_32.S */
17 u32 olpc_ofw_pgd __initdata
;
19 static DEFINE_SPINLOCK(ofw_lock
);
23 void __init
setup_olpc_ofw_pgd(void)
25 pgd_t
*base
, *ofw_pde
;
31 base
= early_ioremap(olpc_ofw_pgd
, sizeof(olpc_ofw_pgd
) * PTRS_PER_PGD
);
33 printk(KERN_ERR
"failed to remap OFW's pgd - disabling OFW!\n");
37 ofw_pde
= &base
[OLPC_OFW_PDE_NR
];
39 /* install OFW's PDE permanently into the kernel's pgtable */
40 set_pgd(&swapper_pg_dir
[OLPC_OFW_PDE_NR
], *ofw_pde
);
41 /* implicit optimization barrier here due to uninline function return */
43 early_iounmap(base
, sizeof(olpc_ofw_pgd
) * PTRS_PER_PGD
);
46 int __olpc_ofw(const char *name
, int nr_args
, const void **args
, int nr_res
,
49 int ofw_args
[MAXARGS
+ 3];
53 BUG_ON(nr_args
+ nr_res
> MAXARGS
);
58 ofw_args
[0] = (int)name
;
59 ofw_args
[1] = nr_args
;
63 for (i
= 0; i
< nr_args
; i
++, p
++)
67 spin_lock_irqsave(&ofw_lock
, flags
);
68 ret
= olpc_ofw_cif(ofw_args
);
69 spin_unlock_irqrestore(&ofw_lock
, flags
);
72 for (i
= 0; i
< nr_res
; i
++, p
++)
73 *((int *)res
[i
]) = *p
;
78 EXPORT_SYMBOL_GPL(__olpc_ofw
);
80 bool olpc_ofw_present(void)
82 return olpc_ofw_cif
!= NULL
;
84 EXPORT_SYMBOL_GPL(olpc_ofw_present
);
86 /* OFW cif _should_ be above this address */
87 #define OFW_MIN 0xff000000
89 /* OFW starts on a 1MB boundary */
90 #define OFW_BOUND (1<<20)
92 void __init
olpc_ofw_detect(void)
94 struct olpc_ofw_header
*hdr
= &boot_params
.olpc_ofw_header
;
97 /* ensure OFW booted us by checking for "OFW " string */
98 if (hdr
->ofw_magic
!= OLPC_OFW_SIG
)
101 olpc_ofw_cif
= (int (*)(int *))hdr
->cif_handler
;
103 if ((unsigned long)olpc_ofw_cif
< OFW_MIN
) {
104 printk(KERN_ERR
"OFW detected, but cif has invalid address 0x%lx - disabling.\n",
105 (unsigned long)olpc_ofw_cif
);
110 /* determine where OFW starts in memory */
111 start
= round_down((unsigned long)olpc_ofw_cif
, OFW_BOUND
);
112 printk(KERN_INFO
"OFW detected in memory, cif @ 0x%lx (reserving top %ldMB)\n",
113 (unsigned long)olpc_ofw_cif
, (-start
) >> 20);
114 reserve_top_address(-start
);
117 bool __init
olpc_ofw_is_installed(void)
119 return olpc_ofw_cif
!= NULL
;