WIP FPC-III support
[linux/fpc-iii.git] / arch / powerpc / boot / planetcore.c
blobd5f391e342bedaf424d3d6738bac574efb9678d8
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * PlanetCore configuration data support functions
5 * Author: Scott Wood <scottwood@freescale.com>
7 * Copyright (c) 2007 Freescale Semiconductor, Inc.
8 */
10 #include "stdio.h"
11 #include "stdlib.h"
12 #include "ops.h"
13 #include "planetcore.h"
14 #include "io.h"
16 /* PlanetCore passes information to the OS in the form of
17 * a table of key=value strings, separated by newlines.
19 * The list is terminated by an empty string (i.e. two
20 * consecutive newlines).
22 * To make it easier to parse, we first convert all the
23 * newlines into null bytes.
26 void planetcore_prepare_table(char *table)
28 do {
29 if (*table == '\n')
30 *table = 0;
32 table++;
33 } while (*(table - 1) || *table != '\n');
35 *table = 0;
38 const char *planetcore_get_key(const char *table, const char *key)
40 int keylen = strlen(key);
42 do {
43 if (!strncmp(table, key, keylen) && table[keylen] == '=')
44 return table + keylen + 1;
46 table += strlen(table) + 1;
47 } while (strlen(table) != 0);
49 return NULL;
52 int planetcore_get_decimal(const char *table, const char *key, u64 *val)
54 const char *str = planetcore_get_key(table, key);
55 if (!str)
56 return 0;
58 *val = strtoull(str, NULL, 10);
59 return 1;
62 int planetcore_get_hex(const char *table, const char *key, u64 *val)
64 const char *str = planetcore_get_key(table, key);
65 if (!str)
66 return 0;
68 *val = strtoull(str, NULL, 16);
69 return 1;
72 static u64 mac_table[4] = {
73 0x000000000000,
74 0x000000800000,
75 0x000000400000,
76 0x000000c00000,
79 void planetcore_set_mac_addrs(const char *table)
81 u8 addr[4][6];
82 u64 int_addr;
83 u32 i;
84 int j;
86 if (!planetcore_get_hex(table, PLANETCORE_KEY_MAC_ADDR, &int_addr))
87 return;
89 for (i = 0; i < 4; i++) {
90 u64 this_dev_addr = (int_addr & ~0x000000c00000) |
91 mac_table[i];
93 for (j = 5; j >= 0; j--) {
94 addr[i][j] = this_dev_addr & 0xff;
95 this_dev_addr >>= 8;
98 dt_fixup_mac_address(i, addr[i]);
102 static char prop_buf[MAX_PROP_LEN];
104 void planetcore_set_stdout_path(const char *table)
106 char *path;
107 const char *label;
108 void *node, *chosen;
110 label = planetcore_get_key(table, PLANETCORE_KEY_SERIAL_PORT);
111 if (!label)
112 return;
114 node = find_node_by_prop_value_str(NULL, "linux,planetcore-label",
115 label);
116 if (!node)
117 return;
119 path = get_path(node, prop_buf, MAX_PROP_LEN);
120 if (!path)
121 return;
123 chosen = finddevice("/chosen");
124 if (!chosen)
125 chosen = create_node(NULL, "chosen");
126 if (!chosen)
127 return;
129 setprop_str(chosen, "linux,stdout-path", path);