cpu.h revision 1.1
11.1Smatt/* $NetBSD: cpu.h,v 1.1 2014/09/03 19:34:26 matt Exp $ */ 21.1Smatt 31.1Smatt/*- 41.1Smatt * Copyright (c) 2014 The NetBSD Foundation, Inc. 51.1Smatt * All rights reserved. 61.1Smatt * 71.1Smatt * This code is derived from software contributed to The NetBSD Foundation 81.1Smatt * by Matt Thomas of 3am Software Foundry. 91.1Smatt * 101.1Smatt * Redistribution and use in source and binary forms, with or without 111.1Smatt * modification, are permitted provided that the following conditions 121.1Smatt * are met: 131.1Smatt * 1. Redistributions of source code must retain the above copyright 141.1Smatt * notice, this list of conditions and the following disclaimer. 151.1Smatt * 2. Redistributions in binary form must reproduce the above copyright 161.1Smatt * notice, this list of conditions and the following disclaimer in the 171.1Smatt * documentation and/or other materials provided with the distribution. 181.1Smatt * 191.1Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Smatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Smatt * POSSIBILITY OF SUCH DAMAGE. 301.1Smatt */ 311.1Smatt 321.1Smatt#ifndef _OR1K_CPU_H_ 331.1Smatt#define _OR1K_CPU_H_ 341.1Smatt 351.1Smatt#if defined(_KERNEL) || defined(_KMEMUSER) 361.1Smattstruct clockframe { 371.1Smatt uintptr_t cf_pc; 381.1Smatt uint32_t cf_sr; 391.1Smatt int cf_intr_depth; 401.1Smatt}; 411.1Smatt 421.1Smatt#define CLKF_USERMODE(cf) (((cf)->cf_sr & 1) == 0) 431.1Smatt#define CLKF_PC(cf) ((cf)->cf_pc) 441.1Smatt#define CLKF_INTR(cf) ((cf)->cf_intr_depth > 0) 451.1Smatt 461.1Smatt#include <sys/cpu_data.h> 471.1Smatt#include <sys/device_if.h> 481.1Smatt#include <sys/intr.h> 491.1Smatt 501.1Smattstruct cpu_info { 511.1Smatt struct cpu_data ci_data; 521.1Smatt device_t ci_dev; 531.1Smatt cpuid_t ci_cpuid; 541.1Smatt struct lwp *ci_curlwp; 551.1Smatt struct lwp *ci_softlwps[SOFTINT_COUNT]; 561.1Smatt 571.1Smatt uint64_t ci_lastintr; 581.1Smatt 591.1Smatt int ci_mtx_oldspl; 601.1Smatt int ci_mtx_count; 611.1Smatt 621.1Smatt int ci_want_resched; 631.1Smatt int ci_cpl; 641.1Smatt u_int ci_softints; 651.1Smatt volatile u_int ci_intr_depth; 661.1Smatt}; 671.1Smatt 681.1Smattregister struct lwp *or1k_curlwp __asm("r10"); 691.1Smatt#define curlwp or1k_curlwp 701.1Smatt 711.1Smattstatic inline struct cpu_info * 721.1Smattcurcpu(void) 731.1Smatt{ 741.1Smatt return curlwp->l_cpu; 751.1Smatt} 761.1Smatt 771.1Smattstatic inline cpuid_t 781.1Smattcpu_number(void) 791.1Smatt{ 801.1Smatt#ifdef MULTIPROCESSOR 811.1Smatt return curcpu()->ci_cpuid; 821.1Smatt#else 831.1Smatt return 0; 841.1Smatt#endif 851.1Smatt} 861.1Smatt 871.1Smattvoid cpu_set_curpri(int); 881.1Smattvoid cpu_proc_fork(struct proc *, struct proc *); 891.1Smattvoid cpu_signotify(struct lwp *); 901.1Smattvoid cpu_need_proftick(struct lwp *l); 911.1Smattvoid cpu_boot_secondary_processors(void); 921.1Smatt 931.1Smatt#define CPU_INFO_ITERATOR cpuid_t 941.1Smatt#ifdef MULTIPROCESSOR 951.1Smatt#define CPU_INFO_FOREACH(cii, ci) \ 961.1Smatt (cii) = 0; ((ci) = cpu_infos[cii]) != NULL; (cii)++ 971.1Smatt#else 981.1Smatt#define CPU_INFO_FOREACH(cii, ci) \ 991.1Smatt (cii) = 0; (cii) == 0 && (ci) = curcpu(); (cii)++ 1001.1Smatt#endif 1011.1Smatt 1021.1Smattstatic inline void 1031.1Smattcpu_dosoftints(void) 1041.1Smatt{ 1051.1Smatt extern void dosoftints(void); 1061.1Smatt struct cpu_info * const ci = curcpu(); 1071.1Smatt if (ci->ci_intr_depth == 0 1081.1Smatt && (ci->ci_data.cpu_softints >> ci->ci_cpl) > 0) 1091.1Smatt dosoftints(); 1101.1Smatt} 1111.1Smatt 1121.1Smattstatic inline bool 1131.1Smattcpu_intr_p(void) 1141.1Smatt{ 1151.1Smatt return curcpu()->ci_intr_depth > 0; 1161.1Smatt} 1171.1Smatt 1181.1Smatt#endif /* _KERNEL || _KMEMUSER */ 1191.1Smatt 1201.1Smatt#endif /* _OR1K_CPU_H_ */ 121