xref: /netbsd-src/usr.sbin/cpuctl/arch/sparc.c (revision d914a3c1b942947a8b1fa87645678df29ac8e6ab)
1*d914a3c1Smrg /*	$NetBSD: sparc.c,v 1.2 2021/12/11 19:24:22 mrg Exp $	*/
28ea87328Smrg 
38ea87328Smrg /*
48ea87328Smrg  * Copyright (c) 2018 Matthew R. Green
58ea87328Smrg  * All rights reserved.
68ea87328Smrg  *
78ea87328Smrg  * Redistribution and use in source and binary forms, with or without
88ea87328Smrg  * modification, are permitted provided that the following conditions
98ea87328Smrg  * are met:
108ea87328Smrg  * 1. Redistributions of source code must retain the above copyright
118ea87328Smrg  *    notice, this list of conditions and the following disclaimer.
128ea87328Smrg  * 2. Redistributions in binary form must reproduce the above copyright
138ea87328Smrg  *    notice, this list of conditions and the following disclaimer in the
148ea87328Smrg  *    documentation and/or other materials provided with the distribution.
158ea87328Smrg  *
168ea87328Smrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
178ea87328Smrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
188ea87328Smrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
198ea87328Smrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
208ea87328Smrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
218ea87328Smrg  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
228ea87328Smrg  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
238ea87328Smrg  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
248ea87328Smrg  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
258ea87328Smrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
268ea87328Smrg  * SUCH DAMAGE.
278ea87328Smrg  */
288ea87328Smrg #include <sys/cdefs.h>
298ea87328Smrg 
308ea87328Smrg #ifndef lint
31*d914a3c1Smrg __RCSID("$NetBSD: sparc.c,v 1.2 2021/12/11 19:24:22 mrg Exp $");
328ea87328Smrg #endif
338ea87328Smrg 
348ea87328Smrg #include <sys/types.h>
358ea87328Smrg #include <sys/cpuio.h>
368ea87328Smrg #include <sys/sysctl.h>
378ea87328Smrg 
388ea87328Smrg #include <machine/cpu.h>
398ea87328Smrg 
408ea87328Smrg #include <stdio.h>
418ea87328Smrg #include <err.h>
428ea87328Smrg 
438ea87328Smrg #include "../cpuctl.h"
448ea87328Smrg #include "../../../sys/arch/sparc/sparc/cache_print.h"
458ea87328Smrg 
468ea87328Smrg void
identifycpu(int fd,const char * cpuname)478ea87328Smrg identifycpu(int fd, const char *cpuname)
488ea87328Smrg {
498ea87328Smrg 	char path[128];
508ea87328Smrg 	char *name;
518ea87328Smrg 	char *fpuname;
528ea87328Smrg 	int cpu_arch, mid, hz;
538ea87328Smrg 	struct cacheinfo cacheinfo;
548ea87328Smrg 	size_t len;
558ea87328Smrg 
568ea87328Smrg 	len = sizeof(cpu_arch);
578ea87328Smrg 	if (sysctlbyname("machdep.cpu_arch", &cpu_arch, &len, 0, 0) == -1)
588ea87328Smrg 		err(1, "couldn't get machdep.cpu_arch");
598ea87328Smrg 
608ea87328Smrg 	snprintf(path, sizeof path, "hw.%s.cacheinfo", cpuname);
618ea87328Smrg 	len = sizeof(cacheinfo);
628ea87328Smrg 	if (sysctlbyname(path, &cacheinfo, &len, 0, 0) == -1)
638ea87328Smrg 		err(1, "couldn't get %s", path);
648ea87328Smrg 
658ea87328Smrg 	snprintf(path, sizeof path, "hw.%s.mid", cpuname);
668ea87328Smrg 	len = sizeof(mid);
678ea87328Smrg 	if (sysctlbyname(path, &mid, &len, 0, 0) == -1)
688ea87328Smrg 		err(1, "couldn't get %s", path);
698ea87328Smrg 
708ea87328Smrg 	snprintf(path, sizeof path, "hw.%s.clock_frequency", cpuname);
718ea87328Smrg 	len = sizeof(hz);
728ea87328Smrg 	if (sysctlbyname(path, &hz, &len, 0, 0) == -1)
738ea87328Smrg 		err(1, "couldn't get %s", path);
748ea87328Smrg 	snprintf(path, sizeof path, "hw.%s.name", cpuname);
758ea87328Smrg 	name = asysctlbyname(path, &len);
768ea87328Smrg 
778ea87328Smrg 	snprintf(path, sizeof path, "hw.%s.fpuname", cpuname);
788ea87328Smrg 	fpuname = asysctlbyname(path, &len);
798ea87328Smrg 
808ea87328Smrg 	printf("%s: mid %d: %s @ %d MHz, %s FPU\n", cpuname, mid, name, hz / 1000000, fpuname);
818ea87328Smrg 	cache_printf_backend(&cacheinfo, cpuname);
828ea87328Smrg 
838ea87328Smrg 	printf("%s: SPARC v%d\n", cpuname, cpu_arch);
848ea87328Smrg }
858ea87328Smrg 
868ea87328Smrg bool
identifycpu_bind(void)878ea87328Smrg identifycpu_bind(void)
888ea87328Smrg {
898ea87328Smrg 
908ea87328Smrg 	return false;
918ea87328Smrg }
928ea87328Smrg 
938ea87328Smrg int
ucodeupdate_check(int fd,struct cpu_ucode * uc)948ea87328Smrg ucodeupdate_check(int fd, struct cpu_ucode *uc)
958ea87328Smrg {
968ea87328Smrg 
978ea87328Smrg 	return 0;
988ea87328Smrg }
99