~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86/platform/olpc/olpc_ofw.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 #include <linux/kernel.h>
  3 #include <linux/export.h>
  4 #include <linux/spinlock_types.h>
  5 #include <linux/init.h>
  6 #include <linux/pgtable.h>
  7 #include <asm/page.h>
  8 #include <asm/setup.h>
  9 #include <asm/io.h>
 10 #include <asm/cpufeature.h>
 11 #include <asm/special_insns.h>
 12 #include <asm/olpc_ofw.h>
 13 
 14 /* address of OFW callback interface; will be NULL if OFW isn't found */
 15 static int (*olpc_ofw_cif)(int *);
 16 
 17 /* page dir entry containing OFW's pgdir table; filled in by head_32.S */
 18 u32 olpc_ofw_pgd __initdata;
 19 
 20 static DEFINE_SPINLOCK(ofw_lock);
 21 
 22 #define MAXARGS 10
 23 
 24 void __init setup_olpc_ofw_pgd(void)
 25 {
 26         pgd_t *base, *ofw_pde;
 27 
 28         if (!olpc_ofw_cif)
 29                 return;
 30 
 31         /* fetch OFW's PDE */
 32         base = early_ioremap(olpc_ofw_pgd, sizeof(olpc_ofw_pgd) * PTRS_PER_PGD);
 33         if (!base) {
 34                 printk(KERN_ERR "failed to remap OFW's pgd - disabling OFW!\n");
 35                 olpc_ofw_cif = NULL;
 36                 return;
 37         }
 38         ofw_pde = &base[OLPC_OFW_PDE_NR];
 39 
 40         /* install OFW's PDE permanently into the kernel's pgtable */
 41         set_pgd(&swapper_pg_dir[OLPC_OFW_PDE_NR], *ofw_pde);
 42         /* implicit optimization barrier here due to uninline function return */
 43 
 44         early_iounmap(base, sizeof(olpc_ofw_pgd) * PTRS_PER_PGD);
 45 }
 46 
 47 int __olpc_ofw(const char *name, int nr_args, const void **args, int nr_res,
 48                 void **res)
 49 {
 50         int ofw_args[MAXARGS + 3];
 51         unsigned long flags;
 52         int ret, i, *p;
 53 
 54         BUG_ON(nr_args + nr_res > MAXARGS);
 55 
 56         if (!olpc_ofw_cif)
 57                 return -EIO;
 58 
 59         ofw_args[0] = (int)name;
 60         ofw_args[1] = nr_args;
 61         ofw_args[2] = nr_res;
 62 
 63         p = &ofw_args[3];
 64         for (i = 0; i < nr_args; i++, p++)
 65                 *p = (int)args[i];
 66 
 67         /* call into ofw */
 68         spin_lock_irqsave(&ofw_lock, flags);
 69         ret = olpc_ofw_cif(ofw_args);
 70         spin_unlock_irqrestore(&ofw_lock, flags);
 71 
 72         if (!ret) {
 73                 for (i = 0; i < nr_res; i++, p++)
 74                         *((int *)res[i]) = *p;
 75         }
 76 
 77         return ret;
 78 }
 79 EXPORT_SYMBOL_GPL(__olpc_ofw);
 80 
 81 bool olpc_ofw_present(void)
 82 {
 83         return olpc_ofw_cif != NULL;
 84 }
 85 EXPORT_SYMBOL_GPL(olpc_ofw_present);
 86 
 87 /* OFW cif _should_ be above this address */
 88 #define OFW_MIN 0xff000000
 89 
 90 /* OFW starts on a 1MB boundary */
 91 #define OFW_BOUND (1<<20)
 92 
 93 void __init olpc_ofw_detect(void)
 94 {
 95         struct olpc_ofw_header *hdr = &boot_params.olpc_ofw_header;
 96         unsigned long start;
 97 
 98         /* ensure OFW booted us by checking for "OFW " string */
 99         if (hdr->ofw_magic != OLPC_OFW_SIG)
100                 return;
101 
102         olpc_ofw_cif = (int (*)(int *))hdr->cif_handler;
103 
104         if ((unsigned long)olpc_ofw_cif < OFW_MIN) {
105                 printk(KERN_ERR "OFW detected, but cif has invalid address 0x%lx - disabling.\n",
106                                 (unsigned long)olpc_ofw_cif);
107                 olpc_ofw_cif = NULL;
108                 return;
109         }
110 
111         /* determine where OFW starts in memory */
112         start = round_down((unsigned long)olpc_ofw_cif, OFW_BOUND);
113         printk(KERN_INFO "OFW detected in memory, cif @ 0x%lx (reserving top %ldMB)\n",
114                         (unsigned long)olpc_ofw_cif, (-start) >> 20);
115         reserve_top_address(-start);
116 }
117 
118 bool __init olpc_ofw_is_installed(void)
119 {
120         return olpc_ofw_cif != NULL;
121 }
122 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php