2e044338753cb4d14cef934126ec15f472d09bb2
2 * AGPGART driver frontend
3 * Copyright (C) 2004 Silicon Graphics, Inc.
4 * Copyright (C) 2002-2003 Dave Jones
5 * Copyright (C) 1999 Jeff Hartmann
6 * Copyright (C) 1999 Precision Insight, Inc.
7 * Copyright (C) 1999 Xi Graphics, Inc.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * JEFF HARTMANN, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
23 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #include <linux/types.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/mman.h>
33 #include <linux/pci.h>
34 #include <linux/init.h>
35 #include <linux/miscdevice.h>
36 #include <linux/agp_backend.h>
37 #include <linux/agpgart.h>
38 #include <linux/slab.h>
41 #include <linux/sched.h>
42 #include <asm/uaccess.h>
43 #include <asm/pgtable.h>
46 struct agp_front_data agp_fe
;
48 struct agp_memory
*agp_find_mem_by_key(int key
)
50 struct agp_memory
*curr
;
52 if (agp_fe
.current_controller
== NULL
)
55 curr
= agp_fe
.current_controller
->pool
;
57 while (curr
!= NULL
) {
63 DBG("key=%d -> mem=%p", key
, curr
);
67 static void agp_remove_from_pool(struct agp_memory
*temp
)
69 struct agp_memory
*prev
;
70 struct agp_memory
*next
;
72 /* Check to see if this is even in the memory pool */
75 if (agp_find_mem_by_key(temp
->key
) != NULL
) {
85 /* This is the first item on the list */
89 agp_fe
.current_controller
->pool
= next
;
95 * Routines for managing each client's segment list -
96 * These routines handle adding and removing segments
97 * to each auth'ed client.
101 agp_segment_priv
*agp_find_seg_in_client(const struct agp_client
*client
,
102 unsigned long offset
,
103 int size
, pgprot_t page_prot
)
105 struct agp_segment_priv
*seg
;
110 pg_start
= offset
/ 4096;
111 pg_count
= size
/ 4096;
112 seg
= *(client
->segments
);
113 num_segments
= client
->num_segments
;
115 for (i
= 0; i
< client
->num_segments
; i
++) {
116 if ((seg
[i
].pg_start
== pg_start
) &&
117 (seg
[i
].pg_count
== pg_count
) &&
118 (pgprot_val(seg
[i
].prot
) == pgprot_val(page_prot
))) {
126 static void agp_remove_seg_from_client(struct agp_client
*client
)
128 DBG("client=%p", client
);
130 if (client
->segments
!= NULL
) {
131 if (*(client
->segments
) != NULL
) {
132 DBG("Freeing %p from client %p", *(client
->segments
), client
);
133 kfree(*(client
->segments
));
135 DBG("Freeing %p from client %p", client
->segments
, client
);
136 kfree(client
->segments
);
137 client
->segments
= NULL
;
141 static void agp_add_seg_to_client(struct agp_client
*client
,
142 struct agp_segment_priv
** seg
, int num_segments
)
144 struct agp_segment_priv
**prev_seg
;
146 prev_seg
= client
->segments
;
148 if (prev_seg
!= NULL
)
149 agp_remove_seg_from_client(client
);
151 DBG("Adding seg %p (%d segments) to client %p", seg
, num_segments
, client
);
152 client
->num_segments
= num_segments
;
153 client
->segments
= seg
;
156 static pgprot_t
agp_convert_mmap_flags(int prot
)
158 unsigned long prot_bits
;
160 prot_bits
= calc_vm_prot_bits(prot
) | VM_SHARED
;
161 return vm_get_page_prot(prot_bits
);
164 int agp_create_segment(struct agp_client
*client
, struct agp_region
*region
)
166 struct agp_segment_priv
**ret_seg
;
167 struct agp_segment_priv
*seg
;
168 struct agp_segment
*user_seg
;
171 seg
= kzalloc((sizeof(struct agp_segment_priv
) * region
->seg_count
), GFP_KERNEL
);
173 kfree(region
->seg_list
);
174 region
->seg_list
= NULL
;
177 user_seg
= region
->seg_list
;
179 for (i
= 0; i
< region
->seg_count
; i
++) {
180 seg
[i
].pg_start
= user_seg
[i
].pg_start
;
181 seg
[i
].pg_count
= user_seg
[i
].pg_count
;
182 seg
[i
].prot
= agp_convert_mmap_flags(user_seg
[i
].prot
);
184 kfree(region
->seg_list
);
185 region
->seg_list
= NULL
;
187 ret_seg
= kmalloc(sizeof(void *), GFP_KERNEL
);
188 if (ret_seg
== NULL
) {
193 agp_add_seg_to_client(client
, ret_seg
, region
->seg_count
);
197 /* End - Routines for managing each client's segment list */
199 /* This function must only be called when current_controller != NULL */
200 static void agp_insert_into_pool(struct agp_memory
* temp
)
202 struct agp_memory
*prev
;
204 prev
= agp_fe
.current_controller
->pool
;
210 agp_fe
.current_controller
->pool
= temp
;
214 /* File private list routines */
216 struct agp_file_private
*agp_find_private(pid_t pid
)
218 struct agp_file_private
*curr
;
220 curr
= agp_fe
.file_priv_list
;
222 while (curr
!= NULL
) {
223 if (curr
->my_pid
== pid
)
231 static void agp_insert_file_private(struct agp_file_private
* priv
)
233 struct agp_file_private
*prev
;
235 prev
= agp_fe
.file_priv_list
;
240 agp_fe
.file_priv_list
= priv
;
243 static void agp_remove_file_private(struct agp_file_private
* priv
)
245 struct agp_file_private
*next
;
246 struct agp_file_private
*prev
;
261 agp_fe
.file_priv_list
= next
;
265 /* End - File flag list routines */
268 * Wrappers for agp_free_memory & agp_allocate_memory
269 * These make sure that internal lists are kept updated.
271 void agp_free_memory_wrap(struct agp_memory
*memory
)
273 agp_remove_from_pool(memory
);
274 agp_free_memory(memory
);
277 struct agp_memory
*agp_allocate_memory_wrap(size_t pg_count
, u32 type
)
279 struct agp_memory
*memory
;
281 memory
= agp_allocate_memory(agp_bridge
, pg_count
, type
);
285 agp_insert_into_pool(memory
);
289 /* Routines for managing the list of controllers -
290 * These routines manage the current controller, and the list of
294 static struct agp_controller
*agp_find_controller_by_pid(pid_t id
)
296 struct agp_controller
*controller
;
298 controller
= agp_fe
.controllers
;
300 while (controller
!= NULL
) {
301 if (controller
->pid
== id
)
303 controller
= controller
->next
;
309 static struct agp_controller
*agp_create_controller(pid_t id
)
311 struct agp_controller
*controller
;
313 controller
= kzalloc(sizeof(struct agp_controller
), GFP_KERNEL
);
314 if (controller
== NULL
)
317 controller
->pid
= id
;
321 static int agp_insert_controller(struct agp_controller
*controller
)
323 struct agp_controller
*prev_controller
;
325 prev_controller
= agp_fe
.controllers
;
326 controller
->next
= prev_controller
;
328 if (prev_controller
!= NULL
)
329 prev_controller
->prev
= controller
;
331 agp_fe
.controllers
= controller
;
336 static void agp_remove_all_clients(struct agp_controller
*controller
)
338 struct agp_client
*client
;
339 struct agp_client
*temp
;
341 client
= controller
->clients
;
344 struct agp_file_private
*priv
;
347 agp_remove_seg_from_client(temp
);
348 priv
= agp_find_private(temp
->pid
);
351 clear_bit(AGP_FF_IS_VALID
, &priv
->access_flags
);
352 clear_bit(AGP_FF_IS_CLIENT
, &priv
->access_flags
);
354 client
= client
->next
;
359 static void agp_remove_all_memory(struct agp_controller
*controller
)
361 struct agp_memory
*memory
;
362 struct agp_memory
*temp
;
364 memory
= controller
->pool
;
368 memory
= memory
->next
;
369 agp_free_memory_wrap(temp
);
373 static int agp_remove_controller(struct agp_controller
*controller
)
375 struct agp_controller
*prev_controller
;
376 struct agp_controller
*next_controller
;
378 prev_controller
= controller
->prev
;
379 next_controller
= controller
->next
;
381 if (prev_controller
!= NULL
) {
382 prev_controller
->next
= next_controller
;
383 if (next_controller
!= NULL
)
384 next_controller
->prev
= prev_controller
;
387 if (next_controller
!= NULL
)
388 next_controller
->prev
= NULL
;
390 agp_fe
.controllers
= next_controller
;
393 agp_remove_all_memory(controller
);
394 agp_remove_all_clients(controller
);
396 if (agp_fe
.current_controller
== controller
) {
397 agp_fe
.current_controller
= NULL
;
398 agp_fe
.backend_acquired
= false;
399 agp_backend_release(agp_bridge
);
405 static void agp_controller_make_current(struct agp_controller
*controller
)
407 struct agp_client
*clients
;
409 clients
= controller
->clients
;
411 while (clients
!= NULL
) {
412 struct agp_file_private
*priv
;
414 priv
= agp_find_private(clients
->pid
);
417 set_bit(AGP_FF_IS_VALID
, &priv
->access_flags
);
418 set_bit(AGP_FF_IS_CLIENT
, &priv
->access_flags
);
420 clients
= clients
->next
;
423 agp_fe
.current_controller
= controller
;
426 static void agp_controller_release_current(struct agp_controller
*controller
,
427 struct agp_file_private
*controller_priv
)
429 struct agp_client
*clients
;
431 clear_bit(AGP_FF_IS_VALID
, &controller_priv
->access_flags
);
432 clients
= controller
->clients
;
434 while (clients
!= NULL
) {
435 struct agp_file_private
*priv
;
437 priv
= agp_find_private(clients
->pid
);
440 clear_bit(AGP_FF_IS_VALID
, &priv
->access_flags
);
442 clients
= clients
->next
;
445 agp_fe
.current_controller
= NULL
;
446 agp_fe
.used_by_controller
= false;
447 agp_backend_release(agp_bridge
);
451 * Routines for managing client lists -
452 * These routines are for managing the list of auth'ed clients.
455 static struct agp_client
456 *agp_find_client_in_controller(struct agp_controller
*controller
, pid_t id
)
458 struct agp_client
*client
;
460 if (controller
== NULL
)
463 client
= controller
->clients
;
465 while (client
!= NULL
) {
466 if (client
->pid
== id
)
468 client
= client
->next
;
474 static struct agp_controller
*agp_find_controller_for_client(pid_t id
)
476 struct agp_controller
*controller
;
478 controller
= agp_fe
.controllers
;
480 while (controller
!= NULL
) {
481 if ((agp_find_client_in_controller(controller
, id
)) != NULL
)
483 controller
= controller
->next
;
489 struct agp_client
*agp_find_client_by_pid(pid_t id
)
491 struct agp_client
*temp
;
493 if (agp_fe
.current_controller
== NULL
)
496 temp
= agp_find_client_in_controller(agp_fe
.current_controller
, id
);
500 static void agp_insert_client(struct agp_client
*client
)
502 struct agp_client
*prev_client
;
504 prev_client
= agp_fe
.current_controller
->clients
;
505 client
->next
= prev_client
;
507 if (prev_client
!= NULL
)
508 prev_client
->prev
= client
;
510 agp_fe
.current_controller
->clients
= client
;
511 agp_fe
.current_controller
->num_clients
++;
514 struct agp_client
*agp_create_client(pid_t id
)
516 struct agp_client
*new_client
;
518 new_client
= kzalloc(sizeof(struct agp_client
), GFP_KERNEL
);
519 if (new_client
== NULL
)
522 new_client
->pid
= id
;
523 agp_insert_client(new_client
);
527 int agp_remove_client(pid_t id
)
529 struct agp_client
*client
;
530 struct agp_client
*prev_client
;
531 struct agp_client
*next_client
;
532 struct agp_controller
*controller
;
534 controller
= agp_find_controller_for_client(id
);
535 if (controller
== NULL
)
538 client
= agp_find_client_in_controller(controller
, id
);
542 prev_client
= client
->prev
;
543 next_client
= client
->next
;
545 if (prev_client
!= NULL
) {
546 prev_client
->next
= next_client
;
547 if (next_client
!= NULL
)
548 next_client
->prev
= prev_client
;
551 if (next_client
!= NULL
)
552 next_client
->prev
= NULL
;
553 controller
->clients
= next_client
;
556 controller
->num_clients
--;
557 agp_remove_seg_from_client(client
);
562 /* End - Routines for managing client lists */
564 /* File Operations */
566 static int agp_mmap(struct file
*file
, struct vm_area_struct
*vma
)
568 unsigned int size
, current_size
;
569 unsigned long offset
;
570 struct agp_client
*client
;
571 struct agp_file_private
*priv
= file
->private_data
;
572 struct agp_kern_info kerninfo
;
574 mutex_lock(&(agp_fe
.agp_mutex
));
576 if (agp_fe
.backend_acquired
!= true)
579 if (!(test_bit(AGP_FF_IS_VALID
, &priv
->access_flags
)))
582 agp_copy_info(agp_bridge
, &kerninfo
);
583 size
= vma
->vm_end
- vma
->vm_start
;
584 current_size
= kerninfo
.aper_size
;
585 current_size
= current_size
* 0x100000;
586 offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
587 DBG("%lx:%lx", offset
, offset
+size
);
589 if (test_bit(AGP_FF_IS_CLIENT
, &priv
->access_flags
)) {
590 if ((size
+ offset
) > current_size
)
593 client
= agp_find_client_by_pid(current
->pid
);
598 if (!agp_find_seg_in_client(client
, offset
, size
, vma
->vm_page_prot
))
601 DBG("client vm_ops=%p", kerninfo
.vm_ops
);
602 if (kerninfo
.vm_ops
) {
603 vma
->vm_ops
= kerninfo
.vm_ops
;
604 } else if (io_remap_pfn_range(vma
, vma
->vm_start
,
605 (kerninfo
.aper_base
+ offset
) >> PAGE_SHIFT
,
606 size
, vma
->vm_page_prot
)) {
609 mutex_unlock(&(agp_fe
.agp_mutex
));
613 if (test_bit(AGP_FF_IS_CONTROLLER
, &priv
->access_flags
)) {
614 if (size
!= current_size
)
617 DBG("controller vm_ops=%p", kerninfo
.vm_ops
);
618 if (kerninfo
.vm_ops
) {
619 vma
->vm_ops
= kerninfo
.vm_ops
;
620 } else if (io_remap_pfn_range(vma
, vma
->vm_start
,
621 kerninfo
.aper_base
>> PAGE_SHIFT
,
622 size
, vma
->vm_page_prot
)) {
625 mutex_unlock(&(agp_fe
.agp_mutex
));
630 mutex_unlock(&(agp_fe
.agp_mutex
));
634 mutex_unlock(&(agp_fe
.agp_mutex
));
638 mutex_unlock(&(agp_fe
.agp_mutex
));
642 static int agp_release(struct inode
*inode
, struct file
*file
)
644 struct agp_file_private
*priv
= file
->private_data
;
646 mutex_lock(&(agp_fe
.agp_mutex
));
648 DBG("priv=%p", priv
);
650 if (test_bit(AGP_FF_IS_CONTROLLER
, &priv
->access_flags
)) {
651 struct agp_controller
*controller
;
653 controller
= agp_find_controller_by_pid(priv
->my_pid
);
655 if (controller
!= NULL
) {
656 if (controller
== agp_fe
.current_controller
)
657 agp_controller_release_current(controller
, priv
);
658 agp_remove_controller(controller
);
663 if (test_bit(AGP_FF_IS_CLIENT
, &priv
->access_flags
))
664 agp_remove_client(priv
->my_pid
);
666 agp_remove_file_private(priv
);
668 file
->private_data
= NULL
;
669 mutex_unlock(&(agp_fe
.agp_mutex
));
673 static int agp_open(struct inode
*inode
, struct file
*file
)
675 int minor
= iminor(inode
);
676 struct agp_file_private
*priv
;
677 struct agp_client
*client
;
679 if (minor
!= AGPGART_MINOR
)
682 mutex_lock(&(agp_fe
.agp_mutex
));
684 priv
= kzalloc(sizeof(struct agp_file_private
), GFP_KERNEL
);
686 mutex_unlock(&(agp_fe
.agp_mutex
));
690 set_bit(AGP_FF_ALLOW_CLIENT
, &priv
->access_flags
);
691 priv
->my_pid
= current
->pid
;
693 if (capable(CAP_SYS_RAWIO
))
694 /* Root priv, can be controller */
695 set_bit(AGP_FF_ALLOW_CONTROLLER
, &priv
->access_flags
);
697 client
= agp_find_client_by_pid(current
->pid
);
699 if (client
!= NULL
) {
700 set_bit(AGP_FF_IS_CLIENT
, &priv
->access_flags
);
701 set_bit(AGP_FF_IS_VALID
, &priv
->access_flags
);
703 file
->private_data
= (void *) priv
;
704 agp_insert_file_private(priv
);
705 DBG("private=%p, client=%p", priv
, client
);
707 mutex_unlock(&(agp_fe
.agp_mutex
));
713 static ssize_t
agp_read(struct file
*file
, char __user
*buf
,
714 size_t count
, loff_t
* ppos
)
719 static ssize_t
agp_write(struct file
*file
, const char __user
*buf
,
720 size_t count
, loff_t
* ppos
)
725 static int agpioc_info_wrap(struct agp_file_private
*priv
, void __user
*arg
)
727 struct agp_info userinfo
;
728 struct agp_kern_info kerninfo
;
730 agp_copy_info(agp_bridge
, &kerninfo
);
732 userinfo
.version
.major
= kerninfo
.version
.major
;
733 userinfo
.version
.minor
= kerninfo
.version
.minor
;
734 userinfo
.bridge_id
= kerninfo
.device
->vendor
|
735 (kerninfo
.device
->device
<< 16);
736 userinfo
.agp_mode
= kerninfo
.mode
;
737 userinfo
.aper_base
= kerninfo
.aper_base
;
738 userinfo
.aper_size
= kerninfo
.aper_size
;
739 userinfo
.pg_total
= userinfo
.pg_system
= kerninfo
.max_memory
;
740 userinfo
.pg_used
= kerninfo
.current_memory
;
742 if (copy_to_user(arg
, &userinfo
, sizeof(struct agp_info
)))
748 int agpioc_acquire_wrap(struct agp_file_private
*priv
)
750 struct agp_controller
*controller
;
754 if (!(test_bit(AGP_FF_ALLOW_CONTROLLER
, &priv
->access_flags
)))
757 if (agp_fe
.current_controller
!= NULL
)
763 if (atomic_read(&agp_bridge
->agp_in_use
))
766 atomic_inc(&agp_bridge
->agp_in_use
);
768 agp_fe
.backend_acquired
= true;
770 controller
= agp_find_controller_by_pid(priv
->my_pid
);
772 if (controller
!= NULL
) {
773 agp_controller_make_current(controller
);
775 controller
= agp_create_controller(priv
->my_pid
);
777 if (controller
== NULL
) {
778 agp_fe
.backend_acquired
= false;
779 agp_backend_release(agp_bridge
);
782 agp_insert_controller(controller
);
783 agp_controller_make_current(controller
);
786 set_bit(AGP_FF_IS_CONTROLLER
, &priv
->access_flags
);
787 set_bit(AGP_FF_IS_VALID
, &priv
->access_flags
);
791 int agpioc_release_wrap(struct agp_file_private
*priv
)
794 agp_controller_release_current(agp_fe
.current_controller
, priv
);
798 int agpioc_setup_wrap(struct agp_file_private
*priv
, void __user
*arg
)
800 struct agp_setup mode
;
803 if (copy_from_user(&mode
, arg
, sizeof(struct agp_setup
)))
806 agp_enable(agp_bridge
, mode
.agp_mode
);
810 static int agpioc_reserve_wrap(struct agp_file_private
*priv
, void __user
*arg
)
812 struct agp_region reserve
;
813 struct agp_client
*client
;
814 struct agp_file_private
*client_priv
;
817 if (copy_from_user(&reserve
, arg
, sizeof(struct agp_region
)))
820 if ((unsigned) reserve
.seg_count
>= ~0U/sizeof(struct agp_segment
))
823 client
= agp_find_client_by_pid(reserve
.pid
);
825 if (reserve
.seg_count
== 0) {
826 /* remove a client */
827 client_priv
= agp_find_private(reserve
.pid
);
829 if (client_priv
!= NULL
) {
830 set_bit(AGP_FF_IS_CLIENT
, &client_priv
->access_flags
);
831 set_bit(AGP_FF_IS_VALID
, &client_priv
->access_flags
);
833 if (client
== NULL
) {
834 /* client is already removed */
837 return agp_remove_client(reserve
.pid
);
839 struct agp_segment
*segment
;
841 if (reserve
.seg_count
>= 16384)
844 segment
= kmalloc((sizeof(struct agp_segment
) * reserve
.seg_count
),
850 if (copy_from_user(segment
, (void __user
*) reserve
.seg_list
,
851 sizeof(struct agp_segment
) * reserve
.seg_count
)) {
855 reserve
.seg_list
= segment
;
857 if (client
== NULL
) {
858 /* Create the client and add the segment */
859 client
= agp_create_client(reserve
.pid
);
861 if (client
== NULL
) {
865 client_priv
= agp_find_private(reserve
.pid
);
867 if (client_priv
!= NULL
) {
868 set_bit(AGP_FF_IS_CLIENT
, &client_priv
->access_flags
);
869 set_bit(AGP_FF_IS_VALID
, &client_priv
->access_flags
);
872 return agp_create_segment(client
, &reserve
);
874 /* Will never really happen */
878 int agpioc_protect_wrap(struct agp_file_private
*priv
)
881 /* This function is not currently implemented */
885 static int agpioc_allocate_wrap(struct agp_file_private
*priv
, void __user
*arg
)
887 struct agp_memory
*memory
;
888 struct agp_allocate alloc
;
891 if (copy_from_user(&alloc
, arg
, sizeof(struct agp_allocate
)))
894 if (alloc
.type
>= AGP_USER_TYPES
)
897 memory
= agp_allocate_memory_wrap(alloc
.pg_count
, alloc
.type
);
902 alloc
.key
= memory
->key
;
903 alloc
.physical
= memory
->physical
;
905 if (copy_to_user(arg
, &alloc
, sizeof(struct agp_allocate
))) {
906 agp_free_memory_wrap(memory
);
912 int agpioc_deallocate_wrap(struct agp_file_private
*priv
, int arg
)
914 struct agp_memory
*memory
;
917 memory
= agp_find_mem_by_key(arg
);
922 agp_free_memory_wrap(memory
);
926 static int agpioc_bind_wrap(struct agp_file_private
*priv
, void __user
*arg
)
928 struct agp_bind bind_info
;
929 struct agp_memory
*memory
;
932 if (copy_from_user(&bind_info
, arg
, sizeof(struct agp_bind
)))
935 memory
= agp_find_mem_by_key(bind_info
.key
);
940 return agp_bind_memory(memory
, bind_info
.pg_start
);
943 static int agpioc_unbind_wrap(struct agp_file_private
*priv
, void __user
*arg
)
945 struct agp_memory
*memory
;
946 struct agp_unbind unbind
;
949 if (copy_from_user(&unbind
, arg
, sizeof(struct agp_unbind
)))
952 memory
= agp_find_mem_by_key(unbind
.key
);
957 return agp_unbind_memory(memory
);
960 static long agp_ioctl(struct file
*file
,
961 unsigned int cmd
, unsigned long arg
)
963 struct agp_file_private
*curr_priv
= file
->private_data
;
964 int ret_val
= -ENOTTY
;
966 DBG("priv=%p, cmd=%x", curr_priv
, cmd
);
967 mutex_lock(&(agp_fe
.agp_mutex
));
969 if ((agp_fe
.current_controller
== NULL
) &&
970 (cmd
!= AGPIOC_ACQUIRE
)) {
974 if ((agp_fe
.backend_acquired
!= true) &&
975 (cmd
!= AGPIOC_ACQUIRE
)) {
979 if (cmd
!= AGPIOC_ACQUIRE
) {
980 if (!(test_bit(AGP_FF_IS_CONTROLLER
, &curr_priv
->access_flags
))) {
984 /* Use the original pid of the controller,
985 * in case it's threaded */
987 if (agp_fe
.current_controller
->pid
!= curr_priv
->my_pid
) {
995 ret_val
= agpioc_info_wrap(curr_priv
, (void __user
*) arg
);
999 ret_val
= agpioc_acquire_wrap(curr_priv
);
1002 case AGPIOC_RELEASE
:
1003 ret_val
= agpioc_release_wrap(curr_priv
);
1007 ret_val
= agpioc_setup_wrap(curr_priv
, (void __user
*) arg
);
1010 case AGPIOC_RESERVE
:
1011 ret_val
= agpioc_reserve_wrap(curr_priv
, (void __user
*) arg
);
1014 case AGPIOC_PROTECT
:
1015 ret_val
= agpioc_protect_wrap(curr_priv
);
1018 case AGPIOC_ALLOCATE
:
1019 ret_val
= agpioc_allocate_wrap(curr_priv
, (void __user
*) arg
);
1022 case AGPIOC_DEALLOCATE
:
1023 ret_val
= agpioc_deallocate_wrap(curr_priv
, (int) arg
);
1027 ret_val
= agpioc_bind_wrap(curr_priv
, (void __user
*) arg
);
1031 ret_val
= agpioc_unbind_wrap(curr_priv
, (void __user
*) arg
);
1034 case AGPIOC_CHIPSET_FLUSH
:
1039 DBG("ioctl returns %d\n", ret_val
);
1040 mutex_unlock(&(agp_fe
.agp_mutex
));
1044 static const struct file_operations agp_fops
=
1046 .owner
= THIS_MODULE
,
1047 .llseek
= no_llseek
,
1050 .unlocked_ioctl
= agp_ioctl
,
1051 #ifdef CONFIG_COMPAT
1052 .compat_ioctl
= compat_agp_ioctl
,
1056 .release
= agp_release
,
1059 static struct miscdevice agp_miscdev
=
1061 .minor
= AGPGART_MINOR
,
1066 int agp_frontend_initialize(void)
1068 memset(&agp_fe
, 0, sizeof(struct agp_front_data
));
1069 mutex_init(&(agp_fe
.agp_mutex
));
1071 if (misc_register(&agp_miscdev
)) {
1072 printk(KERN_ERR PFX
"unable to get minor: %d\n", AGPGART_MINOR
);
1078 void agp_frontend_cleanup(void)
1080 misc_deregister(&agp_miscdev
);