ia64/linux-2.6.18-xen.hg

annotate arch/mips/sgi-ip27/ip27-klconfig.c @ 0:831230e53067

Import 2.6.18 from kernel.org tarball.
author Ian Campbell <ian.campbell@xensource.com>
date Wed Apr 11 14:15:44 2007 +0100 (2007-04-11)
parents
children
rev   line source
ian@0 1 /*
ian@0 2 * Copyright (C) 1999, 2000 Ralf Baechle (ralf@gnu.org)
ian@0 3 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
ian@0 4 */
ian@0 5 #include <linux/init.h>
ian@0 6 #include <linux/kernel.h>
ian@0 7 #include <linux/sched.h>
ian@0 8 #include <linux/interrupt.h>
ian@0 9 #include <linux/kernel_stat.h>
ian@0 10 #include <linux/param.h>
ian@0 11 #include <linux/timex.h>
ian@0 12 #include <linux/mm.h>
ian@0 13
ian@0 14 #include <asm/sn/klconfig.h>
ian@0 15 #include <asm/sn/arch.h>
ian@0 16 #include <asm/sn/gda.h>
ian@0 17
ian@0 18 klinfo_t *find_component(lboard_t *brd, klinfo_t *kli, unsigned char struct_type)
ian@0 19 {
ian@0 20 int index, j;
ian@0 21
ian@0 22 if (kli == (klinfo_t *)NULL) {
ian@0 23 index = 0;
ian@0 24 } else {
ian@0 25 for (j = 0; j < KLCF_NUM_COMPS(brd); j++)
ian@0 26 if (kli == KLCF_COMP(brd, j))
ian@0 27 break;
ian@0 28 index = j;
ian@0 29 if (index == KLCF_NUM_COMPS(brd)) {
ian@0 30 printk("find_component: Bad pointer: 0x%p\n", kli);
ian@0 31 return (klinfo_t *)NULL;
ian@0 32 }
ian@0 33 index++; /* next component */
ian@0 34 }
ian@0 35
ian@0 36 for (; index < KLCF_NUM_COMPS(brd); index++) {
ian@0 37 kli = KLCF_COMP(brd, index);
ian@0 38 if (KLCF_COMP_TYPE(kli) == struct_type)
ian@0 39 return kli;
ian@0 40 }
ian@0 41
ian@0 42 /* Didn't find it. */
ian@0 43 return (klinfo_t *)NULL;
ian@0 44 }
ian@0 45
ian@0 46 klinfo_t *find_first_component(lboard_t *brd, unsigned char struct_type)
ian@0 47 {
ian@0 48 return find_component(brd, (klinfo_t *)NULL, struct_type);
ian@0 49 }
ian@0 50
ian@0 51 lboard_t * find_lboard(lboard_t *start, unsigned char brd_type)
ian@0 52 {
ian@0 53 /* Search all boards stored on this node. */
ian@0 54 while (start) {
ian@0 55 if (start->brd_type == brd_type)
ian@0 56 return start;
ian@0 57 start = KLCF_NEXT(start);
ian@0 58 }
ian@0 59 /* Didn't find it. */
ian@0 60 return (lboard_t *)NULL;
ian@0 61 }
ian@0 62
ian@0 63 lboard_t * find_lboard_class(lboard_t *start, unsigned char brd_type)
ian@0 64 {
ian@0 65 /* Search all boards stored on this node. */
ian@0 66 while (start) {
ian@0 67 if (KLCLASS(start->brd_type) == KLCLASS(brd_type))
ian@0 68 return start;
ian@0 69 start = KLCF_NEXT(start);
ian@0 70 }
ian@0 71
ian@0 72 /* Didn't find it. */
ian@0 73 return (lboard_t *)NULL;
ian@0 74 }
ian@0 75
ian@0 76 cnodeid_t get_cpu_cnode(cpuid_t cpu)
ian@0 77 {
ian@0 78 return CPUID_TO_COMPACT_NODEID(cpu);
ian@0 79 }
ian@0 80
ian@0 81 klcpu_t * nasid_slice_to_cpuinfo(nasid_t nasid, int slice)
ian@0 82 {
ian@0 83 lboard_t *brd;
ian@0 84 klcpu_t *acpu;
ian@0 85
ian@0 86 if (!(brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IP27)))
ian@0 87 return (klcpu_t *)NULL;
ian@0 88
ian@0 89 if (!(acpu = (klcpu_t *)find_first_component(brd, KLSTRUCT_CPU)))
ian@0 90 return (klcpu_t *)NULL;
ian@0 91
ian@0 92 do {
ian@0 93 if ((acpu->cpu_info.physid) == slice)
ian@0 94 return acpu;
ian@0 95 } while ((acpu = (klcpu_t *)find_component(brd, (klinfo_t *)acpu,
ian@0 96 KLSTRUCT_CPU)));
ian@0 97 return (klcpu_t *)NULL;
ian@0 98 }
ian@0 99
ian@0 100 klcpu_t * sn_get_cpuinfo(cpuid_t cpu)
ian@0 101 {
ian@0 102 nasid_t nasid;
ian@0 103 int slice;
ian@0 104 klcpu_t *acpu;
ian@0 105 gda_t *gdap = GDA;
ian@0 106 cnodeid_t cnode;
ian@0 107
ian@0 108 if (!(cpu < MAXCPUS)) {
ian@0 109 printk("sn_get_cpuinfo: illegal cpuid 0x%lx\n", cpu);
ian@0 110 return NULL;
ian@0 111 }
ian@0 112
ian@0 113 cnode = get_cpu_cnode(cpu);
ian@0 114 if (cnode == INVALID_CNODEID)
ian@0 115 return NULL;
ian@0 116
ian@0 117 if ((nasid = gdap->g_nasidtable[cnode]) == INVALID_NASID)
ian@0 118 return NULL;
ian@0 119
ian@0 120 for (slice = 0; slice < CPUS_PER_NODE; slice++) {
ian@0 121 acpu = nasid_slice_to_cpuinfo(nasid, slice);
ian@0 122 if (acpu && acpu->cpu_info.virtid == cpu)
ian@0 123 return acpu;
ian@0 124 }
ian@0 125 return NULL;
ian@0 126 }
ian@0 127
ian@0 128 int get_cpu_slice(cpuid_t cpu)
ian@0 129 {
ian@0 130 klcpu_t *acpu;
ian@0 131
ian@0 132 if ((acpu = sn_get_cpuinfo(cpu)) == NULL)
ian@0 133 return -1;
ian@0 134 return acpu->cpu_info.physid;
ian@0 135 }