-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x86, olpc: Add OLPC device-tree support
Make use of PROC_DEVICETREE to export the tree, and sparc's PROMTREE code to call into OLPC's Open Firmware to build the tree. v5: fix buglet with root node check (introduced in v4) v4: address some minor style issues pointed out by Grant, and explicitly cast negative phandle checks to s32. v3: rename olpc_prom to olpc_dt - rework Kconfig entries - drop devtree build hook from proc, instead adding a call to x86's paging_init (similarly to how sparc64 does it) - switch allocation from using slab to alloc_bootmem. this allows the DT to be built earlier during boot (during setup_arch); the downside is that there are some 1200 bootmem reservations that are done during boot. Not ideal.. - add a helper olpc_ofw_is_installed function to test for the existence and successful detection of OLPC's OFW. Signed-off-by: Andres Salomon <dilinger@queued.net> LKML-Reference: <20101116220952.26526a80@queued.net> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
- Loading branch information
Andres Salomon
authored and
H. Peter Anvin
committed
Dec 16, 2010
1 parent
4722d19
commit c10d1e2
Showing
7 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* dummy prom.h; here to make linux/of.h's #includes happy */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
obj-$(CONFIG_OLPC) += olpc.o | ||
obj-$(CONFIG_OLPC_XO1) += olpc-xo1.o | ||
obj-$(CONFIG_OLPC_OPENFIRMWARE) += olpc_ofw.o | ||
obj-$(CONFIG_OLPC_OPENFIRMWARE_DT) += olpc_dt.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/* | ||
* OLPC-specific OFW device tree support code. | ||
* | ||
* Paul Mackerras August 1996. | ||
* Copyright (C) 1996-2005 Paul Mackerras. | ||
* | ||
* Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner. | ||
* {engebret|bergner}@us.ibm.com | ||
* | ||
* Adapted for sparc by David S. Miller davem@davemloft.net | ||
* Adapted for x86/OLPC by Andres Salomon <dilinger@queued.net> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version | ||
* 2 of the License, or (at your option) any later version. | ||
*/ | ||
|
||
#include <linux/kernel.h> | ||
#include <linux/bootmem.h> | ||
#include <linux/of.h> | ||
#include <linux/of_pdt.h> | ||
#include <asm/olpc_ofw.h> | ||
|
||
static phandle __init olpc_dt_getsibling(phandle node) | ||
{ | ||
const void *args[] = { (void *)node }; | ||
void *res[] = { &node }; | ||
|
||
if ((s32)node == -1) | ||
return 0; | ||
|
||
if (olpc_ofw("peer", args, res) || (s32)node == -1) | ||
return 0; | ||
|
||
return node; | ||
} | ||
|
||
static phandle __init olpc_dt_getchild(phandle node) | ||
{ | ||
const void *args[] = { (void *)node }; | ||
void *res[] = { &node }; | ||
|
||
if ((s32)node == -1) | ||
return 0; | ||
|
||
if (olpc_ofw("child", args, res) || (s32)node == -1) { | ||
pr_err("PROM: %s: fetching child failed!\n", __func__); | ||
return 0; | ||
} | ||
|
||
return node; | ||
} | ||
|
||
static int __init olpc_dt_getproplen(phandle node, const char *prop) | ||
{ | ||
const void *args[] = { (void *)node, prop }; | ||
int len; | ||
void *res[] = { &len }; | ||
|
||
if ((s32)node == -1) | ||
return -1; | ||
|
||
if (olpc_ofw("getproplen", args, res)) { | ||
pr_err("PROM: %s: getproplen failed!\n", __func__); | ||
return -1; | ||
} | ||
|
||
return len; | ||
} | ||
|
||
static int __init olpc_dt_getproperty(phandle node, const char *prop, | ||
char *buf, int bufsize) | ||
{ | ||
int plen; | ||
|
||
plen = olpc_dt_getproplen(node, prop); | ||
if (plen > bufsize || plen < 1) { | ||
return -1; | ||
} else { | ||
const void *args[] = { (void *)node, prop, buf, (void *)plen }; | ||
void *res[] = { &plen }; | ||
|
||
if (olpc_ofw("getprop", args, res)) { | ||
pr_err("PROM: %s: getprop failed!\n", __func__); | ||
return -1; | ||
} | ||
} | ||
|
||
return plen; | ||
} | ||
|
||
static int __init olpc_dt_nextprop(phandle node, char *prev, char *buf) | ||
{ | ||
const void *args[] = { (void *)node, prev, buf }; | ||
int success; | ||
void *res[] = { &success }; | ||
|
||
buf[0] = '\0'; | ||
|
||
if ((s32)node == -1) | ||
return -1; | ||
|
||
if (olpc_ofw("nextprop", args, res) || success != 1) | ||
return -1; | ||
|
||
return 0; | ||
} | ||
|
||
static int __init olpc_dt_pkg2path(phandle node, char *buf, | ||
const int buflen, int *len) | ||
{ | ||
const void *args[] = { (void *)node, buf, (void *)buflen }; | ||
void *res[] = { len }; | ||
|
||
if ((s32)node == -1) | ||
return -1; | ||
|
||
if (olpc_ofw("package-to-path", args, res) || *len < 1) | ||
return -1; | ||
|
||
return 0; | ||
} | ||
|
||
static unsigned int prom_early_allocated __initdata; | ||
|
||
void * __init prom_early_alloc(unsigned long size) | ||
{ | ||
void *res; | ||
|
||
res = alloc_bootmem(size); | ||
if (res) | ||
memset(res, 0, size); | ||
|
||
prom_early_allocated += size; | ||
|
||
return res; | ||
} | ||
|
||
static struct of_pdt_ops prom_olpc_ops __initdata = { | ||
.nextprop = olpc_dt_nextprop, | ||
.getproplen = olpc_dt_getproplen, | ||
.getproperty = olpc_dt_getproperty, | ||
.getchild = olpc_dt_getchild, | ||
.getsibling = olpc_dt_getsibling, | ||
.pkg2path = olpc_dt_pkg2path, | ||
}; | ||
|
||
void __init olpc_dt_build_devicetree(void) | ||
{ | ||
phandle root; | ||
|
||
if (!olpc_ofw_is_installed()) | ||
return; | ||
|
||
root = olpc_dt_getsibling(0); | ||
if (!root) { | ||
pr_err("PROM: unable to get root node from OFW!\n"); | ||
return; | ||
} | ||
of_pdt_build_devicetree(root, &prom_olpc_ops); | ||
|
||
pr_info("PROM DT: Built device tree with %u bytes of memory.\n", | ||
prom_early_allocated); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters