diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2010-10-23 05:28:42 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-10-27 11:22:16 -0400 |
commit | 8654b1c2de1465120974899fc1c8aa00e91d4b7e (patch) | |
tree | 2bfe8cd3cb0caadf8be0bdf6574690e476173f75 /arch/x86/platform | |
parent | 329b84e42e3ee348b114fd0bfe4b2421e6139257 (diff) |
x86: Move olpc to platform
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Andres Salomon <dilinger@queued.net>
Diffstat (limited to 'arch/x86/platform')
-rw-r--r-- | arch/x86/platform/Makefile | 1 | ||||
-rw-r--r-- | arch/x86/platform/olpc/Makefile | 3 | ||||
-rw-r--r-- | arch/x86/platform/olpc/olpc-xo1.c | 140 | ||||
-rw-r--r-- | arch/x86/platform/olpc/olpc.c | 281 | ||||
-rw-r--r-- | arch/x86/platform/olpc/olpc_ofw.c | 112 |
5 files changed, 537 insertions, 0 deletions
diff --git a/arch/x86/platform/Makefile b/arch/x86/platform/Makefile index 8519b01f1acb..7bf70b812fa2 100644 --- a/arch/x86/platform/Makefile +++ b/arch/x86/platform/Makefile | |||
@@ -1,6 +1,7 @@ | |||
1 | # Platform specific code goes here | 1 | # Platform specific code goes here |
2 | obj-y += efi/ | 2 | obj-y += efi/ |
3 | obj-y += mrst/ | 3 | obj-y += mrst/ |
4 | obj-y += olpc/ | ||
4 | obj-y += scx200/ | 5 | obj-y += scx200/ |
5 | obj-y += sfi/ | 6 | obj-y += sfi/ |
6 | obj-y += visws/ | 7 | obj-y += visws/ |
diff --git a/arch/x86/platform/olpc/Makefile b/arch/x86/platform/olpc/Makefile new file mode 100644 index 000000000000..c31b8fcb5a86 --- /dev/null +++ b/arch/x86/platform/olpc/Makefile | |||
@@ -0,0 +1,3 @@ | |||
1 | obj-$(CONFIG_OLPC) += olpc.o | ||
2 | obj-$(CONFIG_OLPC_XO1) += olpc-xo1.o | ||
3 | obj-$(CONFIG_OLPC_OPENFIRMWARE) += olpc_ofw.o | ||
diff --git a/arch/x86/platform/olpc/olpc-xo1.c b/arch/x86/platform/olpc/olpc-xo1.c new file mode 100644 index 000000000000..f5442c03abc3 --- /dev/null +++ b/arch/x86/platform/olpc/olpc-xo1.c | |||
@@ -0,0 +1,140 @@ | |||
1 | /* | ||
2 | * Support for features of the OLPC XO-1 laptop | ||
3 | * | ||
4 | * Copyright (C) 2010 One Laptop per Child | ||
5 | * Copyright (C) 2006 Red Hat, Inc. | ||
6 | * Copyright (C) 2006 Advanced Micro Devices, Inc. | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | */ | ||
13 | |||
14 | #include <linux/module.h> | ||
15 | #include <linux/pci.h> | ||
16 | #include <linux/pci_ids.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/pm.h> | ||
19 | |||
20 | #include <asm/io.h> | ||
21 | #include <asm/olpc.h> | ||
22 | |||
23 | #define DRV_NAME "olpc-xo1" | ||
24 | |||
25 | #define PMS_BAR 4 | ||
26 | #define ACPI_BAR 5 | ||
27 | |||
28 | /* PMC registers (PMS block) */ | ||
29 | #define PM_SCLK 0x10 | ||
30 | #define PM_IN_SLPCTL 0x20 | ||
31 | #define PM_WKXD 0x34 | ||
32 | #define PM_WKD 0x30 | ||
33 | #define PM_SSC 0x54 | ||
34 | |||
35 | /* PM registers (ACPI block) */ | ||
36 | #define PM1_CNT 0x08 | ||
37 | #define PM_GPE0_STS 0x18 | ||
38 | |||
39 | static unsigned long acpi_base; | ||
40 | static unsigned long pms_base; | ||
41 | |||
42 | static void xo1_power_off(void) | ||
43 | { | ||
44 | printk(KERN_INFO "OLPC XO-1 power off sequence...\n"); | ||
45 | |||
46 | /* Enable all of these controls with 0 delay */ | ||
47 | outl(0x40000000, pms_base + PM_SCLK); | ||
48 | outl(0x40000000, pms_base + PM_IN_SLPCTL); | ||
49 | outl(0x40000000, pms_base + PM_WKXD); | ||
50 | outl(0x40000000, pms_base + PM_WKD); | ||
51 | |||
52 | /* Clear status bits (possibly unnecessary) */ | ||
53 | outl(0x0002ffff, pms_base + PM_SSC); | ||
54 | outl(0xffffffff, acpi_base + PM_GPE0_STS); | ||
55 | |||
56 | /* Write SLP_EN bit to start the machinery */ | ||
57 | outl(0x00002000, acpi_base + PM1_CNT); | ||
58 | } | ||
59 | |||
60 | /* Read the base addresses from the PCI BAR info */ | ||
61 | static int __devinit setup_bases(struct pci_dev *pdev) | ||
62 | { | ||
63 | int r; | ||
64 | |||
65 | r = pci_enable_device_io(pdev); | ||
66 | if (r) { | ||
67 | dev_err(&pdev->dev, "can't enable device IO\n"); | ||
68 | return r; | ||
69 | } | ||
70 | |||
71 | r = pci_request_region(pdev, ACPI_BAR, DRV_NAME); | ||
72 | if (r) { | ||
73 | dev_err(&pdev->dev, "can't alloc PCI BAR #%d\n", ACPI_BAR); | ||
74 | return r; | ||
75 | } | ||
76 | |||
77 | r = pci_request_region(pdev, PMS_BAR, DRV_NAME); | ||
78 | if (r) { | ||
79 | dev_err(&pdev->dev, "can't alloc PCI BAR #%d\n", PMS_BAR); | ||
80 | pci_release_region(pdev, ACPI_BAR); | ||
81 | return r; | ||
82 | } | ||
83 | |||
84 | acpi_base = pci_resource_start(pdev, ACPI_BAR); | ||
85 | pms_base = pci_resource_start(pdev, PMS_BAR); | ||
86 | |||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | static int __devinit olpc_xo1_probe(struct platform_device *pdev) | ||
91 | { | ||
92 | struct pci_dev *pcidev; | ||
93 | int r; | ||
94 | |||
95 | pcidev = pci_get_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA, | ||
96 | NULL); | ||
97 | if (!pdev) | ||
98 | return -ENODEV; | ||
99 | |||
100 | r = setup_bases(pcidev); | ||
101 | if (r) | ||
102 | return r; | ||
103 | |||
104 | pm_power_off = xo1_power_off; | ||
105 | |||
106 | printk(KERN_INFO "OLPC XO-1 support registered\n"); | ||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | static int __devexit olpc_xo1_remove(struct platform_device *pdev) | ||
111 | { | ||
112 | pm_power_off = NULL; | ||
113 | return 0; | ||
114 | } | ||
115 | |||
116 | static struct platform_driver olpc_xo1_driver = { | ||
117 | .driver = { | ||
118 | .name = DRV_NAME, | ||
119 | .owner = THIS_MODULE, | ||
120 | }, | ||
121 | .probe = olpc_xo1_probe, | ||
122 | .remove = __devexit_p(olpc_xo1_remove), | ||
123 | }; | ||
124 | |||
125 | static int __init olpc_xo1_init(void) | ||
126 | { | ||
127 | return platform_driver_register(&olpc_xo1_driver); | ||
128 | } | ||
129 | |||
130 | static void __exit olpc_xo1_exit(void) | ||
131 | { | ||
132 | platform_driver_unregister(&olpc_xo1_driver); | ||
133 | } | ||
134 | |||
135 | MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>"); | ||
136 | MODULE_LICENSE("GPL"); | ||
137 | MODULE_ALIAS("platform:olpc-xo1"); | ||
138 | |||
139 | module_init(olpc_xo1_init); | ||
140 | module_exit(olpc_xo1_exit); | ||
diff --git a/arch/x86/platform/olpc/olpc.c b/arch/x86/platform/olpc/olpc.c new file mode 100644 index 000000000000..edaf3fe8dc5e --- /dev/null +++ b/arch/x86/platform/olpc/olpc.c | |||
@@ -0,0 +1,281 @@ | |||
1 | /* | ||
2 | * Support for the OLPC DCON and OLPC EC access | ||
3 | * | ||
4 | * Copyright © 2006 Advanced Micro Devices, Inc. | ||
5 | * Copyright © 2007-2008 Andres Salomon <dilinger@debian.org> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | */ | ||
12 | |||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/delay.h> | ||
17 | #include <linux/spinlock.h> | ||
18 | #include <linux/io.h> | ||
19 | #include <linux/string.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | |||
22 | #include <asm/geode.h> | ||
23 | #include <asm/setup.h> | ||
24 | #include <asm/olpc.h> | ||
25 | #include <asm/olpc_ofw.h> | ||
26 | |||
27 | struct olpc_platform_t olpc_platform_info; | ||
28 | EXPORT_SYMBOL_GPL(olpc_platform_info); | ||
29 | |||
30 | static DEFINE_SPINLOCK(ec_lock); | ||
31 | |||
32 | /* what the timeout *should* be (in ms) */ | ||
33 | #define EC_BASE_TIMEOUT 20 | ||
34 | |||
35 | /* the timeout that bugs in the EC might force us to actually use */ | ||
36 | static int ec_timeout = EC_BASE_TIMEOUT; | ||
37 | |||
38 | static int __init olpc_ec_timeout_set(char *str) | ||
39 | { | ||
40 | if (get_option(&str, &ec_timeout) != 1) { | ||
41 | ec_timeout = EC_BASE_TIMEOUT; | ||
42 | printk(KERN_ERR "olpc-ec: invalid argument to " | ||
43 | "'olpc_ec_timeout=', ignoring!\n"); | ||
44 | } | ||
45 | printk(KERN_DEBUG "olpc-ec: using %d ms delay for EC commands.\n", | ||
46 | ec_timeout); | ||
47 | return 1; | ||
48 | } | ||
49 | __setup("olpc_ec_timeout=", olpc_ec_timeout_set); | ||
50 | |||
51 | /* | ||
52 | * These {i,o}bf_status functions return whether the buffers are full or not. | ||
53 | */ | ||
54 | |||
55 | static inline unsigned int ibf_status(unsigned int port) | ||
56 | { | ||
57 | return !!(inb(port) & 0x02); | ||
58 | } | ||
59 | |||
60 | static inline unsigned int obf_status(unsigned int port) | ||
61 | { | ||
62 | return inb(port) & 0x01; | ||
63 | } | ||
64 | |||
65 | #define wait_on_ibf(p, d) __wait_on_ibf(__LINE__, (p), (d)) | ||
66 | static int __wait_on_ibf(unsigned int line, unsigned int port, int desired) | ||
67 | { | ||
68 | unsigned int timeo; | ||
69 | int state = ibf_status(port); | ||
70 | |||
71 | for (timeo = ec_timeout; state != desired && timeo; timeo--) { | ||
72 | mdelay(1); | ||
73 | state = ibf_status(port); | ||
74 | } | ||
75 | |||
76 | if ((state == desired) && (ec_timeout > EC_BASE_TIMEOUT) && | ||
77 | timeo < (ec_timeout - EC_BASE_TIMEOUT)) { | ||
78 | printk(KERN_WARNING "olpc-ec: %d: waited %u ms for IBF!\n", | ||
79 | line, ec_timeout - timeo); | ||
80 | } | ||
81 | |||
82 | return !(state == desired); | ||
83 | } | ||
84 | |||
85 | #define wait_on_obf(p, d) __wait_on_obf(__LINE__, (p), (d)) | ||
86 | static int __wait_on_obf(unsigned int line, unsigned int port, int desired) | ||
87 | { | ||
88 | unsigned int timeo; | ||
89 | int state = obf_status(port); | ||
90 | |||
91 | for (timeo = ec_timeout; state != desired && timeo; timeo--) { | ||
92 | mdelay(1); | ||
93 | state = obf_status(port); | ||
94 | } | ||
95 | |||
96 | if ((state == desired) && (ec_timeout > EC_BASE_TIMEOUT) && | ||
97 | timeo < (ec_timeout - EC_BASE_TIMEOUT)) { | ||
98 | printk(KERN_WARNING "olpc-ec: %d: waited %u ms for OBF!\n", | ||
99 | line, ec_timeout - timeo); | ||
100 | } | ||
101 | |||
102 | return !(state == desired); | ||
103 | } | ||
104 | |||
105 | /* | ||
106 | * This allows the kernel to run Embedded Controller commands. The EC is | ||
107 | * documented at <http://wiki.laptop.org/go/Embedded_controller>, and the | ||
108 | * available EC commands are here: | ||
109 | * <http://wiki.laptop.org/go/Ec_specification>. Unfortunately, while | ||
110 | * OpenFirmware's source is available, the EC's is not. | ||
111 | */ | ||
112 | int olpc_ec_cmd(unsigned char cmd, unsigned char *inbuf, size_t inlen, | ||
113 | unsigned char *outbuf, size_t outlen) | ||
114 | { | ||
115 | unsigned long flags; | ||
116 | int ret = -EIO; | ||
117 | int i; | ||
118 | int restarts = 0; | ||
119 | |||
120 | spin_lock_irqsave(&ec_lock, flags); | ||
121 | |||
122 | /* Clear OBF */ | ||
123 | for (i = 0; i < 10 && (obf_status(0x6c) == 1); i++) | ||
124 | inb(0x68); | ||
125 | if (i == 10) { | ||
126 | printk(KERN_ERR "olpc-ec: timeout while attempting to " | ||
127 | "clear OBF flag!\n"); | ||
128 | goto err; | ||
129 | } | ||
130 | |||
131 | if (wait_on_ibf(0x6c, 0)) { | ||
132 | printk(KERN_ERR "olpc-ec: timeout waiting for EC to " | ||
133 | "quiesce!\n"); | ||
134 | goto err; | ||
135 | } | ||
136 | |||
137 | restart: | ||
138 | /* | ||
139 | * Note that if we time out during any IBF checks, that's a failure; | ||
140 | * we have to return. There's no way for the kernel to clear that. | ||
141 | * | ||
142 | * If we time out during an OBF check, we can restart the command; | ||
143 | * reissuing it will clear the OBF flag, and we should be alright. | ||
144 | * The OBF flag will sometimes misbehave due to what we believe | ||
145 | * is a hardware quirk.. | ||
146 | */ | ||
147 | pr_devel("olpc-ec: running cmd 0x%x\n", cmd); | ||
148 | outb(cmd, 0x6c); | ||
149 | |||
150 | if (wait_on_ibf(0x6c, 0)) { | ||
151 | printk(KERN_ERR "olpc-ec: timeout waiting for EC to read " | ||
152 | "command!\n"); | ||
153 | goto err; | ||
154 | } | ||
155 | |||
156 | if (inbuf && inlen) { | ||
157 | /* write data to EC */ | ||
158 | for (i = 0; i < inlen; i++) { | ||
159 | if (wait_on_ibf(0x6c, 0)) { | ||
160 | printk(KERN_ERR "olpc-ec: timeout waiting for" | ||
161 | " EC accept data!\n"); | ||
162 | goto err; | ||
163 | } | ||
164 | pr_devel("olpc-ec: sending cmd arg 0x%x\n", inbuf[i]); | ||
165 | outb(inbuf[i], 0x68); | ||
166 | } | ||
167 | } | ||
168 | if (outbuf && outlen) { | ||
169 | /* read data from EC */ | ||
170 | for (i = 0; i < outlen; i++) { | ||
171 | if (wait_on_obf(0x6c, 1)) { | ||
172 | printk(KERN_ERR "olpc-ec: timeout waiting for" | ||
173 | " EC to provide data!\n"); | ||
174 | if (restarts++ < 10) | ||
175 | goto restart; | ||
176 | goto err; | ||
177 | } | ||
178 | outbuf[i] = inb(0x68); | ||
179 | pr_devel("olpc-ec: received 0x%x\n", outbuf[i]); | ||
180 | } | ||
181 | } | ||
182 | |||
183 | ret = 0; | ||
184 | err: | ||
185 | spin_unlock_irqrestore(&ec_lock, flags); | ||
186 | return ret; | ||
187 | } | ||
188 | EXPORT_SYMBOL_GPL(olpc_ec_cmd); | ||
189 | |||
190 | static bool __init check_ofw_architecture(void) | ||
191 | { | ||
192 | size_t propsize; | ||
193 | char olpc_arch[5]; | ||
194 | const void *args[] = { NULL, "architecture", olpc_arch, (void *)5 }; | ||
195 | void *res[] = { &propsize }; | ||
196 | |||
197 | if (olpc_ofw("getprop", args, res)) { | ||
198 | printk(KERN_ERR "ofw: getprop call failed!\n"); | ||
199 | return false; | ||
200 | } | ||
201 | return propsize == 5 && strncmp("OLPC", olpc_arch, 5) == 0; | ||
202 | } | ||
203 | |||
204 | static u32 __init get_board_revision(void) | ||
205 | { | ||
206 | size_t propsize; | ||
207 | __be32 rev; | ||
208 | const void *args[] = { NULL, "board-revision-int", &rev, (void *)4 }; | ||
209 | void *res[] = { &propsize }; | ||
210 | |||
211 | if (olpc_ofw("getprop", args, res) || propsize != 4) { | ||
212 | printk(KERN_ERR "ofw: getprop call failed!\n"); | ||
213 | return cpu_to_be32(0); | ||
214 | } | ||
215 | return be32_to_cpu(rev); | ||
216 | } | ||
217 | |||
218 | static bool __init platform_detect(void) | ||
219 | { | ||
220 | if (!check_ofw_architecture()) | ||
221 | return false; | ||
222 | olpc_platform_info.flags |= OLPC_F_PRESENT; | ||
223 | olpc_platform_info.boardrev = get_board_revision(); | ||
224 | return true; | ||
225 | } | ||
226 | |||
227 | static int __init add_xo1_platform_devices(void) | ||
228 | { | ||
229 | struct platform_device *pdev; | ||
230 | |||
231 | pdev = platform_device_register_simple("xo1-rfkill", -1, NULL, 0); | ||
232 | if (IS_ERR(pdev)) | ||
233 | return PTR_ERR(pdev); | ||
234 | |||
235 | pdev = platform_device_register_simple("olpc-xo1", -1, NULL, 0); | ||
236 | if (IS_ERR(pdev)) | ||
237 | return PTR_ERR(pdev); | ||
238 | |||
239 | return 0; | ||
240 | } | ||
241 | |||
242 | static int __init olpc_init(void) | ||
243 | { | ||
244 | int r = 0; | ||
245 | |||
246 | if (!olpc_ofw_present() || !platform_detect()) | ||
247 | return 0; | ||
248 | |||
249 | spin_lock_init(&ec_lock); | ||
250 | |||
251 | /* assume B1 and above models always have a DCON */ | ||
252 | if (olpc_board_at_least(olpc_board(0xb1))) | ||
253 | olpc_platform_info.flags |= OLPC_F_DCON; | ||
254 | |||
255 | /* get the EC revision */ | ||
256 | olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0, | ||
257 | (unsigned char *) &olpc_platform_info.ecver, 1); | ||
258 | |||
259 | #ifdef CONFIG_PCI_OLPC | ||
260 | /* If the VSA exists let it emulate PCI, if not emulate in kernel. | ||
261 | * XO-1 only. */ | ||
262 | if (olpc_platform_info.boardrev < olpc_board_pre(0xd0) && | ||
263 | !cs5535_has_vsa2()) | ||
264 | x86_init.pci.arch_init = pci_olpc_init; | ||
265 | #endif | ||
266 | |||
267 | printk(KERN_INFO "OLPC board revision %s%X (EC=%x)\n", | ||
268 | ((olpc_platform_info.boardrev & 0xf) < 8) ? "pre" : "", | ||
269 | olpc_platform_info.boardrev >> 4, | ||
270 | olpc_platform_info.ecver); | ||
271 | |||
272 | if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) { /* XO-1 */ | ||
273 | r = add_xo1_platform_devices(); | ||
274 | if (r) | ||
275 | return r; | ||
276 | } | ||
277 | |||
278 | return 0; | ||
279 | } | ||
280 | |||
281 | postcore_initcall(olpc_init); | ||
diff --git a/arch/x86/platform/olpc/olpc_ofw.c b/arch/x86/platform/olpc/olpc_ofw.c new file mode 100644 index 000000000000..787320464379 --- /dev/null +++ b/arch/x86/platform/olpc/olpc_ofw.c | |||
@@ -0,0 +1,112 @@ | |||
1 | #include <linux/kernel.h> | ||
2 | #include <linux/module.h> | ||
3 | #include <linux/init.h> | ||
4 | #include <asm/page.h> | ||
5 | #include <asm/setup.h> | ||
6 | #include <asm/io.h> | ||
7 | #include <asm/pgtable.h> | ||
8 | #include <asm/olpc_ofw.h> | ||
9 | |||
10 | /* address of OFW callback interface; will be NULL if OFW isn't found */ | ||
11 | static int (*olpc_ofw_cif)(int *); | ||
12 | |||
13 | /* page dir entry containing OFW's pgdir table; filled in by head_32.S */ | ||
14 | u32 olpc_ofw_pgd __initdata; | ||
15 | |||
16 | static DEFINE_SPINLOCK(ofw_lock); | ||
17 | |||
18 | #define MAXARGS 10 | ||
19 | |||
20 | void __init setup_olpc_ofw_pgd(void) | ||
21 | { | ||
22 | pgd_t *base, *ofw_pde; | ||
23 | |||
24 | if (!olpc_ofw_cif) | ||
25 | return; | ||
26 | |||
27 | /* fetch OFW's PDE */ | ||
28 | base = early_ioremap(olpc_ofw_pgd, sizeof(olpc_ofw_pgd) * PTRS_PER_PGD); | ||
29 | if (!base) { | ||
30 | printk(KERN_ERR "failed to remap OFW's pgd - disabling OFW!\n"); | ||
31 | olpc_ofw_cif = NULL; | ||
32 | return; | ||
33 | } | ||
34 | ofw_pde = &base[OLPC_OFW_PDE_NR]; | ||
35 | |||
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 */ | ||
39 | |||
40 | early_iounmap(base, sizeof(olpc_ofw_pgd) * PTRS_PER_PGD); | ||
41 | } | ||
42 | |||
43 | int __olpc_ofw(const char *name, int nr_args, const void **args, int nr_res, | ||
44 | void **res) | ||
45 | { | ||
46 | int ofw_args[MAXARGS + 3]; | ||
47 | unsigned long flags; | ||
48 | int ret, i, *p; | ||
49 | |||
50 | BUG_ON(nr_args + nr_res > MAXARGS); | ||
51 | |||
52 | if (!olpc_ofw_cif) | ||
53 | return -EIO; | ||
54 | |||
55 | ofw_args[0] = (int)name; | ||
56 | ofw_args[1] = nr_args; | ||
57 | ofw_args[2] = nr_res; | ||
58 | |||
59 | p = &ofw_args[3]; | ||
60 | for (i = 0; i < nr_args; i++, p++) | ||
61 | *p = (int)args[i]; | ||
62 | |||
63 | /* call into ofw */ | ||
64 | spin_lock_irqsave(&ofw_lock, flags); | ||
65 | ret = olpc_ofw_cif(ofw_args); | ||
66 | spin_unlock_irqrestore(&ofw_lock, flags); | ||
67 | |||
68 | if (!ret) { | ||
69 | for (i = 0; i < nr_res; i++, p++) | ||
70 | *((int *)res[i]) = *p; | ||
71 | } | ||
72 | |||
73 | return ret; | ||
74 | } | ||
75 | EXPORT_SYMBOL_GPL(__olpc_ofw); | ||
76 | |||
77 | bool olpc_ofw_present(void) | ||
78 | { | ||
79 | return olpc_ofw_cif != NULL; | ||
80 | } | ||
81 | EXPORT_SYMBOL_GPL(olpc_ofw_present); | ||
82 | |||
83 | /* OFW cif _should_ be above this address */ | ||
84 | #define OFW_MIN 0xff000000 | ||
85 | |||
86 | /* OFW starts on a 1MB boundary */ | ||
87 | #define OFW_BOUND (1<<20) | ||
88 | |||
89 | void __init olpc_ofw_detect(void) | ||
90 | { | ||
91 | struct olpc_ofw_header *hdr = &boot_params.olpc_ofw_header; | ||
92 | unsigned long start; | ||
93 | |||
94 | /* ensure OFW booted us by checking for "OFW " string */ | ||
95 | if (hdr->ofw_magic != OLPC_OFW_SIG) | ||
96 | return; | ||
97 | |||
98 | olpc_ofw_cif = (int (*)(int *))hdr->cif_handler; | ||
99 | |||
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); | ||
103 | olpc_ofw_cif = NULL; | ||
104 | return; | ||
105 | } | ||
106 | |||
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); | ||
112 | } | ||