summaryrefslogtreecommitdiffstats
path: root/tools/ddcprobe/xbox.c
blob: ae1d8f0d789973e7fd5321aab987b494959bbe02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* test for an xbox and return video ram from fb device 
 * sbenedict@mandrakesoft.com
 */

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <ctype.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include "vbe.h"

int box_is_xbox() {
	int is_xbox = 0;
	int result = -1;
	int fd;
	size_t rd;
	char *xbox_id = "0000\t10de02a5";
	char id[13];

	if (!(fd = open("/proc/bus/pci/devices", O_RDONLY))) {
		printf("Unable to open /proc/bus/pci/devices\n");
	}
	if (!(rd = read(fd, id, sizeof(id)))) {
		printf("Unable to read /proc/bus/pci/devices\n");
	}

	if (fd > 0)
		close(fd);

#if DEBUG	
	printf("read_id: %s\n", id);	
	printf("xbox_id: %s\n", xbox_id);	
#endif
	result = strncmp(id, xbox_id, 13);
	if (result == 0)
		is_xbox = 1;
	return is_xbox;
}

/* taken from of.c */
int get_fb_info(struct vbe_info *ret)
{
        struct fb_fix_screeninfo fix;
	unsigned char *mem;
        int rc = 0;
        int fd = -1;
	int i;

	if (ret == NULL)
		return 0;

        if (!rc && !(fd = open("/dev/fb0", O_RDONLY)))
        {
                rc = 1;
                fprintf(stderr, "Unable to open /dev/fb0. Exiting.\n");
        }

        if ((!rc) && (ioctl(fd, FBIOGET_FSCREENINFO, &fix)))
        {
                rc = 1;
                fprintf(stderr, "Framebuffer ioctl failed. Exiting.\n");
        }

	if (fd > 0)
		close(fd);

        if (!rc)
        {
                // Note: if OFfb, vram info is unreliable!
		if (strcmp(fix.id, "OFfb"))
		{
			mem = strdup(fix.id);
			while(((i = strlen(mem)) > 0) && isspace(mem[i - 1])) {
				mem[i - 1] = '\0';
			}
			ret->oem_name = strdup(mem);
			ret->product_name = NULL;
			ret->vendor_name = NULL;
			ret->product_revision = NULL;
			ret->memory_size = fix.smem_len;
		}
        }

	return !rc;
}