Comment out the correct #endif directive.
[mplayer/greg.git] / vidix / mtrr.c
blob9b0d11dbfd1cf65fde86fb7fe2b0bb5b26e6b9c5
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
18 * along with MPlayer; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "config.h"
25 #include <stdio.h>
26 #include <string.h>
27 #include <errno.h>
28 #include "dha.h"
29 #include "AsmMacros.h"
31 #if defined (__i386__) && defined (__NetBSD__)
32 #include <sys/param.h>
33 #if __NetBSD_Version__ > 105240000
34 #include <stdint.h>
35 #include <stdlib.h>
36 #include <machine/mtrr.h>
37 #include <machine/sysarch.h>
38 #endif
39 #endif
41 int mtrr_set_type(unsigned base,unsigned size,int type)
43 #ifdef linux
44 FILE * mtrr_fd;
45 char * stype;
46 switch(type)
48 case MTRR_TYPE_UNCACHABLE: stype = "uncachable"; break;
49 case MTRR_TYPE_WRCOMB: stype = "write-combining"; break;
50 case MTRR_TYPE_WRTHROUGH: stype = "write-through"; break;
51 case MTRR_TYPE_WRPROT: stype = "write-protect"; break;
52 case MTRR_TYPE_WRBACK: stype = "write-back"; break;
53 default: return EINVAL;
55 mtrr_fd = fopen("/proc/mtrr","wt");
56 if(mtrr_fd)
58 char sout[256];
59 unsigned wr_len;
60 sprintf(sout,"base=0x%08X size=0x%08X type=%s\n",base,size,stype);
61 wr_len = fprintf(mtrr_fd,sout);
62 /*printf("MTRR: %s\n",sout);*/
63 fclose(mtrr_fd);
64 return wr_len == strlen(sout) ? 0 : EPERM;
66 return ENOSYS;
67 #elif defined (__i386__ ) && defined (__NetBSD__) && __NetBSD_Version__ > 105240000
68 struct mtrr *mtrrp;
69 int n;
71 mtrrp = malloc(sizeof (struct mtrr));
72 mtrrp->base = base;
73 mtrrp->len = size;
74 mtrrp->type = type;
75 mtrrp->flags = MTRR_VALID | MTRR_PRIVATE;
76 n = 1;
78 if (i386_set_mtrr(mtrrp, &n) < 0) {
79 free(mtrrp);
80 return errno;
82 free(mtrrp);
83 return 0;
84 #else
85 /* NetBSD prior to 1.5Y doesn't have MTRR support */
86 return ENOSYS;
87 #endif