user_tagp.c revision d13d74bbf207c2d01598c6fef092a75b93b07c71
1/* 2 * 3 * Copyright (c) International Business Machines Corp., 2001 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 * the GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 */ 19/* 20 * This is the main of your user space test program, 21 * which will open the correct kernel module, find the 22 * file descriptor value and use that value to make 23 * ioctl calls to the system 24 * 25 * Use the ki_generic and other ki_testname functions 26 * to abstract the calls from the main 27 * 28 * author: Kai Zhao 29 * date: 08/25/2003 30 * 31 */ 32 33#include <stdio.h> 34#include <stdlib.h> 35#include <errno.h> 36#include <sys/stat.h> 37#include <sys/ioctl.h> 38#include <fcntl.h> 39#include <linux/kernel.h> 40#include <linux/errno.h> 41 42#include "user_tagp.h" 43#include "../kernel_space/tagp.h" 44 45static int tagp_fd = -1; /* file descriptor */ 46 47int tagpopen() { 48 49 dev_t devt; 50 struct stat st; 51 int rc = 0; 52 53 devt = makedev(TAGP_MAJOR, 0); 54 55 if (rc) { 56 if (errno == ENOENT) { 57 /* dev node does not exist. */ 58 rc = mkdir(DEVICE_NAME, (S_IFDIR | S_IRWXU | 59 S_IRGRP | S_IXGRP | 60 S_IROTH | S_IXOTH)); 61 } else { 62 printf("ERROR: Problem with Base dev directory. Error code from stat() is %d\n\n", errno); 63 } 64 65 } else { 66 if (!(st.st_mode & S_IFDIR)) { 67 rc = unlink(DEVICE_NAME); 68 if (!rc) { 69 rc = mkdir(DEVICE_NAME, (S_IFDIR | S_IRWXU | 70 S_IRGRP | S_IXGRP | 71 S_IROTH | S_IXOTH)); 72 } 73 } 74 } 75 76 77 /* 78 * Check for the /dev/tbase node, and create if it does not 79 * exist. 80 */ 81 rc = stat(DEVICE_NAME, &st); 82 if (rc) { 83 if (errno == ENOENT) { 84 /* dev node does not exist */ 85 rc = mknod(DEVICE_NAME, (S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP), devt); 86 } else { 87 printf("ERROR:Problem with tbase device node directory. Error code form stat() is %d\n\n", errno); 88 } 89 90 } else { 91 /* 92 * /dev/tbase CHR device exists. Check to make sure it is for a 93 * block device and that it has the right major and minor. 94 */ 95 if ((!(st.st_mode & S_IFCHR)) || 96 (st.st_rdev != devt)) { 97 98 /* Recreate the dev node. */ 99 rc = unlink(DEVICE_NAME); 100 if (!rc) { 101 rc = mknod(DEVICE_NAME, (S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP), devt); 102 } 103 } 104 } 105 106 tagp_fd = open(DEVICE_NAME, O_RDWR); 107 108 if (tagp_fd < 0) { 109 printf("ERROR: Open of device %s failed %d errno = %d\n", DEVICE_NAME,tagp_fd, errno); 110 return errno; 111 } 112 else { 113 printf("Device opened successfully \n"); 114 return 0; 115 } 116 117} 118 119 120int 121tagpclose() { 122 123 if (tagp_fd != -1) { 124 close (tagp_fd); 125 tagp_fd = -1; 126 } 127 128 return 0; 129} 130 131int agpgart_io_test() 132{ 133 int tagp_fd = 0; 134 char read_buf[BUFFER_LEN]; 135 136 if ((tagp_fd = open("/dev/agpgart", O_RDWR)) < 0) { 137 printf("Open /dev/agpgart failed \n"); 138 return -1; 139 } 140 141 close(tagp_fd); 142 143 return 0; 144} 145 146 147int main() { 148 int rc; 149 150 if(agpgart_io_test()) 151 printf("Test agpgart io failed\n"); 152 else 153 printf("Test agpgart io success\n"); 154 155 /* open the module */ 156 rc = tagpopen(); 157 if (rc ) { 158 printf("Test AGP Driver may not be loaded\n"); 159 exit(1); 160 } 161 162 /* make test calls for pci_find_device*/ 163 if(ki_generic(tagp_fd, TEST_PCI_FIND_DEV)) 164 printf("Success: Expected failure for pci_find_dev test\n"); 165 else 166 printf("Fail on pci_find_dev test\n"); 167 168 /* make test calls for agp_backend_acquier */ 169 if(ki_generic(tagp_fd, TEST_BACKEND_ACQUIRE)) 170 printf("Fail on agp_backend_acquier\n"); 171 else 172 printf("Success on agp_backend_acquier\n"); 173 174 /* make test calls for agp_backend_release */ 175 if(ki_generic(tagp_fd, TEST_BACKEND_RELEASE)) 176 printf("Fail on agp_backend_release\n"); 177 else 178 printf("Success on agp_backend_release\n"); 179 180 /* make test calls for agp_alloc_bridge */ 181 if(ki_generic(tagp_fd, TEST_ALLOC_BRIDGE)) 182 printf("Fail on agp_alloc_bridge \n"); 183 else 184 printf("Success on agp_alloc_bridge\n"); 185 186 /* make test calls for and agp_put_bridge */ 187 if(ki_generic(tagp_fd, TEST_PUT_BRIDGE)) 188 printf("Fail on agp_put_bridge\n"); 189 else 190 printf("Success on agp_put_bridge\n"); 191 192 /* make test calls for agp_create_memory and agp_free_memory */ 193 if(ki_generic(tagp_fd, TEST_CREATE_AND_FREE_MEMORY)) 194 printf("Fail on agp_create_memory \n"); 195 else 196 printf("Success on agp_create_memory\n"); 197/* 198 if(ki_generic(tagp_fd, TEST_FREE_MEMORY)) 199 printf("Fail on agp_free_memory\n"); 200 else 201 printf("Success on agp_free_memory\n"); 202*/ /////////////////////////////////////////////////////////////////////// 203 /* make test calls for agp_num_entries */ 204 if(ki_generic(tagp_fd, TEST_NUM_ENTRIES)) 205 printf("Fail on agp_num_entries\n"); 206 else 207 printf("Success on agp_num_entries\n"); 208 209 /* make test calls for agp_copy_info */ 210 if(ki_generic(tagp_fd, TEST_COPY_INFO)) 211 printf("Fail on agp_copy_info\n"); 212 else 213 printf("Success on agp_copy_info\n"); 214 215 /* make test calls for agp_alloc_memory */ 216// if(ki_generic(tagp_fd, TEST_ALLOC_MEMORY_AND_BAND_UNBAND)) 217// printf("Fail on agp_alloc_memory_and_band_unband\n"); 218// else 219// printf("Success on agp_alloc_memory_and_band_unband\n"); 220 221 /* make test calls for agp_get_version */ 222 if(ki_generic(tagp_fd, TEST_GET_VERSION)) 223 printf("Fail on agp_get_version\n"); 224 else 225 printf("Success on agp_get_version\n"); 226 227 /* make test calls for agp_generic_enable */ 228 if(ki_generic(tagp_fd, TEST_GENERIC_ENABLE)) 229 printf("Fail on agp_generic_enable\n"); 230 else 231 printf("Success on agp_generic_enable\n"); 232 233 /* make test calls for agp_generic_create_gatt_table */ 234 if(ki_generic(tagp_fd, TEST_GENERIC_CREATE_GATT_TABLE)) 235 printf("Fail on agp_generic_create_gatt_table\n"); 236 else 237 printf("Success on agp_generic_create_gatt_table\n"); 238 239 240 /* make test calls for agp_generic_free_gatt_table */ 241 if(ki_generic(tagp_fd, TEST_GENERIC_FREE_GATT_TABLE)) 242 printf("Fail on agp_generic_free_gatt_table\n"); 243 else 244 printf("Success on agp_generic_free_gatt_table\n"); 245 246 247 /* make test calls for agp_generic_insert_memory */ 248 if(ki_generic(tagp_fd, TEST_GENERIC_INSERT_MEMROY)) 249 printf("Fail on agp_generic_insert_memory\n"); 250 else 251 printf("Success on agp_generic_insert_memory\n"); 252 253 /* make test calls for agp_generic_alloc_by_type */ 254 if(ki_generic(tagp_fd, TEST_GENERIC_ALLOC_BY_TYPE)) 255 printf("Fail on agp_generic_alloc_by_type\n"); 256 else 257 printf("Success on agp_generic_alloc_by_type\n"); 258 259 /* make test calls for agp_generic_alloc_page */ 260 if(ki_generic(tagp_fd, TEST_GENERIC_ALLOC_PAGE)) 261 printf("Fail on agp_generic_alloc_page\n"); 262 else 263 printf("Success on agp_generic_alloc_page\n"); 264 265 /* make test calls for agp_generic_destory_page */ 266 if(ki_generic(tagp_fd, TEST_GENERIC_ALLOC_PAGE)) 267 printf("Fail on agp_generic_destory_page\n"); 268 else 269 printf("Success on agp_generic_destory_page\n"); 270 271 /* make test calls for agp_enable */ 272 if(ki_generic(tagp_fd, TEST_ENABLE)) 273 printf("Fail on agp_enable\n"); 274 else 275 printf("Success on agp_enable\n"); 276 277 /* make test calls for agp_global_cache_flush */ 278 if(ki_generic(tagp_fd, TEST_GLOBAL_CACHE_FLUSH)) 279 printf("Fail on agp_global_cache_flush\n"); 280 else 281 printf("Success on agp_gloabl_cache_flush\n"); 282 283 /* make test calls for agp_generic_mask_memory */ 284 if(ki_generic(tagp_fd, TEST_GENERIC_MASK_MEMORY)) 285 printf("Fail on agp_generic_mask_memory\n"); 286 else 287 printf("Success on agp_generic_mask_memory\n"); 288 289 /* close the module */ 290 rc = tagpclose(); 291 if (rc ) { 292 printf("Test AGP Driver may not be closed\n"); 293 exit(1); 294 } 295 296 return 0; 297} 298