diff options
author | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
---|---|---|
committer | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
commit | c71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch) | |
tree | ecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /arch/x86/platform/olpc | |
parent | ea53c912f8a86a8567697115b6a0d8152beee5c8 (diff) | |
parent | 6a00f206debf8a5c8899055726ad127dbeeed098 (diff) |
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts:
litmus/sched_cedf.c
Diffstat (limited to 'arch/x86/platform/olpc')
-rw-r--r-- | arch/x86/platform/olpc/Makefile | 2 | ||||
-rw-r--r-- | arch/x86/platform/olpc/olpc-xo1.c | 146 | ||||
-rw-r--r-- | arch/x86/platform/olpc/olpc.c | 284 | ||||
-rw-r--r-- | arch/x86/platform/olpc/olpc_dt.c | 201 | ||||
-rw-r--r-- | arch/x86/platform/olpc/olpc_ofw.c | 117 |
5 files changed, 750 insertions, 0 deletions
diff --git a/arch/x86/platform/olpc/Makefile b/arch/x86/platform/olpc/Makefile new file mode 100644 index 000000000000..81c5e2165c24 --- /dev/null +++ b/arch/x86/platform/olpc/Makefile | |||
@@ -0,0 +1,2 @@ | |||
1 | obj-$(CONFIG_OLPC) += olpc.o olpc_ofw.o olpc_dt.o | ||
2 | obj-$(CONFIG_OLPC_XO1) += olpc-xo1.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..ab81fb271760 --- /dev/null +++ b/arch/x86/platform/olpc/olpc-xo1.c | |||
@@ -0,0 +1,146 @@ | |||
1 | /* | ||
2 | * Support for features of the OLPC XO-1 laptop | ||
3 | * | ||
4 | * Copyright (C) 2010 Andres Salomon <dilinger@queued.net> | ||
5 | * Copyright (C) 2010 One Laptop per Child | ||
6 | * Copyright (C) 2006 Red Hat, Inc. | ||
7 | * Copyright (C) 2006 Advanced Micro Devices, Inc. | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | */ | ||
14 | |||
15 | #include <linux/module.h> | ||
16 | #include <linux/platform_device.h> | ||
17 | #include <linux/pm.h> | ||
18 | #include <linux/mfd/core.h> | ||
19 | |||
20 | #include <asm/io.h> | ||
21 | #include <asm/olpc.h> | ||
22 | |||
23 | #define DRV_NAME "olpc-xo1" | ||
24 | |||
25 | /* PMC registers (PMS block) */ | ||
26 | #define PM_SCLK 0x10 | ||
27 | #define PM_IN_SLPCTL 0x20 | ||
28 | #define PM_WKXD 0x34 | ||
29 | #define PM_WKD 0x30 | ||
30 | #define PM_SSC 0x54 | ||
31 | |||
32 | /* PM registers (ACPI block) */ | ||
33 | #define PM1_CNT 0x08 | ||
34 | #define PM_GPE0_STS 0x18 | ||
35 | |||
36 | static unsigned long acpi_base; | ||
37 | static unsigned long pms_base; | ||
38 | |||
39 | static void xo1_power_off(void) | ||
40 | { | ||
41 | printk(KERN_INFO "OLPC XO-1 power off sequence...\n"); | ||
42 | |||
43 | /* Enable all of these controls with 0 delay */ | ||
44 | outl(0x40000000, pms_base + PM_SCLK); | ||
45 | outl(0x40000000, pms_base + PM_IN_SLPCTL); | ||
46 | outl(0x40000000, pms_base + PM_WKXD); | ||
47 | outl(0x40000000, pms_base + PM_WKD); | ||
48 | |||
49 | /* Clear status bits (possibly unnecessary) */ | ||
50 | outl(0x0002ffff, pms_base + PM_SSC); | ||
51 | outl(0xffffffff, acpi_base + PM_GPE0_STS); | ||
52 | |||
53 | /* Write SLP_EN bit to start the machinery */ | ||
54 | outl(0x00002000, acpi_base + PM1_CNT); | ||
55 | } | ||
56 | |||
57 | static int __devinit olpc_xo1_probe(struct platform_device *pdev) | ||
58 | { | ||
59 | struct resource *res; | ||
60 | int err; | ||
61 | |||
62 | /* don't run on non-XOs */ | ||
63 | if (!machine_is_olpc()) | ||
64 | return -ENODEV; | ||
65 | |||
66 | err = mfd_cell_enable(pdev); | ||
67 | if (err) | ||
68 | return err; | ||
69 | |||
70 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
71 | if (!res) { | ||
72 | dev_err(&pdev->dev, "can't fetch device resource info\n"); | ||
73 | return -EIO; | ||
74 | } | ||
75 | if (strcmp(pdev->name, "cs5535-pms") == 0) | ||
76 | pms_base = res->start; | ||
77 | else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0) | ||
78 | acpi_base = res->start; | ||
79 | |||
80 | /* If we have both addresses, we can override the poweroff hook */ | ||
81 | if (pms_base && acpi_base) { | ||
82 | pm_power_off = xo1_power_off; | ||
83 | printk(KERN_INFO "OLPC XO-1 support registered\n"); | ||
84 | } | ||
85 | |||
86 | return 0; | ||
87 | } | ||
88 | |||
89 | static int __devexit olpc_xo1_remove(struct platform_device *pdev) | ||
90 | { | ||
91 | mfd_cell_disable(pdev); | ||
92 | |||
93 | if (strcmp(pdev->name, "cs5535-pms") == 0) | ||
94 | pms_base = 0; | ||
95 | else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0) | ||
96 | acpi_base = 0; | ||
97 | |||
98 | pm_power_off = NULL; | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | static struct platform_driver cs5535_pms_drv = { | ||
103 | .driver = { | ||
104 | .name = "cs5535-pms", | ||
105 | .owner = THIS_MODULE, | ||
106 | }, | ||
107 | .probe = olpc_xo1_probe, | ||
108 | .remove = __devexit_p(olpc_xo1_remove), | ||
109 | }; | ||
110 | |||
111 | static struct platform_driver cs5535_acpi_drv = { | ||
112 | .driver = { | ||
113 | .name = "olpc-xo1-pm-acpi", | ||
114 | .owner = THIS_MODULE, | ||
115 | }, | ||
116 | .probe = olpc_xo1_probe, | ||
117 | .remove = __devexit_p(olpc_xo1_remove), | ||
118 | }; | ||
119 | |||
120 | static int __init olpc_xo1_init(void) | ||
121 | { | ||
122 | int r; | ||
123 | |||
124 | r = platform_driver_register(&cs5535_pms_drv); | ||
125 | if (r) | ||
126 | return r; | ||
127 | |||
128 | r = platform_driver_register(&cs5535_acpi_drv); | ||
129 | if (r) | ||
130 | platform_driver_unregister(&cs5535_pms_drv); | ||
131 | |||
132 | return r; | ||
133 | } | ||
134 | |||
135 | static void __exit olpc_xo1_exit(void) | ||
136 | { | ||
137 | platform_driver_unregister(&cs5535_acpi_drv); | ||
138 | platform_driver_unregister(&cs5535_pms_drv); | ||
139 | } | ||
140 | |||
141 | MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>"); | ||
142 | MODULE_LICENSE("GPL"); | ||
143 | MODULE_ALIAS("platform:cs5535-pms"); | ||
144 | |||
145 | module_init(olpc_xo1_init); | ||
146 | 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..0060fd59ea00 --- /dev/null +++ b/arch/x86/platform/olpc/olpc.c | |||
@@ -0,0 +1,284 @@ | |||
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 | #include <linux/of.h> | ||
22 | |||
23 | #include <asm/geode.h> | ||
24 | #include <asm/setup.h> | ||
25 | #include <asm/olpc.h> | ||
26 | #include <asm/olpc_ofw.h> | ||
27 | |||
28 | struct olpc_platform_t olpc_platform_info; | ||
29 | EXPORT_SYMBOL_GPL(olpc_platform_info); | ||
30 | |||
31 | static DEFINE_SPINLOCK(ec_lock); | ||
32 | |||
33 | /* what the timeout *should* be (in ms) */ | ||
34 | #define EC_BASE_TIMEOUT 20 | ||
35 | |||
36 | /* the timeout that bugs in the EC might force us to actually use */ | ||
37 | static int ec_timeout = EC_BASE_TIMEOUT; | ||
38 | |||
39 | static int __init olpc_ec_timeout_set(char *str) | ||
40 | { | ||
41 | if (get_option(&str, &ec_timeout) != 1) { | ||
42 | ec_timeout = EC_BASE_TIMEOUT; | ||
43 | printk(KERN_ERR "olpc-ec: invalid argument to " | ||
44 | "'olpc_ec_timeout=', ignoring!\n"); | ||
45 | } | ||
46 | printk(KERN_DEBUG "olpc-ec: using %d ms delay for EC commands.\n", | ||
47 | ec_timeout); | ||
48 | return 1; | ||
49 | } | ||
50 | __setup("olpc_ec_timeout=", olpc_ec_timeout_set); | ||
51 | |||
52 | /* | ||
53 | * These {i,o}bf_status functions return whether the buffers are full or not. | ||
54 | */ | ||
55 | |||
56 | static inline unsigned int ibf_status(unsigned int port) | ||
57 | { | ||
58 | return !!(inb(port) & 0x02); | ||
59 | } | ||
60 | |||
61 | static inline unsigned int obf_status(unsigned int port) | ||
62 | { | ||
63 | return inb(port) & 0x01; | ||
64 | } | ||
65 | |||
66 | #define wait_on_ibf(p, d) __wait_on_ibf(__LINE__, (p), (d)) | ||
67 | static int __wait_on_ibf(unsigned int line, unsigned int port, int desired) | ||
68 | { | ||
69 | unsigned int timeo; | ||
70 | int state = ibf_status(port); | ||
71 | |||
72 | for (timeo = ec_timeout; state != desired && timeo; timeo--) { | ||
73 | mdelay(1); | ||
74 | state = ibf_status(port); | ||
75 | } | ||
76 | |||
77 | if ((state == desired) && (ec_timeout > EC_BASE_TIMEOUT) && | ||
78 | timeo < (ec_timeout - EC_BASE_TIMEOUT)) { | ||
79 | printk(KERN_WARNING "olpc-ec: %d: waited %u ms for IBF!\n", | ||
80 | line, ec_timeout - timeo); | ||
81 | } | ||
82 | |||
83 | return !(state == desired); | ||
84 | } | ||
85 | |||
86 | #define wait_on_obf(p, d) __wait_on_obf(__LINE__, (p), (d)) | ||
87 | static int __wait_on_obf(unsigned int line, unsigned int port, int desired) | ||
88 | { | ||
89 | unsigned int timeo; | ||
90 | int state = obf_status(port); | ||
91 | |||
92 | for (timeo = ec_timeout; state != desired && timeo; timeo--) { | ||
93 | mdelay(1); | ||
94 | state = obf_status(port); | ||
95 | } | ||
96 | |||
97 | if ((state == desired) && (ec_timeout > EC_BASE_TIMEOUT) && | ||
98 | timeo < (ec_timeout - EC_BASE_TIMEOUT)) { | ||
99 | printk(KERN_WARNING "olpc-ec: %d: waited %u ms for OBF!\n", | ||
100 | line, ec_timeout - timeo); | ||
101 | } | ||
102 | |||
103 | return !(state == desired); | ||
104 | } | ||
105 | |||
106 | /* | ||
107 | * This allows the kernel to run Embedded Controller commands. The EC is | ||
108 | * documented at <http://wiki.laptop.org/go/Embedded_controller>, and the | ||
109 | * available EC commands are here: | ||
110 | * <http://wiki.laptop.org/go/Ec_specification>. Unfortunately, while | ||
111 | * OpenFirmware's source is available, the EC's is not. | ||
112 | */ | ||
113 | int olpc_ec_cmd(unsigned char cmd, unsigned char *inbuf, size_t inlen, | ||
114 | unsigned char *outbuf, size_t outlen) | ||
115 | { | ||
116 | unsigned long flags; | ||
117 | int ret = -EIO; | ||
118 | int i; | ||
119 | int restarts = 0; | ||
120 | |||
121 | spin_lock_irqsave(&ec_lock, flags); | ||
122 | |||
123 | /* Clear OBF */ | ||
124 | for (i = 0; i < 10 && (obf_status(0x6c) == 1); i++) | ||
125 | inb(0x68); | ||
126 | if (i == 10) { | ||
127 | printk(KERN_ERR "olpc-ec: timeout while attempting to " | ||
128 | "clear OBF flag!\n"); | ||
129 | goto err; | ||
130 | } | ||
131 | |||
132 | if (wait_on_ibf(0x6c, 0)) { | ||
133 | printk(KERN_ERR "olpc-ec: timeout waiting for EC to " | ||
134 | "quiesce!\n"); | ||
135 | goto err; | ||
136 | } | ||
137 | |||
138 | restart: | ||
139 | /* | ||
140 | * Note that if we time out during any IBF checks, that's a failure; | ||
141 | * we have to return. There's no way for the kernel to clear that. | ||
142 | * | ||
143 | * If we time out during an OBF check, we can restart the command; | ||
144 | * reissuing it will clear the OBF flag, and we should be alright. | ||
145 | * The OBF flag will sometimes misbehave due to what we believe | ||
146 | * is a hardware quirk.. | ||
147 | */ | ||
148 | pr_devel("olpc-ec: running cmd 0x%x\n", cmd); | ||
149 | outb(cmd, 0x6c); | ||
150 | |||
151 | if (wait_on_ibf(0x6c, 0)) { | ||
152 | printk(KERN_ERR "olpc-ec: timeout waiting for EC to read " | ||
153 | "command!\n"); | ||
154 | goto err; | ||
155 | } | ||
156 | |||
157 | if (inbuf && inlen) { | ||
158 | /* write data to EC */ | ||
159 | for (i = 0; i < inlen; i++) { | ||
160 | if (wait_on_ibf(0x6c, 0)) { | ||
161 | printk(KERN_ERR "olpc-ec: timeout waiting for" | ||
162 | " EC accept data!\n"); | ||
163 | goto err; | ||
164 | } | ||
165 | pr_devel("olpc-ec: sending cmd arg 0x%x\n", inbuf[i]); | ||
166 | outb(inbuf[i], 0x68); | ||
167 | } | ||
168 | } | ||
169 | if (outbuf && outlen) { | ||
170 | /* read data from EC */ | ||
171 | for (i = 0; i < outlen; i++) { | ||
172 | if (wait_on_obf(0x6c, 1)) { | ||
173 | printk(KERN_ERR "olpc-ec: timeout waiting for" | ||
174 | " EC to provide data!\n"); | ||
175 | if (restarts++ < 10) | ||
176 | goto restart; | ||
177 | goto err; | ||
178 | } | ||
179 | outbuf[i] = inb(0x68); | ||
180 | pr_devel("olpc-ec: received 0x%x\n", outbuf[i]); | ||
181 | } | ||
182 | } | ||
183 | |||
184 | ret = 0; | ||
185 | err: | ||
186 | spin_unlock_irqrestore(&ec_lock, flags); | ||
187 | return ret; | ||
188 | } | ||
189 | EXPORT_SYMBOL_GPL(olpc_ec_cmd); | ||
190 | |||
191 | static bool __init check_ofw_architecture(struct device_node *root) | ||
192 | { | ||
193 | const char *olpc_arch; | ||
194 | int propsize; | ||
195 | |||
196 | olpc_arch = of_get_property(root, "architecture", &propsize); | ||
197 | return propsize == 5 && strncmp("OLPC", olpc_arch, 5) == 0; | ||
198 | } | ||
199 | |||
200 | static u32 __init get_board_revision(struct device_node *root) | ||
201 | { | ||
202 | int propsize; | ||
203 | const __be32 *rev; | ||
204 | |||
205 | rev = of_get_property(root, "board-revision-int", &propsize); | ||
206 | if (propsize != 4) | ||
207 | return 0; | ||
208 | |||
209 | return be32_to_cpu(*rev); | ||
210 | } | ||
211 | |||
212 | static bool __init platform_detect(void) | ||
213 | { | ||
214 | struct device_node *root = of_find_node_by_path("/"); | ||
215 | bool success; | ||
216 | |||
217 | if (!root) | ||
218 | return false; | ||
219 | |||
220 | success = check_ofw_architecture(root); | ||
221 | if (success) { | ||
222 | olpc_platform_info.boardrev = get_board_revision(root); | ||
223 | olpc_platform_info.flags |= OLPC_F_PRESENT; | ||
224 | } | ||
225 | |||
226 | of_node_put(root); | ||
227 | return success; | ||
228 | } | ||
229 | |||
230 | static int __init add_xo1_platform_devices(void) | ||
231 | { | ||
232 | struct platform_device *pdev; | ||
233 | |||
234 | pdev = platform_device_register_simple("xo1-rfkill", -1, NULL, 0); | ||
235 | if (IS_ERR(pdev)) | ||
236 | return PTR_ERR(pdev); | ||
237 | |||
238 | pdev = platform_device_register_simple("olpc-xo1", -1, NULL, 0); | ||
239 | if (IS_ERR(pdev)) | ||
240 | return PTR_ERR(pdev); | ||
241 | |||
242 | return 0; | ||
243 | } | ||
244 | |||
245 | static int __init olpc_init(void) | ||
246 | { | ||
247 | int r = 0; | ||
248 | |||
249 | if (!olpc_ofw_present() || !platform_detect()) | ||
250 | return 0; | ||
251 | |||
252 | spin_lock_init(&ec_lock); | ||
253 | |||
254 | /* assume B1 and above models always have a DCON */ | ||
255 | if (olpc_board_at_least(olpc_board(0xb1))) | ||
256 | olpc_platform_info.flags |= OLPC_F_DCON; | ||
257 | |||
258 | /* get the EC revision */ | ||
259 | olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0, | ||
260 | (unsigned char *) &olpc_platform_info.ecver, 1); | ||
261 | |||
262 | #ifdef CONFIG_PCI_OLPC | ||
263 | /* If the VSA exists let it emulate PCI, if not emulate in kernel. | ||
264 | * XO-1 only. */ | ||
265 | if (olpc_platform_info.boardrev < olpc_board_pre(0xd0) && | ||
266 | !cs5535_has_vsa2()) | ||
267 | x86_init.pci.arch_init = pci_olpc_init; | ||
268 | #endif | ||
269 | |||
270 | printk(KERN_INFO "OLPC board revision %s%X (EC=%x)\n", | ||
271 | ((olpc_platform_info.boardrev & 0xf) < 8) ? "pre" : "", | ||
272 | olpc_platform_info.boardrev >> 4, | ||
273 | olpc_platform_info.ecver); | ||
274 | |||
275 | if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) { /* XO-1 */ | ||
276 | r = add_xo1_platform_devices(); | ||
277 | if (r) | ||
278 | return r; | ||
279 | } | ||
280 | |||
281 | return 0; | ||
282 | } | ||
283 | |||
284 | postcore_initcall(olpc_init); | ||
diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c new file mode 100644 index 000000000000..d39f63d017d2 --- /dev/null +++ b/arch/x86/platform/olpc/olpc_dt.c | |||
@@ -0,0 +1,201 @@ | |||
1 | /* | ||
2 | * OLPC-specific OFW device tree support code. | ||
3 | * | ||
4 | * Paul Mackerras August 1996. | ||
5 | * Copyright (C) 1996-2005 Paul Mackerras. | ||
6 | * | ||
7 | * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner. | ||
8 | * {engebret|bergner}@us.ibm.com | ||
9 | * | ||
10 | * Adapted for sparc by David S. Miller davem@davemloft.net | ||
11 | * Adapted for x86/OLPC by Andres Salomon <dilinger@queued.net> | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version | ||
16 | * 2 of the License, or (at your option) any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/bootmem.h> | ||
21 | #include <linux/of.h> | ||
22 | #include <linux/of_platform.h> | ||
23 | #include <linux/of_pdt.h> | ||
24 | #include <asm/olpc.h> | ||
25 | #include <asm/olpc_ofw.h> | ||
26 | |||
27 | static phandle __init olpc_dt_getsibling(phandle node) | ||
28 | { | ||
29 | const void *args[] = { (void *)node }; | ||
30 | void *res[] = { &node }; | ||
31 | |||
32 | if ((s32)node == -1) | ||
33 | return 0; | ||
34 | |||
35 | if (olpc_ofw("peer", args, res) || (s32)node == -1) | ||
36 | return 0; | ||
37 | |||
38 | return node; | ||
39 | } | ||
40 | |||
41 | static phandle __init olpc_dt_getchild(phandle node) | ||
42 | { | ||
43 | const void *args[] = { (void *)node }; | ||
44 | void *res[] = { &node }; | ||
45 | |||
46 | if ((s32)node == -1) | ||
47 | return 0; | ||
48 | |||
49 | if (olpc_ofw("child", args, res) || (s32)node == -1) { | ||
50 | pr_err("PROM: %s: fetching child failed!\n", __func__); | ||
51 | return 0; | ||
52 | } | ||
53 | |||
54 | return node; | ||
55 | } | ||
56 | |||
57 | static int __init olpc_dt_getproplen(phandle node, const char *prop) | ||
58 | { | ||
59 | const void *args[] = { (void *)node, prop }; | ||
60 | int len; | ||
61 | void *res[] = { &len }; | ||
62 | |||
63 | if ((s32)node == -1) | ||
64 | return -1; | ||
65 | |||
66 | if (olpc_ofw("getproplen", args, res)) { | ||
67 | pr_err("PROM: %s: getproplen failed!\n", __func__); | ||
68 | return -1; | ||
69 | } | ||
70 | |||
71 | return len; | ||
72 | } | ||
73 | |||
74 | static int __init olpc_dt_getproperty(phandle node, const char *prop, | ||
75 | char *buf, int bufsize) | ||
76 | { | ||
77 | int plen; | ||
78 | |||
79 | plen = olpc_dt_getproplen(node, prop); | ||
80 | if (plen > bufsize || plen < 1) { | ||
81 | return -1; | ||
82 | } else { | ||
83 | const void *args[] = { (void *)node, prop, buf, (void *)plen }; | ||
84 | void *res[] = { &plen }; | ||
85 | |||
86 | if (olpc_ofw("getprop", args, res)) { | ||
87 | pr_err("PROM: %s: getprop failed!\n", __func__); | ||
88 | return -1; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | return plen; | ||
93 | } | ||
94 | |||
95 | static int __init olpc_dt_nextprop(phandle node, char *prev, char *buf) | ||
96 | { | ||
97 | const void *args[] = { (void *)node, prev, buf }; | ||
98 | int success; | ||
99 | void *res[] = { &success }; | ||
100 | |||
101 | buf[0] = '\0'; | ||
102 | |||
103 | if ((s32)node == -1) | ||
104 | return -1; | ||
105 | |||
106 | if (olpc_ofw("nextprop", args, res) || success != 1) | ||
107 | return -1; | ||
108 | |||
109 | return 0; | ||
110 | } | ||
111 | |||
112 | static int __init olpc_dt_pkg2path(phandle node, char *buf, | ||
113 | const int buflen, int *len) | ||
114 | { | ||
115 | const void *args[] = { (void *)node, buf, (void *)buflen }; | ||
116 | void *res[] = { len }; | ||
117 | |||
118 | if ((s32)node == -1) | ||
119 | return -1; | ||
120 | |||
121 | if (olpc_ofw("package-to-path", args, res) || *len < 1) | ||
122 | return -1; | ||
123 | |||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | static unsigned int prom_early_allocated __initdata; | ||
128 | |||
129 | void * __init prom_early_alloc(unsigned long size) | ||
130 | { | ||
131 | static u8 *mem; | ||
132 | static size_t free_mem; | ||
133 | void *res; | ||
134 | |||
135 | if (free_mem < size) { | ||
136 | const size_t chunk_size = max(PAGE_SIZE, size); | ||
137 | |||
138 | /* | ||
139 | * To mimimize the number of allocations, grab at least | ||
140 | * PAGE_SIZE of memory (that's an arbitrary choice that's | ||
141 | * fast enough on the platforms we care about while minimizing | ||
142 | * wasted bootmem) and hand off chunks of it to callers. | ||
143 | */ | ||
144 | res = alloc_bootmem(chunk_size); | ||
145 | BUG_ON(!res); | ||
146 | prom_early_allocated += chunk_size; | ||
147 | memset(res, 0, chunk_size); | ||
148 | free_mem = chunk_size; | ||
149 | mem = res; | ||
150 | } | ||
151 | |||
152 | /* allocate from the local cache */ | ||
153 | free_mem -= size; | ||
154 | res = mem; | ||
155 | mem += size; | ||
156 | return res; | ||
157 | } | ||
158 | |||
159 | static struct of_pdt_ops prom_olpc_ops __initdata = { | ||
160 | .nextprop = olpc_dt_nextprop, | ||
161 | .getproplen = olpc_dt_getproplen, | ||
162 | .getproperty = olpc_dt_getproperty, | ||
163 | .getchild = olpc_dt_getchild, | ||
164 | .getsibling = olpc_dt_getsibling, | ||
165 | .pkg2path = olpc_dt_pkg2path, | ||
166 | }; | ||
167 | |||
168 | void __init olpc_dt_build_devicetree(void) | ||
169 | { | ||
170 | phandle root; | ||
171 | |||
172 | if (!olpc_ofw_is_installed()) | ||
173 | return; | ||
174 | |||
175 | root = olpc_dt_getsibling(0); | ||
176 | if (!root) { | ||
177 | pr_err("PROM: unable to get root node from OFW!\n"); | ||
178 | return; | ||
179 | } | ||
180 | of_pdt_build_devicetree(root, &prom_olpc_ops); | ||
181 | |||
182 | pr_info("PROM DT: Built device tree with %u bytes of memory.\n", | ||
183 | prom_early_allocated); | ||
184 | } | ||
185 | |||
186 | /* A list of DT node/bus matches that we want to expose as platform devices */ | ||
187 | static struct of_device_id __initdata of_ids[] = { | ||
188 | { .compatible = "olpc,xo1-battery" }, | ||
189 | { .compatible = "olpc,xo1-dcon" }, | ||
190 | { .compatible = "olpc,xo1-rtc" }, | ||
191 | {}, | ||
192 | }; | ||
193 | |||
194 | static int __init olpc_create_platform_devices(void) | ||
195 | { | ||
196 | if (machine_is_olpc()) | ||
197 | return of_platform_bus_probe(NULL, of_ids, NULL); | ||
198 | else | ||
199 | return 0; | ||
200 | } | ||
201 | device_initcall(olpc_create_platform_devices); | ||
diff --git a/arch/x86/platform/olpc/olpc_ofw.c b/arch/x86/platform/olpc/olpc_ofw.c new file mode 100644 index 000000000000..e7604f62870d --- /dev/null +++ b/arch/x86/platform/olpc/olpc_ofw.c | |||
@@ -0,0 +1,117 @@ | |||
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 | } | ||
113 | |||
114 | bool __init olpc_ofw_is_installed(void) | ||
115 | { | ||
116 | return olpc_ofw_cif != NULL; | ||
117 | } | ||