mtrr.h revision 1.2
11.2Sriastrad/*	$NetBSD: mtrr.h,v 1.2 2014/03/18 18:20:42 riastradh Exp $	*/
21.2Sriastrad
31.2Sriastrad/*-
41.2Sriastrad * Copyright (c) 2013 The NetBSD Foundation, Inc.
51.2Sriastrad * All rights reserved.
61.2Sriastrad *
71.2Sriastrad * This code is derived from software contributed to The NetBSD Foundation
81.2Sriastrad * by Taylor R. Campbell.
91.2Sriastrad *
101.2Sriastrad * Redistribution and use in source and binary forms, with or without
111.2Sriastrad * modification, are permitted provided that the following conditions
121.2Sriastrad * are met:
131.2Sriastrad * 1. Redistributions of source code must retain the above copyright
141.2Sriastrad *    notice, this list of conditions and the following disclaimer.
151.2Sriastrad * 2. Redistributions in binary form must reproduce the above copyright
161.2Sriastrad *    notice, this list of conditions and the following disclaimer in the
171.2Sriastrad *    documentation and/or other materials provided with the distribution.
181.2Sriastrad *
191.2Sriastrad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.2Sriastrad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.2Sriastrad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.2Sriastrad * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.2Sriastrad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.2Sriastrad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.2Sriastrad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.2Sriastrad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.2Sriastrad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.2Sriastrad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.2Sriastrad * POSSIBILITY OF SUCH DAMAGE.
301.2Sriastrad */
311.2Sriastrad
321.2Sriastrad#ifndef _ASM_MTRR_H_
331.2Sriastrad#define _ASM_MTRR_H_
341.2Sriastrad
351.2Sriastrad#ifdef _KERNEL_OPT
361.2Sriastrad#include "opt_mtrr.h"
371.2Sriastrad#endif
381.2Sriastrad
391.2Sriastrad#include <machine/mtrr.h>
401.2Sriastrad
411.2Sriastrad#define	MTRR_TYPE_WRCOMB	MTRR_TYPE_WC
421.2Sriastrad
431.2Sriastradstatic inline int
441.2Sriastradmtrr_add(unsigned long base, unsigned long size, int type,
451.2Sriastrad    bool increment __unused)
461.2Sriastrad{
471.2Sriastrad#ifdef MTRR
481.2Sriastrad	struct mtrr mtrr;
491.2Sriastrad	int n = 1;
501.2Sriastrad
511.2Sriastrad	mtrr.base = base;
521.2Sriastrad	mtrr.len = size;
531.2Sriastrad	mtrr.type = type;
541.2Sriastrad	mtrr.flags = MTRR_VALID;
551.2Sriastrad
561.2Sriastrad	/* XXX errno NetBSD->Linux */
571.2Sriastrad	return -mtrr_set(&mtrr, &n, NULL, MTRR_GETSET_KERNEL);
581.2Sriastrad#else
591.2Sriastrad	return 0;
601.2Sriastrad#endif
611.2Sriastrad}
621.2Sriastrad
631.2Sriastradstatic inline int
641.2Sriastradmtrr_del(int handle __unused, unsigned long base, unsigned long size)
651.2Sriastrad{
661.2Sriastrad#ifdef MTRR
671.2Sriastrad	struct mtrr mtrr;
681.2Sriastrad	int n = 1;
691.2Sriastrad
701.2Sriastrad	mtrr.base = base;
711.2Sriastrad	mtrr.len = size;
721.2Sriastrad	mtrr.type = 0;
731.2Sriastrad	mtrr.flags = 0;		/* not MTRR_VALID */
741.2Sriastrad
751.2Sriastrad	/* XXX errno NetBSD->Linux */
761.2Sriastrad	return -mtrr_set(&mtrr, &n, NULL, MTRR_GETSET_KERNEL);
771.2Sriastrad#else
781.2Sriastrad	return 0;
791.2Sriastrad#endif
801.2Sriastrad}
811.2Sriastrad
821.2Sriastrad#endif  /* _ASM_MTRR_H_ */
83