Home | History | Annotate | Line # | Download | only in include
cpu_msr.h revision 1.6.34.1
      1  1.6.34.1      jym /* $NetBSD: cpu_msr.h,v 1.6.34.1 2009/11/01 13:58:16 jym Exp $ */
      2       1.1  xtraeme 
      3       1.1  xtraeme /*-
      4       1.5  xtraeme  * Copyright (c) 2007 Juan Romero Pardines.
      5       1.1  xtraeme  * All rights reserved.
      6       1.1  xtraeme  *
      7       1.1  xtraeme  * Redistribution and use in source and binary forms, with or without
      8       1.1  xtraeme  * modification, are permitted provided that the following conditions
      9       1.1  xtraeme  * are met:
     10       1.1  xtraeme  * 1. Redistributions of source code must retain the above copyright
     11       1.1  xtraeme  *    notice, this list of conditions and the following disclaimer.
     12       1.1  xtraeme  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1  xtraeme  *    notice, this list of conditions and the following disclaimer in the
     14       1.1  xtraeme  *    documentation and/or other materials provided with the distribution.
     15       1.1  xtraeme  *
     16       1.5  xtraeme  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17       1.5  xtraeme  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18       1.5  xtraeme  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19       1.5  xtraeme  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20       1.5  xtraeme  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21       1.5  xtraeme  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22       1.5  xtraeme  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23       1.5  xtraeme  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24       1.5  xtraeme  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25       1.5  xtraeme  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26       1.1  xtraeme  */
     27       1.1  xtraeme 
     28       1.1  xtraeme #ifndef _X86_CPU_MSR_H
     29       1.1  xtraeme #define _X86_CPU_MSR_H
     30       1.1  xtraeme 
     31       1.1  xtraeme #include <sys/param.h>
     32  1.6.34.1      jym #include <sys/types.h>
     33       1.1  xtraeme 
     34       1.1  xtraeme #ifdef _KERNEL
     35       1.1  xtraeme 
     36  1.6.34.1      jym struct msr_rw_info {
     37  1.6.34.1      jym 	int		msr_read;
     38  1.6.34.1      jym 	int		msr_type;
     39  1.6.34.1      jym 	uint64_t	msr_value;
     40  1.6.34.1      jym 	uint64_t	msr_mask;
     41       1.1  xtraeme };
     42       1.1  xtraeme 
     43  1.6.34.1      jym static inline void
     44  1.6.34.1      jym x86_msr_xcall(void *arg1, void *arg2)
     45  1.6.34.1      jym {
     46  1.6.34.1      jym 	struct msr_rw_info *msrdat = arg1;
     47  1.6.34.1      jym 	uint64_t msr = 0;
     48  1.6.34.1      jym 
     49  1.6.34.1      jym 	KASSERT(msrdat->msr_type != 0);
     50  1.6.34.1      jym 
     51  1.6.34.1      jym 	/* Read the MSR requested and apply the mask if defined. */
     52  1.6.34.1      jym 	if (msrdat->msr_read) {
     53  1.6.34.1      jym 		msr = rdmsr(msrdat->msr_type);
     54  1.6.34.1      jym 		if (msrdat->msr_mask) {
     55  1.6.34.1      jym 			msr &= ~msrdat->msr_mask;
     56  1.6.34.1      jym 		}
     57  1.6.34.1      jym 	}
     58  1.6.34.1      jym 	/* Assign (or extract, on read) the value and perform the write. */
     59  1.6.34.1      jym 	msr |= msrdat->msr_value;
     60  1.6.34.1      jym 	wrmsr(msrdat->msr_type, msr);
     61  1.6.34.1      jym }
     62       1.1  xtraeme 
     63       1.1  xtraeme #endif /* ! _KERNEL */
     64       1.1  xtraeme #endif /* ! _X86_CPU_MSR_H */
     65