1/* Author:
2   Rudolf Cornelissen 6/2004-9/2004
3*/
4
5#define MODULE_BIT 0x00000100
6
7#include <unistd.h>
8#include "std.h"
9
10
11status_t
12eng_agp_setup(void)
13{
14	eng_nth_agp_info nai;
15	eng_cmd_agp nca;
16	uint8 index;
17	agp_info eng_ai;
18	bool agp = false;
19	eng_ai.interface.status = 0;
20
21	/* set the magic number so the via kerneldriver knows we're for real */
22	nca.magic = nai.magic = VIA_PRIVATE_DATA_MAGIC;
23
24	/* contact driver and get a pointer to the registers and shared data */
25	for (index = 0; index < 8; index++) {
26		/* get nth AGP device info */
27		nai.index = index;
28		ioctl(fd, ENG_GET_NTH_AGP_INFO, &nai, sizeof(nai));
29
30		/* abort if no agp busmanager found */
31		if (!nai.agp_bus) {
32			LOG(4,("AGP: no AGP busmanager found.\n"));
33			/* don't touch AGP command register, we don't know what has been setup:
34			 * touching it anyway might 'hang' the graphics card! */
35
36			return B_ERROR;
37		}
38
39		/* exit if we didn't get device info for this index */
40		if (!nai.exist) {
41			if (index != 0)
42				LOG(4,("AGP: end of AGP capable devices list.\n"));
43			else
44				LOG(4,("AGP: no AGP capable devices found.\n"));
45			break;
46		}
47
48		LOG(4,("AGP: AGP capable device #%d:\n", (index + 1)));
49
50		/* see if we are this one */
51		if (nai.agpi.device_id == si->device_id
52			&& nai.agpi.vendor_id == si->vendor_id
53			&& nai.agpi.bus == si->bus
54			&& nai.agpi.device == si->device
55			&& nai.agpi.function == si->function) {
56			LOG(4,("AGP: (this is the device this accelerant controls)\n"));
57			agp = true;
58			/* remember our info */
59			eng_ai = nai.agpi;
60		}
61	}
62
63	/* if our card is not an AGP type, abort here */
64	/* Note:
65	 * We have to iterate through the capability list as specified in the PCI spec
66	 * one way or the other, otherwise we cannot distinquish between PCI and
67	 * AGP type cards as PCI cards still might have AGP registers that pretend to
68	 * support AGP.
69	 * We rely on the AGP busmanager to iterate trough this list for us. */
70	if (!agp) {
71		LOG(4,("AGP: the graphicscard this accelerant controls is PCI type.\n"));
72
73		/* make sure card is set for PCI access */
74//		CFGW(AGPCMD, 0x00000000);
75
76		return B_ERROR;
77	}
78
79	if (si->settings.force_pci) {
80		/* set PCI mode if specified by user in skel.settings */
81		LOG(4,("AGP: forcing PCI mode (specified in via.settings)\n"));
82
83		/* let the AGP busmanager setup PCI mode.
84		 * (the AGP speed scheme is of no consequence now) */
85		nca.cmd = 0x00000000;
86		ioctl(fd, ENG_ENABLE_AGP, &nca, sizeof(nca));
87	} else {
88		/* activate AGP mode */
89		LOG(4,("AGP: activating AGP mode...\n"));
90
91		/* let the AGP busmanager worry about what mode to set.. */
92		nca.cmd = 0xfffffff7;
93		/* ..but we do need to select the right speed scheme fetched from our card */
94		if (eng_ai.interface.status & AGP_3_MODE)
95			nca.cmd |= AGP_3_MODE;
96		ioctl(fd, ENG_ENABLE_AGP, &nca, sizeof(nca));
97	}
98
99	/* extra check */
100//	LOG(4,("AGP: graphics card AGPCMD register readback $%08x\n", CFGR(AGPCMD)));
101	return B_OK;
102}
103
104