drm_memory.c revision 1.28
1/* $OpenBSD: drm_memory.c,v 1.28 2019/04/14 10:14:51 jsg Exp $ */
2/*-
3 *Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
4 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25 *
26 * Authors:
27 *    Rickard E. (Rik) Faith <faith@valinux.com>
28 *    Gareth Hughes <gareth@valinux.com>
29 *
30 */
31
32/** @file drm_memory.c
33 * Wrappers for MTRR management support.
34 */
35
36#include <drm/drmP.h>
37
38#if !defined(__amd64__) && !defined(__i386__)
39#define DRM_NO_MTRR	1
40#endif
41
42int
43drm_mtrr_add(unsigned long offset, size_t size, int flags)
44{
45#ifndef DRM_NO_MTRR
46	int act;
47	struct mem_range_desc mrdesc;
48
49	mrdesc.mr_base = offset;
50	mrdesc.mr_len = size;
51	mrdesc.mr_flags = flags;
52	act = MEMRANGE_SET_UPDATE;
53	strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner));
54	return mem_range_attr_set(&mrdesc, &act);
55#else
56	return 0;
57#endif
58}
59
60int
61drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags)
62{
63#ifndef DRM_NO_MTRR
64	int act;
65	struct mem_range_desc mrdesc;
66
67	mrdesc.mr_base = offset;
68	mrdesc.mr_len = size;
69	mrdesc.mr_flags = flags;
70	act = MEMRANGE_SET_REMOVE;
71	strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner));
72	return mem_range_attr_set(&mrdesc, &act);
73#else
74	return 0;
75#endif
76}
77