Import 2.4.0-test3pre8
[davej-history.git] / arch / mips64 / sgi-ip27 / ip27-klconfig.c
blobbfa176745235b5f454a5c28a60f0aa19757c1000
1 /* $Id$
3 * Copyright (C) 1999, 2000 Ralf Baechle (ralf@gnu.org)
4 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
5 */
6 #include <linux/init.h>
7 #include <linux/kernel.h>
8 #include <linux/sched.h>
9 #include <linux/interrupt.h>
10 #include <linux/kernel_stat.h>
11 #include <linux/param.h>
12 #include <linux/timex.h>
13 #include <linux/mm.h>
15 #include <asm/sn/klconfig.h>
16 #include <asm/sn/arch.h>
17 #include <asm/sn/gda.h>
19 klinfo_t *find_component(lboard_t *brd, klinfo_t *kli, unsigned char struct_type)
21 int index, j;
23 if (kli == (klinfo_t *)NULL) {
24 index = 0;
25 } else {
26 for (j = 0; j < KLCF_NUM_COMPS(brd); j++)
27 if (kli == KLCF_COMP(brd, j))
28 break;
29 index = j;
30 if (index == KLCF_NUM_COMPS(brd)) {
31 printk("find_component: Bad pointer: 0x%p\n", kli);
32 return (klinfo_t *)NULL;
34 index++; /* next component */
37 for (; index < KLCF_NUM_COMPS(brd); index++) {
38 kli = KLCF_COMP(brd, index);
39 if (KLCF_COMP_TYPE(kli) == struct_type)
40 return kli;
43 /* Didn't find it. */
44 return (klinfo_t *)NULL;
47 klinfo_t *find_first_component(lboard_t *brd, unsigned char struct_type)
49 return find_component(brd, (klinfo_t *)NULL, struct_type);
52 lboard_t * find_lboard(lboard_t *start, unsigned char brd_type)
54 /* Search all boards stored on this node. */
55 while (start) {
56 if (start->brd_type == brd_type)
57 return start;
58 start = KLCF_NEXT(start);
60 /* Didn't find it. */
61 return (lboard_t *)NULL;
64 cnodeid_t get_cpu_cnode(cpuid_t cpu)
66 return CPUID_TO_COMPACT_NODEID(cpu);
69 klcpu_t * nasid_slice_to_cpuinfo(nasid_t nasid, int slice)
71 lboard_t *brd;
72 klcpu_t *acpu;
74 if (!(brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IP27)))
75 return (klcpu_t *)NULL;
77 if (!(acpu = (klcpu_t *)find_first_component(brd, KLSTRUCT_CPU)))
78 return (klcpu_t *)NULL;
80 do {
81 if ((acpu->cpu_info.physid) == slice)
82 return acpu;
83 } while ((acpu = (klcpu_t *)find_component(brd, (klinfo_t *)acpu,
84 KLSTRUCT_CPU)));
85 return (klcpu_t *)NULL;
88 klcpu_t * sn_get_cpuinfo(cpuid_t cpu)
90 nasid_t nasid;
91 int slice;
92 klcpu_t *acpu;
93 gda_t *gdap = GDA;
94 cnodeid_t cnode;
96 if (!(cpu < MAXCPUS)) {
97 printk("sn_get_cpuinfo: illegal cpuid 0x%lx\n", cpu);
98 return NULL;
101 cnode = get_cpu_cnode(cpu);
102 if (cnode == INVALID_CNODEID)
103 return NULL;
105 if ((nasid = gdap->g_nasidtable[cnode]) == INVALID_NASID)
106 return NULL;
108 for (slice = 0; slice < CPUS_PER_NODE; slice++) {
109 acpu = nasid_slice_to_cpuinfo(nasid, slice);
110 if (acpu && acpu->cpu_info.virtid == cpu)
111 return acpu;
113 return NULL;
116 int get_cpu_slice(cpuid_t cpu)
118 klcpu_t *acpu;
120 if ((acpu = sn_get_cpuinfo(cpu)) == NULL)
121 return -1;
122 return acpu->cpu_info.physid;