Home | History | Annotate | Line # | Download | only in arch
sparc.c revision 1.1
      1 /*	$NetBSD: sparc.c,v 1.1 2018/01/16 08:23:18 mrg Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2018 Matthew R. Green
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  * SUCH DAMAGE.
     29  */
     30 #include <sys/cdefs.h>
     31 
     32 #ifndef lint
     33 __RCSID("$NetBSD: sparc.c,v 1.1 2018/01/16 08:23:18 mrg Exp $");
     34 #endif
     35 
     36 #include <sys/types.h>
     37 #include <sys/cpuio.h>
     38 #include <sys/sysctl.h>
     39 
     40 #include <machine/cpu.h>
     41 
     42 #include <stdio.h>
     43 #include <err.h>
     44 
     45 #include "../cpuctl.h"
     46 #include "../../../sys/arch/sparc/sparc/cache_print.h"
     47 
     48 void
     49 identifycpu(int fd, const char *cpuname)
     50 {
     51 	char path[128];
     52 	char *name;
     53 	char *fpuname;
     54 	int cpu_arch, mid, hz;
     55 	struct cacheinfo cacheinfo;
     56 	size_t len;
     57 
     58 	len = sizeof(cpu_arch);
     59 	if (sysctlbyname("machdep.cpu_arch", &cpu_arch, &len, 0, 0) == -1)
     60 		err(1, "couldn't get machdep.cpu_arch");
     61 
     62 	snprintf(path, sizeof path, "hw.%s.cacheinfo", cpuname);
     63 	len = sizeof(cacheinfo);
     64 	if (sysctlbyname(path, &cacheinfo, &len, 0, 0) == -1)
     65 		err(1, "couldn't get %s", path);
     66 
     67 	snprintf(path, sizeof path, "hw.%s.mid", cpuname);
     68 	len = sizeof(mid);
     69 	if (sysctlbyname(path, &mid, &len, 0, 0) == -1)
     70 		err(1, "couldn't get %s", path);
     71 
     72 	snprintf(path, sizeof path, "hw.%s.clock_frequency", cpuname);
     73 	len = sizeof(hz);
     74 	if (sysctlbyname(path, &hz, &len, 0, 0) == -1)
     75 		err(1, "couldn't get %s", path);
     76 	snprintf(path, sizeof path, "hw.%s.name", cpuname);
     77 	name = asysctlbyname(path, &len);
     78 
     79 	snprintf(path, sizeof path, "hw.%s.fpuname", cpuname);
     80 	fpuname = asysctlbyname(path, &len);
     81 
     82 	printf("%s: mid %d: %s @ %d MHz, %s FPU\n", cpuname, mid, name, hz / 1000000, fpuname);
     83 	cache_printf_backend(&cacheinfo, cpuname);
     84 
     85 	printf("%s: SPARC v%d\n", cpuname, cpu_arch);
     86 }
     87 
     88 bool
     89 identifycpu_bind(void)
     90 {
     91 
     92 	return false;
     93 }
     94 
     95 int
     96 ucodeupdate_check(int fd, struct cpu_ucode *uc)
     97 {
     98 
     99 	return 0;
    100 }
    101