Move -vo gl suboptions that should be irrelevant for the average user
[mplayer/glamo.git] / libdha / mtrr.c
blob04f4d5ac3b751a342b0b7f93b06305b394b15250
1 /*
2 mtrr.c - Stuff for optimizing memory access
3 Copyrights:
4 2002 - Linux version by Nick Kurshev
5 Licence: GPL
6 */
8 #include "config.h"
10 #include <stdio.h>
11 #include <string.h>
12 #include <errno.h>
13 #include "libdha.h"
14 #include "AsmMacros.h"
16 #if defined (__i386__) && defined (__NetBSD__)
17 #include <sys/param.h>
18 #if __NetBSD_Version__ > 105240000
19 #include <stdint.h>
20 #include <stdlib.h>
21 #include <machine/mtrr.h>
22 #include <machine/sysarch.h>
23 #endif
24 #endif
26 int mtrr_set_type(unsigned base,unsigned size,int type)
28 #ifdef linux
29 FILE * mtrr_fd;
30 char * stype;
31 switch(type)
33 case MTRR_TYPE_UNCACHABLE: stype = "uncachable"; break;
34 case MTRR_TYPE_WRCOMB: stype = "write-combining"; break;
35 case MTRR_TYPE_WRTHROUGH: stype = "write-through"; break;
36 case MTRR_TYPE_WRPROT: stype = "write-protect"; break;
37 case MTRR_TYPE_WRBACK: stype = "write-back"; break;
38 default: return EINVAL;
40 mtrr_fd = fopen("/proc/mtrr","wt");
41 if(mtrr_fd)
43 char sout[256];
44 unsigned wr_len;
45 sprintf(sout,"base=0x%08X size=0x%08X type=%s\n",base,size,stype);
46 wr_len = fprintf(mtrr_fd,sout);
47 /*printf("MTRR: %s\n",sout);*/
48 fclose(mtrr_fd);
49 return wr_len == strlen(sout) ? 0 : EPERM;
51 return ENOSYS;
52 #elif defined (__i386__ ) && defined (__NetBSD__) && __NetBSD_Version__ > 105240000
53 struct mtrr *mtrrp;
54 int n;
56 mtrrp = malloc(sizeof (struct mtrr));
57 mtrrp->base = base;
58 mtrrp->len = size;
59 mtrrp->type = type;
60 mtrrp->flags = MTRR_VALID | MTRR_PRIVATE;
61 n = 1;
63 if (i386_set_mtrr(mtrrp, &n) < 0) {
64 free(mtrrp);
65 return errno;
67 free(mtrrp);
68 return 0;
69 #else
70 /* NetBSD prior to 1.5Y doesn't have MTRR support */
71 return ENOSYS;
72 #endif