• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18   *
19  
20   * This example module shows how a test driver
21   * can be driven through various ioctl calls in
22   * a user space program that has attained the
23   * appropriate file descriptor for this device.
24   *
25   * author: Kai Zhao
26   * date:   09/03/2003
27   *
28   * module: tdrm
29   */
30  
31  #include <linux/types.h>
32  #include <linux/kernel.h>
33  #include <linux/fs.h>
34  #include <linux/ioctl.h>
35  #include <linux/module.h>
36  #include <linux/init.h>
37  #include <asm/uaccess.h>
38  #include "str_drm.h"
39  
40  #include <linux/config.h>
41  #include "tdrm.h"
42  #include "drmP.h"
43  
44  #define DRIVER_AUTHOR		"Kai Zhao"
45  
46  #define DRIVER_DESC		"drm test mode"
47  #define DRIVER_DATE		"20030903"
48  
49  static drm_pci_list_t DRM(idlist)[] =
50  {
51  	{
52  	PCI_ANY_ID, PCI_ANY_ID}, {
53  	0, 0}
54  };
55  
56  #define DRIVER_CARD_LIST DRM(idlist)
57  
58  #define DRIVER_FOPS						\
59  static struct file_operations	DRM(fops) = {			\
60  	.owner   		= THIS_MODULE,			\
61  	.open	 		= DRM(open),			\
62  	.flush	 		= DRM(flush),			\
63  	.release 		= DRM(release),			\
64  	.ioctl	 		= DRM(ioctl),			\
65  	.mmap	 		= DRM(mmap),			\
66  	.read	 		= DRM(read),			\
67  	.fasync	 		= DRM(fasync),			\
68  	.poll	 		= DRM(poll),			\
69  }
70  
71  #include "drm_auth.h"
72  #include "drm_bufs.h"
73  #include "drm_context.h"
74  #include "drm_dma.h"
75  #include "drm_drawable.h"
76  #include "drm_drv.h"
77  
78  static int minor = 0;
79  static unsigned long alloc_pages_address = 0;
80  
tdrm_test_stub_register(struct inode * inode,struct file * filp,unsigned int cmd,unsigned long arg)81  int tdrm_test_stub_register(struct inode *inode, struct file *filp,
82  			    unsigned int cmd, unsigned long arg)
83  {
84  	drm_file_t *priv = filp->private_data;
85  	drm_device_t *dev = priv->dev;
86  	minor = DRM(stub_register) (DEVICE_NAME, &DRM(fops), dev);
87  	printk("tdrm stub register : minor = %d\n", minor);
88  	return 0;
89  
90  }
91  
tdrm_test_stub_unregister(struct inode * inode,struct file * filp,unsigned int cmd,unsigned long arg)92  int tdrm_test_stub_unregister(struct inode *inode, struct file *filp,
93  			      unsigned int cmd, unsigned long arg)
94  {
95  	DRM(stub_unregister) (minor);
96  	return 0;
97  }
98  
tdrm_test_uninit_agp(struct inode * inode,struct file * filp,unsigned int cmd,unsigned long arg)99  int tdrm_test_uninit_agp(struct inode *inode, struct file *filp,
100  			 unsigned int cmd, unsigned long arg)
101  {
102  	DRM(agp_uninit) ();
103  	return 0;
104  }
105  
tdrm_test_init_agp(struct inode * inode,struct file * filp,unsigned int cmd,unsigned long arg)106  int tdrm_test_init_agp(struct inode *inode, struct file *filp,
107  		       unsigned int cmd, unsigned long arg)
108  {
109  	DRM(agp_init) ();
110  	return 0;
111  }
112  
tdrm_test_add_magic(struct inode * inode,struct file * filp,unsigned int cmd,unsigned long arg)113  int tdrm_test_add_magic(struct inode *inode, struct file *filp,
114  			unsigned int cmd, unsigned long arg)
115  {
116  	drm_file_t *priv = filp->private_data;
117  	drm_device_t *dev = priv->dev;
118  	int magic = 5;
119  	return (DRM(add_magic) (dev, priv, magic));
120  }
121  
tdrm_test_remove_magic(struct inode * inode,struct file * filp,unsigned int cmd,unsigned long arg)122  int tdrm_test_remove_magic(struct inode *inode, struct file *filp,
123  			   unsigned int cmd, unsigned long arg)
124  {
125  	drm_file_t *priv = filp->private_data;
126  	drm_device_t *dev = priv->dev;
127  	int magic = 5;
128  	return (DRM(remove_magic) (dev, magic));
129  }
130  
tdrm_test_ctxbitmap_init(struct inode * inode,struct file * filp,unsigned int cmd,unsigned long arg)131  int tdrm_test_ctxbitmap_init(struct inode *inode, struct file *filp,
132  			     unsigned int cmd, unsigned long arg)
133  {
134  	drm_file_t *priv = filp->private_data;
135  	drm_device_t *dev = priv->dev;
136  	return (DRM(ctxbitmap_init) (dev));
137  }
138  
tdrm_test_ctxbitmap_cleanup(struct inode * inode,struct file * filp,unsigned int cmd,unsigned long arg)139  int tdrm_test_ctxbitmap_cleanup(struct inode *inode, struct file *filp,
140  				unsigned int cmd, unsigned long arg)
141  {
142  	drm_file_t *priv = filp->private_data;
143  	drm_device_t *dev = priv->dev;
144  	DRM(ctxbitmap_cleanup) (dev);
145  	return 0;
146  }
147  
tdrm_test_alloc_pages(struct inode * inode,struct file * filp,unsigned int cmd,unsigned long arg)148  int tdrm_test_alloc_pages(struct inode *inode, struct file *filp,
149  			  unsigned int cmd, unsigned long arg)
150  {
151  	alloc_pages_address = DRM(alloc_pages) (1, 0);
152  //      printk("address = %ld\n",alloc_pages_address);
153  	return 0;
154  }
155  
tdrm_test_free_pages(struct inode * inode,struct file * filp,unsigned int cmd,unsigned long arg)156  int tdrm_test_free_pages(struct inode *inode, struct file *filp,
157  			 unsigned int cmd, unsigned long arg)
158  {
159  	DRM(free_pages) (alloc_pages_address, 1, 0);
160  	return 0;
161  }
162  
163  #ifndef MODULE
164  
165  /* JH- We have to hand expand the string ourselves because of the cpp.  If
166   * anyone can think of a way that we can fit into the __setup macro without
167   * changing it, then please send the solution my way.
168   */
tdrm_options(char * str)169  static int __init tdrm_options(char *str)
170  {
171  	DRM(parse_options) (str);
172  	return 1;
173  }
174  
175  __setup(DRIVER_NAME "=", tdrm_options);
176  #endif
177  
178  #include "drm_fops.h"
179  #include "drm_init.h"
180  #include "drm_ioctl.h"
181  #include "drm_lock.h"
182  #include "drm_memory.h"
183  #include "drm_proc.h"
184  #include "drm_vm.h"
185  #include "drm_stub.h"
186  #include "drm_agpsupport.h"
187