162306a36Sopenharmony_ci/* SPDX-License-Identifier: LGPL-2.0+ WITH Linux-syscall-note */
262306a36Sopenharmony_ci/*  Generic MTRR (Memory Type Range Register) ioctls.
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci    Copyright (C) 1997-1999  Richard Gooch
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci    This library is free software; you can redistribute it and/or
762306a36Sopenharmony_ci    modify it under the terms of the GNU Library General Public
862306a36Sopenharmony_ci    License as published by the Free Software Foundation; either
962306a36Sopenharmony_ci    version 2 of the License, or (at your option) any later version.
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci    This library is distributed in the hope that it will be useful,
1262306a36Sopenharmony_ci    but WITHOUT ANY WARRANTY; without even the implied warranty of
1362306a36Sopenharmony_ci    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1462306a36Sopenharmony_ci    Library General Public License for more details.
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci    You should have received a copy of the GNU Library General Public
1762306a36Sopenharmony_ci    License along with this library; if not, write to the Free
1862306a36Sopenharmony_ci    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci    Richard Gooch may be reached by email at  rgooch@atnf.csiro.au
2162306a36Sopenharmony_ci    The postal address is:
2262306a36Sopenharmony_ci      Richard Gooch, c/o ATNF, P. O. Box 76, Epping, N.S.W., 2121, Australia.
2362306a36Sopenharmony_ci*/
2462306a36Sopenharmony_ci#ifndef _UAPI_ASM_X86_MTRR_H
2562306a36Sopenharmony_ci#define _UAPI_ASM_X86_MTRR_H
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci#include <linux/types.h>
2862306a36Sopenharmony_ci#include <linux/ioctl.h>
2962306a36Sopenharmony_ci#include <linux/errno.h>
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#define	MTRR_IOCTL_BASE	'M'
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci/* Warning: this structure has a different order from i386
3462306a36Sopenharmony_ci   on x86-64. The 32bit emulation code takes care of that.
3562306a36Sopenharmony_ci   But you need to use this for 64bit, otherwise your X server
3662306a36Sopenharmony_ci   will break. */
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#ifdef __i386__
3962306a36Sopenharmony_cistruct mtrr_sentry {
4062306a36Sopenharmony_ci    unsigned long base;    /*  Base address     */
4162306a36Sopenharmony_ci    unsigned int size;    /*  Size of region   */
4262306a36Sopenharmony_ci    unsigned int type;     /*  Type of region   */
4362306a36Sopenharmony_ci};
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_cistruct mtrr_gentry {
4662306a36Sopenharmony_ci    unsigned int regnum;   /*  Register number  */
4762306a36Sopenharmony_ci    unsigned long base;    /*  Base address     */
4862306a36Sopenharmony_ci    unsigned int size;    /*  Size of region   */
4962306a36Sopenharmony_ci    unsigned int type;     /*  Type of region   */
5062306a36Sopenharmony_ci};
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci#else /* __i386__ */
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistruct mtrr_sentry {
5562306a36Sopenharmony_ci	__u64 base;		/*  Base address     */
5662306a36Sopenharmony_ci	__u32 size;		/*  Size of region   */
5762306a36Sopenharmony_ci	__u32 type;		/*  Type of region   */
5862306a36Sopenharmony_ci};
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_cistruct mtrr_gentry {
6162306a36Sopenharmony_ci	__u64 base;		/*  Base address     */
6262306a36Sopenharmony_ci	__u32 size;		/*  Size of region   */
6362306a36Sopenharmony_ci	__u32 regnum;		/*  Register number  */
6462306a36Sopenharmony_ci	__u32 type;		/*  Type of region   */
6562306a36Sopenharmony_ci	__u32 _pad;		/*  Unused	     */
6662306a36Sopenharmony_ci};
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci#endif /* !__i386__ */
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_cistruct mtrr_var_range {
7162306a36Sopenharmony_ci	__u32 base_lo;
7262306a36Sopenharmony_ci	__u32 base_hi;
7362306a36Sopenharmony_ci	__u32 mask_lo;
7462306a36Sopenharmony_ci	__u32 mask_hi;
7562306a36Sopenharmony_ci};
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci/* In the Intel processor's MTRR interface, the MTRR type is always held in
7862306a36Sopenharmony_ci   an 8 bit field: */
7962306a36Sopenharmony_citypedef __u8 mtrr_type;
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#define MTRR_NUM_FIXED_RANGES 88
8262306a36Sopenharmony_ci#define MTRR_MAX_VAR_RANGES 256
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci#define MTRRphysBase_MSR(reg) (0x200 + 2 * (reg))
8562306a36Sopenharmony_ci#define MTRRphysMask_MSR(reg) (0x200 + 2 * (reg) + 1)
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci/*  These are the various ioctls  */
8862306a36Sopenharmony_ci#define MTRRIOC_ADD_ENTRY        _IOW(MTRR_IOCTL_BASE,  0, struct mtrr_sentry)
8962306a36Sopenharmony_ci#define MTRRIOC_SET_ENTRY        _IOW(MTRR_IOCTL_BASE,  1, struct mtrr_sentry)
9062306a36Sopenharmony_ci#define MTRRIOC_DEL_ENTRY        _IOW(MTRR_IOCTL_BASE,  2, struct mtrr_sentry)
9162306a36Sopenharmony_ci#define MTRRIOC_GET_ENTRY        _IOWR(MTRR_IOCTL_BASE, 3, struct mtrr_gentry)
9262306a36Sopenharmony_ci#define MTRRIOC_KILL_ENTRY       _IOW(MTRR_IOCTL_BASE,  4, struct mtrr_sentry)
9362306a36Sopenharmony_ci#define MTRRIOC_ADD_PAGE_ENTRY   _IOW(MTRR_IOCTL_BASE,  5, struct mtrr_sentry)
9462306a36Sopenharmony_ci#define MTRRIOC_SET_PAGE_ENTRY   _IOW(MTRR_IOCTL_BASE,  6, struct mtrr_sentry)
9562306a36Sopenharmony_ci#define MTRRIOC_DEL_PAGE_ENTRY   _IOW(MTRR_IOCTL_BASE,  7, struct mtrr_sentry)
9662306a36Sopenharmony_ci#define MTRRIOC_GET_PAGE_ENTRY   _IOWR(MTRR_IOCTL_BASE, 8, struct mtrr_gentry)
9762306a36Sopenharmony_ci#define MTRRIOC_KILL_PAGE_ENTRY  _IOW(MTRR_IOCTL_BASE,  9, struct mtrr_sentry)
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci/* MTRR memory types, which are defined in SDM */
10062306a36Sopenharmony_ci#define MTRR_TYPE_UNCACHABLE 0
10162306a36Sopenharmony_ci#define MTRR_TYPE_WRCOMB     1
10262306a36Sopenharmony_ci/*#define MTRR_TYPE_         2*/
10362306a36Sopenharmony_ci/*#define MTRR_TYPE_         3*/
10462306a36Sopenharmony_ci#define MTRR_TYPE_WRTHROUGH  4
10562306a36Sopenharmony_ci#define MTRR_TYPE_WRPROT     5
10662306a36Sopenharmony_ci#define MTRR_TYPE_WRBACK     6
10762306a36Sopenharmony_ci#define MTRR_NUM_TYPES       7
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci/*
11062306a36Sopenharmony_ci * Invalid MTRR memory type.  No longer used outside of MTRR code.
11162306a36Sopenharmony_ci * Note, this value is allocated from the reserved values (0x7-0xff) of
11262306a36Sopenharmony_ci * the MTRR memory types.
11362306a36Sopenharmony_ci */
11462306a36Sopenharmony_ci#define MTRR_TYPE_INVALID    0xff
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci#endif /* _UAPI_ASM_X86_MTRR_H */
117