Home | History | Annotate | Line # | Download | only in ia64
cpu.c revision 1.13
      1 /*	$NetBSD: cpu.c,v 1.13 2014/03/24 20:06:32 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2006 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  *
      8  * Author:
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.13 2014/03/24 20:06:32 christos Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/proc.h>
     37 #include <sys/systm.h>
     38 #include <sys/device.h>
     39 #include <sys/kmem.h>
     40 
     41 #include <dev/acpi/acpica.h>
     42 #include <dev/acpi/acpivar.h>
     43 
     44 #define MHz	1000000L
     45 #define GHz	(1000L * MHz)
     46 
     47 struct cpu_info cpu_info_primary __aligned(CACHE_LINE_SIZE);
     48 struct cpu_info *cpu_info_list = &cpu_info_primary;
     49 
     50 struct cpu_softc {
     51 	device_t sc_dev;		/* device tree glue */
     52 	struct cpu_info *sc_info;	/* pointer to CPU info */
     53 };
     54 
     55 static int cpu_match(device_t, cfdata_t, void *);
     56 static void cpu_attach(device_t, device_t, void *);
     57 
     58 static void identifycpu(struct cpu_softc *);
     59 
     60 CFATTACH_DECL_NEW(cpu, sizeof(struct cpu_softc),
     61     cpu_match, cpu_attach, NULL, NULL);
     62 
     63 
     64 static int
     65 cpu_match(device_t parent, cfdata_t match, void *aux)
     66 {
     67 
     68 	return 1;
     69 }
     70 
     71 static void
     72 cpu_attach(device_t parent, device_t self, void *aux)
     73 {
     74 	struct cpu_softc *sc = device_private(self);
     75 	ACPI_MADT_LOCAL_SAPIC *sapic = (ACPI_MADT_LOCAL_SAPIC *)aux;
     76 	struct cpu_info *ci;
     77 	uint64_t lid;
     78 	int id, eid;
     79 
     80 	aprint_naive("\n");
     81 	aprint_normal(": ProcessorID %d, Id %d, Eid %d%s\n",
     82 	    sapic->ProcessorId, sapic->Id, sapic->Eid,
     83 	    sapic->LapicFlags & ACPI_MADT_ENABLED ? "" : " (disabled)");
     84 
     85 	/* Get current CPU Id */
     86 	lid = ia64_get_lid();
     87 	id = (lid & 0x00000000ff000000) >> 24;
     88 	eid = (lid & 0x0000000000ff0000) >> 16;
     89 
     90 	sc->sc_dev = self;
     91 	if (id == sapic->Id && eid == sapic->Eid)
     92 		ci = curcpu();
     93 	else {
     94 		ci = (struct cpu_info *)kmem_zalloc(sizeof(*ci), KM_NOSLEEP);
     95 		if (ci == NULL) {
     96 			aprint_error_dev(self, "memory alloc failed\n");
     97 			return;
     98 		}
     99 	}
    100 	sc->sc_info = ci;
    101 
    102 	ci->ci_cpuid = sapic->ProcessorId;
    103 	ci->ci_intrdepth = -1;			/* need ? */
    104 	ci->ci_dev = self;
    105 
    106 	identifycpu(sc);
    107 
    108 	return;
    109 }
    110 
    111 
    112 static void
    113 identifycpu(struct cpu_softc *sc)
    114 {
    115 	uint64_t vendor[3];
    116 	const char *family_name, *model_name;
    117 	uint64_t features, tmp;
    118 	int revision, model, family;
    119 	char bitbuf[32];
    120 	extern uint64_t processor_frequency;
    121 
    122 	/*
    123 	 * Assumes little-endian.
    124 	 */
    125 	vendor[0] = ia64_get_cpuid(0);
    126 	vendor[1] = ia64_get_cpuid(1);
    127 	vendor[2] = '\0';
    128 
    129 	tmp = ia64_get_cpuid(3);
    130 	/* number = (tmp >> 0) & 0xff; */
    131 	revision = (tmp >> 8) & 0xff;
    132 	model = (tmp >> 16) & 0xff;
    133 	family = (tmp >> 24) & 0xff;
    134 	/* archrev = (tmp >> 32) & 0xff; */
    135 
    136 	family_name = model_name = "unknown";
    137 	switch (family) {
    138 	case 0x07:
    139 		family_name = "Itanium";
    140 		model_name = "Merced";
    141 		break;
    142 	case 0x1f:
    143 		family_name = "Itanium 2";
    144 		switch (model) {
    145 		case 0x00:
    146 			model_name = "McKinley";
    147 			break;
    148 		case 0x01:
    149 			/*
    150 			 * Deerfield is a low-voltage variant based on the
    151 			 * Madison core. We need circumstantial evidence
    152 			 * (i.e. the clock frequency) to identify those.
    153 			 * Allow for roughly 1% error margin.
    154 			 */
    155 			tmp = processor_frequency >> 7;
    156 			if ((processor_frequency - tmp) < 1*GHz &&
    157 			    (processor_frequency + tmp) >= 1*GHz)
    158 				model_name = "Deerfield";
    159 			else
    160 				model_name = "Madison";
    161 			break;
    162 		case 0x02:
    163 			model_name = "Madison II";
    164 			break;
    165 		}
    166 		break;
    167 	}
    168 	cpu_setmodel("%s", model_name);
    169 
    170 	features = ia64_get_cpuid(4);
    171 
    172 	aprint_normal_dev(sc->sc_dev, "%s (", model_name);
    173 	if (processor_frequency) {
    174 		aprint_normal("%ld.%02ld-MHz ",
    175 		    (processor_frequency + 4999) / MHz,
    176 		    ((processor_frequency + 4999) / (MHz/100)) % 100);
    177 	}
    178 	aprint_normal("%s)\n", family_name);
    179 	aprint_normal_dev(sc->sc_dev, "Origin \"%s\",  Revision %d\n",
    180 	    (char *)vendor, revision);
    181 
    182 #define IA64_FEATURES_BITMASK "\177\020"				\
    183     "b\0LB\0"	/* 'brl' instruction is implemented */			\
    184     "b\1SD\0"	/* Processor implements sportaneous deferral */		\
    185     "b\2AO\0"	/* Processor implements 16-byte atomic operations */	\
    186     "\0"
    187 	snprintb(bitbuf, sizeof(bitbuf), IA64_FEATURES_BITMASK, features);
    188 	aprint_normal_dev(sc->sc_dev, "Features %s\n", bitbuf);
    189 }
    190