1 /* promops.c: Prom node tree operations and Prom Vector initialization 2 * initialization routines. 3 * 4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 5 */ 6
7 #include <linux/kernel.h>
8
9 #include <asm/openprom.h>
10
11 /* #define DEBUG_PROMOPS */ 12 #defineMAX_PR_LEN 16 /* exotic hardware probably overshoots this */ 13
14 intprom_node_root; /* initialized in init_prom */ 15
16 externstructlinux_romvec *romvec;
17
18 /* These two functions return and siblings and direct child descendents 19 * in the prom device tree respectively. 20 */ 21
22 int 23 node_get_sibling(intnode)
/* */ 24 { 25 return (*(romvec->pv_nodeops->no_nextnode))(node);
26 } 27
28 int 29 node_get_child(intnode)
/* */ 30 { 31 return (*(romvec->pv_nodeops->no_child))(node);
32 } 33
34 /* The following routine is used during device probing to determine 35 * an integer value property about a (perhaps virtual) device. This 36 * could be anything, like the size of the mmu cache lines, etc. 37 * the default return value is -1 is the prom has nothing interesting. 38 */ 39
40 unsignedint *
41 get_int_from_prom(intnode, char *nd_prop, unsignedint *value)
/* */ 42 { 43 unsignedintpr_len;
44
45 *value = 0; /* duh, I was returning -1 as an unsigned int, prom_panic() */ 46
47 pr_len = romvec->pv_nodeops->no_proplen(node, nd_prop);
48 if(pr_len > MAX_PR_LEN)
49 { 50 #ifdefDEBUG_PROMOPS 51 printk("Bad pr_len in promops -- node: %d nd_prop: %s pr_len: %d",
52 node, nd_prop, (int) pr_len);
53 #endif 54 returnvalue; /* XXX */ 55 } 56
57 romvec->pv_nodeops->no_getprop(node, nd_prop, (char *) value);
58
59 returnvalue;
60 } 61
62
63 /* This routine returns what is termed a property string as opposed 64 * to a property integer as above. This can be used to extract the 65 * 'type' of device from the prom. An example could be the clock timer 66 * chip type. By default you get returned a null string if garbage 67 * is returned from the prom. 68 */ 69
70 char *
71 get_str_from_prom(intnode, char *nd_prop, char *value)
/* */ 72 { 73 unsignedintpr_len;
74
75 *value='\n';
76
77 pr_len = romvec->pv_nodeops->no_proplen(node, nd_prop);
78 if(pr_len > MAX_PR_LEN)
79 { 80 #ifdefDEBUG_PROMOPS 81 printk("Bad pr_len in promops -- node: %d nd_prop: %s pr_len: %d",
82 node, nd_prop, pr_len);
83 #endif 84 returnvalue; /* XXX */ 85 } 86
87 romvec->pv_nodeops->no_getprop(node, nd_prop, value);
88 value[pr_len] = 0;
89
90 returnvalue;
91 } 92
93 /* This gets called from head.S upon bootup to initialize the 94 * prom vector pointer for the rest of the kernel. 95 */ 96
97 void 98 init_prom(structlinux_romvec *r_ptr)
/* */ 99 { 100 romvec = r_ptr;
101 prom_node_root = romvec->pv_nodeops->no_nextnode(0);
102
103 return;
104 }