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