1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci * 5f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify 6f08c3bdfSopenharmony_ci * it under the terms of the GNU General Public License as published by 7f08c3bdfSopenharmony_ci * the Free Software Foundation; either version 2 of the License, or 8f08c3bdfSopenharmony_ci * (at your option) any later version. 9f08c3bdfSopenharmony_ci * 10f08c3bdfSopenharmony_ci * This program is distributed in the hope that it will be useful, 11f08c3bdfSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 12f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13f08c3bdfSopenharmony_ci * the GNU General Public License for more details. 14f08c3bdfSopenharmony_ci * 15f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License 16f08c3bdfSopenharmony_ci * along with this program; if not, write to the Free Software 17f08c3bdfSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18f08c3bdfSopenharmony_ci * 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_ci * This example module shows how a test driver 21f08c3bdfSopenharmony_ci * can be driven through various ioctl calls in 22f08c3bdfSopenharmony_ci * a user space program that has attained the 23f08c3bdfSopenharmony_ci * appropriate file descriptor for this device. 24f08c3bdfSopenharmony_ci * 25f08c3bdfSopenharmony_ci * author: Kai Zhao 26f08c3bdfSopenharmony_ci * date: 09/03/2003 27f08c3bdfSopenharmony_ci * 28f08c3bdfSopenharmony_ci * module: tdrm 29f08c3bdfSopenharmony_ci */ 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_ci#include <linux/types.h> 32f08c3bdfSopenharmony_ci#include <linux/kernel.h> 33f08c3bdfSopenharmony_ci#include <linux/fs.h> 34f08c3bdfSopenharmony_ci#include <linux/ioctl.h> 35f08c3bdfSopenharmony_ci#include <linux/module.h> 36f08c3bdfSopenharmony_ci#include <linux/init.h> 37f08c3bdfSopenharmony_ci#include <asm/uaccess.h> 38f08c3bdfSopenharmony_ci#include "str_drm.h" 39f08c3bdfSopenharmony_ci 40f08c3bdfSopenharmony_ci#include <linux/config.h> 41f08c3bdfSopenharmony_ci#include "tdrm.h" 42f08c3bdfSopenharmony_ci#include "drmP.h" 43f08c3bdfSopenharmony_ci 44f08c3bdfSopenharmony_ci#define DRIVER_AUTHOR "Kai Zhao" 45f08c3bdfSopenharmony_ci 46f08c3bdfSopenharmony_ci#define DRIVER_DESC "drm test mode" 47f08c3bdfSopenharmony_ci#define DRIVER_DATE "20030903" 48f08c3bdfSopenharmony_ci 49f08c3bdfSopenharmony_cistatic drm_pci_list_t DRM(idlist)[] = 50f08c3bdfSopenharmony_ci{ 51f08c3bdfSopenharmony_ci { 52f08c3bdfSopenharmony_ci PCI_ANY_ID, PCI_ANY_ID}, { 53f08c3bdfSopenharmony_ci 0, 0} 54f08c3bdfSopenharmony_ci}; 55f08c3bdfSopenharmony_ci 56f08c3bdfSopenharmony_ci#define DRIVER_CARD_LIST DRM(idlist) 57f08c3bdfSopenharmony_ci 58f08c3bdfSopenharmony_ci#define DRIVER_FOPS \ 59f08c3bdfSopenharmony_cistatic struct file_operations DRM(fops) = { \ 60f08c3bdfSopenharmony_ci .owner = THIS_MODULE, \ 61f08c3bdfSopenharmony_ci .open = DRM(open), \ 62f08c3bdfSopenharmony_ci .flush = DRM(flush), \ 63f08c3bdfSopenharmony_ci .release = DRM(release), \ 64f08c3bdfSopenharmony_ci .ioctl = DRM(ioctl), \ 65f08c3bdfSopenharmony_ci .mmap = DRM(mmap), \ 66f08c3bdfSopenharmony_ci .read = DRM(read), \ 67f08c3bdfSopenharmony_ci .fasync = DRM(fasync), \ 68f08c3bdfSopenharmony_ci .poll = DRM(poll), \ 69f08c3bdfSopenharmony_ci} 70f08c3bdfSopenharmony_ci 71f08c3bdfSopenharmony_ci#include "drm_auth.h" 72f08c3bdfSopenharmony_ci#include "drm_bufs.h" 73f08c3bdfSopenharmony_ci#include "drm_context.h" 74f08c3bdfSopenharmony_ci#include "drm_dma.h" 75f08c3bdfSopenharmony_ci#include "drm_drawable.h" 76f08c3bdfSopenharmony_ci#include "drm_drv.h" 77f08c3bdfSopenharmony_ci 78f08c3bdfSopenharmony_cistatic int minor = 0; 79f08c3bdfSopenharmony_cistatic unsigned long alloc_pages_address = 0; 80f08c3bdfSopenharmony_ci 81f08c3bdfSopenharmony_ciint tdrm_test_stub_register(struct inode *inode, struct file *filp, 82f08c3bdfSopenharmony_ci unsigned int cmd, unsigned long arg) 83f08c3bdfSopenharmony_ci{ 84f08c3bdfSopenharmony_ci drm_file_t *priv = filp->private_data; 85f08c3bdfSopenharmony_ci drm_device_t *dev = priv->dev; 86f08c3bdfSopenharmony_ci minor = DRM(stub_register) (DEVICE_NAME, &DRM(fops), dev); 87f08c3bdfSopenharmony_ci printk("tdrm stub register : minor = %d\n", minor); 88f08c3bdfSopenharmony_ci return 0; 89f08c3bdfSopenharmony_ci 90f08c3bdfSopenharmony_ci} 91f08c3bdfSopenharmony_ci 92f08c3bdfSopenharmony_ciint tdrm_test_stub_unregister(struct inode *inode, struct file *filp, 93f08c3bdfSopenharmony_ci unsigned int cmd, unsigned long arg) 94f08c3bdfSopenharmony_ci{ 95f08c3bdfSopenharmony_ci DRM(stub_unregister) (minor); 96f08c3bdfSopenharmony_ci return 0; 97f08c3bdfSopenharmony_ci} 98f08c3bdfSopenharmony_ci 99f08c3bdfSopenharmony_ciint tdrm_test_uninit_agp(struct inode *inode, struct file *filp, 100f08c3bdfSopenharmony_ci unsigned int cmd, unsigned long arg) 101f08c3bdfSopenharmony_ci{ 102f08c3bdfSopenharmony_ci DRM(agp_uninit) (); 103f08c3bdfSopenharmony_ci return 0; 104f08c3bdfSopenharmony_ci} 105f08c3bdfSopenharmony_ci 106f08c3bdfSopenharmony_ciint tdrm_test_init_agp(struct inode *inode, struct file *filp, 107f08c3bdfSopenharmony_ci unsigned int cmd, unsigned long arg) 108f08c3bdfSopenharmony_ci{ 109f08c3bdfSopenharmony_ci DRM(agp_init) (); 110f08c3bdfSopenharmony_ci return 0; 111f08c3bdfSopenharmony_ci} 112f08c3bdfSopenharmony_ci 113f08c3bdfSopenharmony_ciint tdrm_test_add_magic(struct inode *inode, struct file *filp, 114f08c3bdfSopenharmony_ci unsigned int cmd, unsigned long arg) 115f08c3bdfSopenharmony_ci{ 116f08c3bdfSopenharmony_ci drm_file_t *priv = filp->private_data; 117f08c3bdfSopenharmony_ci drm_device_t *dev = priv->dev; 118f08c3bdfSopenharmony_ci int magic = 5; 119f08c3bdfSopenharmony_ci return (DRM(add_magic) (dev, priv, magic)); 120f08c3bdfSopenharmony_ci} 121f08c3bdfSopenharmony_ci 122f08c3bdfSopenharmony_ciint tdrm_test_remove_magic(struct inode *inode, struct file *filp, 123f08c3bdfSopenharmony_ci unsigned int cmd, unsigned long arg) 124f08c3bdfSopenharmony_ci{ 125f08c3bdfSopenharmony_ci drm_file_t *priv = filp->private_data; 126f08c3bdfSopenharmony_ci drm_device_t *dev = priv->dev; 127f08c3bdfSopenharmony_ci int magic = 5; 128f08c3bdfSopenharmony_ci return (DRM(remove_magic) (dev, magic)); 129f08c3bdfSopenharmony_ci} 130f08c3bdfSopenharmony_ci 131f08c3bdfSopenharmony_ciint tdrm_test_ctxbitmap_init(struct inode *inode, struct file *filp, 132f08c3bdfSopenharmony_ci unsigned int cmd, unsigned long arg) 133f08c3bdfSopenharmony_ci{ 134f08c3bdfSopenharmony_ci drm_file_t *priv = filp->private_data; 135f08c3bdfSopenharmony_ci drm_device_t *dev = priv->dev; 136f08c3bdfSopenharmony_ci return (DRM(ctxbitmap_init) (dev)); 137f08c3bdfSopenharmony_ci} 138f08c3bdfSopenharmony_ci 139f08c3bdfSopenharmony_ciint tdrm_test_ctxbitmap_cleanup(struct inode *inode, struct file *filp, 140f08c3bdfSopenharmony_ci unsigned int cmd, unsigned long arg) 141f08c3bdfSopenharmony_ci{ 142f08c3bdfSopenharmony_ci drm_file_t *priv = filp->private_data; 143f08c3bdfSopenharmony_ci drm_device_t *dev = priv->dev; 144f08c3bdfSopenharmony_ci DRM(ctxbitmap_cleanup) (dev); 145f08c3bdfSopenharmony_ci return 0; 146f08c3bdfSopenharmony_ci} 147f08c3bdfSopenharmony_ci 148f08c3bdfSopenharmony_ciint tdrm_test_alloc_pages(struct inode *inode, struct file *filp, 149f08c3bdfSopenharmony_ci unsigned int cmd, unsigned long arg) 150f08c3bdfSopenharmony_ci{ 151f08c3bdfSopenharmony_ci alloc_pages_address = DRM(alloc_pages) (1, 0); 152f08c3bdfSopenharmony_ci// printk("address = %ld\n",alloc_pages_address); 153f08c3bdfSopenharmony_ci return 0; 154f08c3bdfSopenharmony_ci} 155f08c3bdfSopenharmony_ci 156f08c3bdfSopenharmony_ciint tdrm_test_free_pages(struct inode *inode, struct file *filp, 157f08c3bdfSopenharmony_ci unsigned int cmd, unsigned long arg) 158f08c3bdfSopenharmony_ci{ 159f08c3bdfSopenharmony_ci DRM(free_pages) (alloc_pages_address, 1, 0); 160f08c3bdfSopenharmony_ci return 0; 161f08c3bdfSopenharmony_ci} 162f08c3bdfSopenharmony_ci 163f08c3bdfSopenharmony_ci#ifndef MODULE 164f08c3bdfSopenharmony_ci 165f08c3bdfSopenharmony_ci/* JH- We have to hand expand the string ourselves because of the cpp. If 166f08c3bdfSopenharmony_ci * anyone can think of a way that we can fit into the __setup macro without 167f08c3bdfSopenharmony_ci * changing it, then please send the solution my way. 168f08c3bdfSopenharmony_ci */ 169f08c3bdfSopenharmony_cistatic int __init tdrm_options(char *str) 170f08c3bdfSopenharmony_ci{ 171f08c3bdfSopenharmony_ci DRM(parse_options) (str); 172f08c3bdfSopenharmony_ci return 1; 173f08c3bdfSopenharmony_ci} 174f08c3bdfSopenharmony_ci 175f08c3bdfSopenharmony_ci__setup(DRIVER_NAME "=", tdrm_options); 176f08c3bdfSopenharmony_ci#endif 177f08c3bdfSopenharmony_ci 178f08c3bdfSopenharmony_ci#include "drm_fops.h" 179f08c3bdfSopenharmony_ci#include "drm_init.h" 180f08c3bdfSopenharmony_ci#include "drm_ioctl.h" 181f08c3bdfSopenharmony_ci#include "drm_lock.h" 182f08c3bdfSopenharmony_ci#include "drm_memory.h" 183f08c3bdfSopenharmony_ci#include "drm_proc.h" 184f08c3bdfSopenharmony_ci#include "drm_vm.h" 185f08c3bdfSopenharmony_ci#include "drm_stub.h" 186f08c3bdfSopenharmony_ci#include "drm_agpsupport.h" 187