~ubuntu-branches/debian/sid/xserver-xorg-video-geode/sid

« back to all changes in this revision

Viewing changes to .pc/0001-Geode-MSR-support-for-OpenBSD.patch/src/geode_msr.c

  • Committer: Package Import Robot
  • Author(s): Martin-Éric Racine
  • Date: 2015-05-06 16:17:34 UTC
  • Revision ID: package-import@ubuntu.com-20150506161734-vck4k9wzaxamoupb
Tags: 2.11.16-9
Bumped debhelper compat level to 9.
Thanks to Julien Cristau for the debian/rules snippet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2008 Advanced Micro Devices, Inc.
 
3
 *
 
4
 * Permission is hereby granted, free of charge, to any person obtaining a
 
5
 * copy of this software and associated documentation files (the "Software"),
 
6
 * to deal in the Software without restriction, including without limitation
 
7
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
8
 * and/or sell copies of the Software, and to permit persons to whom the
 
9
 * Software is furnished to do so, subject to the following conditions:
 
10
 *
 
11
 * The above copyright notice and this permission notice shall be included in
 
12
 * all copies or substantial portions of the Software.
 
13
 *
 
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
15
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
17
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
18
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
19
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
20
 * DEALINGS IN THE SOFTWARE.
 
21
 *
 
22
 * Neither the name of the Advanced Micro Devices, Inc. nor the names of its
 
23
 * contributors may be used to endorse or promote products derived from this
 
24
 * software without specific prior written permission.
 
25
 */
 
26
 
 
27
#ifdef HAVE_CONFIG_H
 
28
#include "config.h"
 
29
#endif
 
30
 
 
31
#include <stdio.h>
 
32
#include <unistd.h>
 
33
#include <fcntl.h>
 
34
#include <sys/types.h>
 
35
#include <errno.h>
 
36
#include "os.h"
 
37
#include "geode.h"
 
38
 
 
39
static int
 
40
_msr_open(void)
 
41
{
 
42
    static int msrfd = 0;
 
43
 
 
44
    if (msrfd == 0) {
 
45
        msrfd = open("/dev/cpu/0/msr", O_RDWR);
 
46
        if (msrfd == -1)
 
47
            ErrorF("Unable to open /dev/cpu/0/msr: %d\n", errno);
 
48
    }
 
49
 
 
50
    return msrfd;
 
51
}
 
52
 
 
53
int
 
54
GeodeReadMSR(unsigned long addr, unsigned long *lo, unsigned long *hi)
 
55
{
 
56
    unsigned int data[2];
 
57
    int fd = _msr_open();
 
58
    int ret;
 
59
 
 
60
    if (fd == -1)
 
61
        return -1;
 
62
 
 
63
    ret = lseek(fd, (off_t) addr, SEEK_SET);
 
64
 
 
65
    if (ret == -1)
 
66
        return -1;
 
67
 
 
68
    ret = read(fd, (void *) data, sizeof(data));
 
69
 
 
70
    if (ret != 8)
 
71
        return -1;
 
72
 
 
73
    *hi = data[1];
 
74
    *lo = data[0];
 
75
 
 
76
    return 0;
 
77
}
 
78
 
 
79
int
 
80
GeodeWriteMSR(unsigned long addr, unsigned long lo, unsigned long hi)
 
81
{
 
82
    unsigned int data[2];
 
83
    int fd = _msr_open();
 
84
 
 
85
    if (fd == -1)
 
86
        return -1;
 
87
 
 
88
    if (lseek(fd, (off_t) addr, SEEK_SET) == -1)
 
89
        return -1;
 
90
 
 
91
    data[0] = lo;
 
92
    data[1] = hi;
 
93
 
 
94
    if (write(fd, (void *) data, 8) != 8)
 
95
        return -1;
 
96
 
 
97
    return 0;
 
98
}