1*ff22bcd2Sriastradh /* $NetBSD: pcu.h,v 1.14 2022/10/26 23:38:58 riastradh Exp $ */ 2bc16d8a4Srmind 3bc16d8a4Srmind /*- 4bc16d8a4Srmind * Copyright (c) 2011 The NetBSD Foundation, Inc. 5bc16d8a4Srmind * All rights reserved. 6bc16d8a4Srmind * 7bc16d8a4Srmind * This code is derived from software contributed to The NetBSD Foundation 8bc16d8a4Srmind * by Mindaugas Rasiukevicius. 9bc16d8a4Srmind * 10bc16d8a4Srmind * Redistribution and use in source and binary forms, with or without 11bc16d8a4Srmind * modification, are permitted provided that the following conditions 12bc16d8a4Srmind * are met: 13bc16d8a4Srmind * 1. Redistributions of source code must retain the above copyright 14bc16d8a4Srmind * notice, this list of conditions and the following disclaimer. 15bc16d8a4Srmind * 2. Redistributions in binary form must reproduce the above copyright 16bc16d8a4Srmind * notice, this list of conditions and the following disclaimer in the 17bc16d8a4Srmind * documentation and/or other materials provided with the distribution. 18bc16d8a4Srmind * 19bc16d8a4Srmind * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20bc16d8a4Srmind * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21bc16d8a4Srmind * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22bc16d8a4Srmind * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23bc16d8a4Srmind * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24bc16d8a4Srmind * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25bc16d8a4Srmind * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26bc16d8a4Srmind * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27bc16d8a4Srmind * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28bc16d8a4Srmind * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29bc16d8a4Srmind * POSSIBILITY OF SUCH DAMAGE. 30bc16d8a4Srmind */ 31bc16d8a4Srmind 32bc16d8a4Srmind #ifndef _SYS_PCU_H_ 33bc16d8a4Srmind #define _SYS_PCU_H_ 34bc16d8a4Srmind 351391a530Srmind #if !defined(_KERNEL) && !defined(_KMEMUSER) 3638d699a2Srmind #error "not supposed to be exposed to userland" 3738d699a2Srmind #endif 3838d699a2Srmind 3950bbbe7fSmartin #ifndef _KERNEL 4050bbbe7fSmartin #include <stdbool.h> 4150bbbe7fSmartin #endif 4250bbbe7fSmartin 43bc16d8a4Srmind /* 447cefbb60Smatt * Default: no PCU for MD. 45bc16d8a4Srmind */ 46bc16d8a4Srmind #ifndef PCU_UNIT_COUNT 477cefbb60Smatt #define PCU_UNIT_COUNT 0 48bc16d8a4Srmind #endif 49bc16d8a4Srmind 5038d699a2Srmind #if PCU_UNIT_COUNT > 0 516146ba63Srmind 52673662efSyamt /* 53d67ab12cSrmind * pcu_state_save(lwp) 54d67ab12cSrmind * Tells MD code to save the current CPU's state into the given 55d67ab12cSrmind * LWP's MD storage. 56673662efSyamt * 5709ae87cfSmatt * pcu_state_load(lwp, flags) 58d67ab12cSrmind * Tells MD code to load PCU state from the given LWP's MD storage 59d67ab12cSrmind * to the current CPU. 60673662efSyamt * 61d67ab12cSrmind * pcu_state_release(lwp) 62d67ab12cSrmind * Tells MD code detect the next use of the PCU on the LWP and 63d67ab12cSrmind * call pcu_load(). 64673662efSyamt */ 65673662efSyamt 66bc16d8a4Srmind typedef struct { 67bc16d8a4Srmind u_int pcu_id; 68d67ab12cSrmind void (*pcu_state_save)(lwp_t *); 69d67ab12cSrmind void (*pcu_state_load)(lwp_t *, unsigned); 70d67ab12cSrmind void (*pcu_state_release)(lwp_t *); 71bc16d8a4Srmind } pcu_ops_t; 72bc16d8a4Srmind 73d67ab12cSrmind /* 74d67ab12cSrmind * Flags for the pcu_state_load() operation. 75d67ab12cSrmind */ 76d67ab12cSrmind #define PCU_VALID 0x01 /* PCU state is considered valid */ 77d67ab12cSrmind #define PCU_REENABLE 0x02 /* the state is present, re-enable PCU */ 7809ae87cfSmatt 7938d699a2Srmind void pcu_switchpoint(lwp_t *); 80f3c47d39Smatt void pcu_discard_all(lwp_t *); 81f3c47d39Smatt void pcu_save_all(lwp_t *); 82bc16d8a4Srmind 8338d699a2Srmind void pcu_load(const pcu_ops_t *); 84877a3ccfSchs void pcu_save(const pcu_ops_t *, lwp_t *); 8569aeb16cSdrochner void pcu_save_all_on_cpu(void); 86877a3ccfSchs void pcu_discard(const pcu_ops_t *, lwp_t *, bool); 87877a3ccfSchs bool pcu_valid_p(const pcu_ops_t *, const lwp_t *); 8838d699a2Srmind 89*ff22bcd2Sriastradh /* PCU operations structure provided by the MD code. */ 90*ff22bcd2Sriastradh extern const pcu_ops_t *const pcu_ops_md_defs[]; 91*ff22bcd2Sriastradh 9238d699a2Srmind #else 9338d699a2Srmind #define pcu_switchpoint(l) 94f3c47d39Smatt #define pcu_discard_all(l) 95f3c47d39Smatt #define pcu_save_all(l) 96bc16d8a4Srmind #endif 976146ba63Srmind 986146ba63Srmind #endif 99