Home | History | Annotate | Line # | Download | only in include
      1  1.7    rmind /* $NetBSD: cpu_msr.h,v 1.7 2009/10/05 23:59:31 rmind 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.7    rmind #include <sys/types.h>
     33  1.1  xtraeme 
     34  1.1  xtraeme #ifdef _KERNEL
     35  1.1  xtraeme 
     36  1.7    rmind struct msr_rw_info {
     37  1.7    rmind 	int		msr_read;
     38  1.7    rmind 	int		msr_type;
     39  1.7    rmind 	uint64_t	msr_value;
     40  1.7    rmind 	uint64_t	msr_mask;
     41  1.1  xtraeme };
     42  1.1  xtraeme 
     43  1.7    rmind static inline void
     44  1.7    rmind x86_msr_xcall(void *arg1, void *arg2)
     45  1.7    rmind {
     46  1.7    rmind 	struct msr_rw_info *msrdat = arg1;
     47  1.7    rmind 	uint64_t msr = 0;
     48  1.7    rmind 
     49  1.7    rmind 	KASSERT(msrdat->msr_type != 0);
     50  1.7    rmind 
     51  1.7    rmind 	/* Read the MSR requested and apply the mask if defined. */
     52  1.7    rmind 	if (msrdat->msr_read) {
     53  1.7    rmind 		msr = rdmsr(msrdat->msr_type);
     54  1.7    rmind 		if (msrdat->msr_mask) {
     55  1.7    rmind 			msr &= ~msrdat->msr_mask;
     56  1.7    rmind 		}
     57  1.7    rmind 	}
     58  1.7    rmind 	/* Assign (or extract, on read) the value and perform the write. */
     59  1.7    rmind 	msr |= msrdat->msr_value;
     60  1.7    rmind 	wrmsr(msrdat->msr_type, msr);
     61  1.7    rmind }
     62  1.1  xtraeme 
     63  1.1  xtraeme #endif /* ! _KERNEL */
     64  1.1  xtraeme #endif /* ! _X86_CPU_MSR_H */
     65