vo_kva: Restore all the attributes after changing aspect ratio
[mplayer/glamo.git] / vidix / mtrr.c
blob372d6ffb26b00e0fb67b728fbb0e367232f4116e
1 /*
2 * VIDIX Memory access optimization routines.
3 * Copyright (C) 2002 Nick Kurshev
5 * This file is part of MPlayer.
7 * MPlayer is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * MPlayer is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "config.h"
24 #include <stdio.h>
25 #include <string.h>
26 #include <errno.h>
27 #include "dha.h"
28 #include "AsmMacros.h"
30 #if defined (__i386__) && defined (__NetBSD__)
31 #include <sys/param.h>
32 #if __NetBSD_Version__ > 105240000
33 #include <stdint.h>
34 #include <stdlib.h>
35 #include <machine/mtrr.h>
36 #include <machine/sysarch.h>
37 #endif
38 #endif
40 int mtrr_set_type(unsigned base,unsigned size,int type)
42 #ifdef __linux__
43 FILE * mtrr_fd;
44 const char *stype;
45 switch(type)
47 case MTRR_TYPE_UNCACHABLE: stype = "uncachable"; break;
48 case MTRR_TYPE_WRCOMB: stype = "write-combining"; break;
49 case MTRR_TYPE_WRTHROUGH: stype = "write-through"; break;
50 case MTRR_TYPE_WRPROT: stype = "write-protect"; break;
51 case MTRR_TYPE_WRBACK: stype = "write-back"; break;
52 default: return EINVAL;
54 mtrr_fd = fopen("/proc/mtrr","wt");
55 if(mtrr_fd)
57 int wr_len = fprintf(mtrr_fd, "base=0x%08X size=0x%08X type=%s\n", base, size, stype);
58 fclose(mtrr_fd);
59 return wr_len > 0 ? 0 : EPERM;
61 return ENOSYS;
62 #elif defined (__i386__ ) && defined (__NetBSD__) && __NetBSD_Version__ > 105240000
63 struct mtrr *mtrrp;
64 int n;
66 mtrrp = malloc(sizeof (struct mtrr));
67 mtrrp->base = base;
68 mtrrp->len = size;
69 mtrrp->type = type;
70 mtrrp->flags = MTRR_VALID | MTRR_PRIVATE;
71 n = 1;
73 if (i386_set_mtrr(mtrrp, &n) < 0) {
74 free(mtrrp);
75 return errno;
77 free(mtrrp);
78 return 0;
79 #else
80 /* NetBSD prior to 1.5Y doesn't have MTRR support */
81 return ENOSYS;
82 #endif