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/miscdevice.h>
35 #include <linux/agp_backend.h>
36 #include <linux/agpgart.h>
37 #include <linux/slab.h>
40 #include <linux/sched.h>
41 #include <asm/uaccess.h>
42 #include <asm/pgtable.h>
45 struct agp_front_data agp_fe
;
47 struct agp_memory
*agp_find_mem_by_key(int key
)
49 struct agp_memory
*curr
;
51 if (agp_fe
.current_controller
== NULL
)
54 curr
= agp_fe
.current_controller
->pool
;
56 while (curr
!= NULL
) {
62 DBG("key=%d -> mem=%p", key
, curr
);
66 static void agp_remove_from_pool(struct agp_memory
*temp
)
68 struct agp_memory
*prev
;
69 struct agp_memory
*next
;
71 /* Check to see if this is even in the memory pool */
74 if (agp_find_mem_by_key(temp
->key
) != NULL
) {
84 /* This is the first item on the list */
88 agp_fe
.current_controller
->pool
= next
;
94 * Routines for managing each client's segment list -
95 * These routines handle adding and removing segments
96 * to each auth'ed client.
100 agp_segment_priv
*agp_find_seg_in_client(const struct agp_client
*client
,
101 unsigned long offset
,
102 int size
, pgprot_t page_prot
)
104 struct agp_segment_priv
*seg
;
109 pg_start
= offset
/ 4096;
110 pg_count
= size
/ 4096;
111 seg
= *(client
->segments
);
112 num_segments
= client
->num_segments
;
114 for (i
= 0; i
< client
->num_segments
; i
++) {
115 if ((seg
[i
].pg_start
== pg_start
) &&
116 (seg
[i
].pg_count
== pg_count
) &&
117 (pgprot_val(seg
[i
].prot
) == pgprot_val(page_prot
))) {
125 static void agp_remove_seg_from_client(struct agp_client
*client
)
127 DBG("client=%p", client
);
129 if (client
->segments
!= NULL
) {
130 if (*(client
->segments
) != NULL
) {
131 DBG("Freeing %p from client %p", *(client
->segments
), client
);
132 kfree(*(client
->segments
));
134 DBG("Freeing %p from client %p", client
->segments
, client
);
135 kfree(client
->segments
);
136 client
->segments
= NULL
;
140 static void agp_add_seg_to_client(struct agp_client
*client
,
141 struct agp_segment_priv
** seg
, int num_segments
)
143 struct agp_segment_priv
**prev_seg
;
145 prev_seg
= client
->segments
;
147 if (prev_seg
!= NULL
)
148 agp_remove_seg_from_client(client
);
150 DBG("Adding seg %p (%d segments) to client %p", seg
, num_segments
, client
);
151 client
->num_segments
= num_segments
;
152 client
->segments
= seg
;
155 static pgprot_t
agp_convert_mmap_flags(int prot
)
157 unsigned long prot_bits
;
159 prot_bits
= calc_vm_prot_bits(prot
) | VM_SHARED
;
160 return vm_get_page_prot(prot_bits
);
163 int agp_create_segment(struct agp_client
*client
, struct agp_region
*region
)
165 struct agp_segment_priv
**ret_seg
;
166 struct agp_segment_priv
*seg
;
167 struct agp_segment
*user_seg
;
170 seg
= kzalloc((sizeof(struct agp_segment_priv
) * region
->seg_count
), GFP_KERNEL
);
172 kfree(region
->seg_list
);
173 region
->seg_list
= NULL
;
176 user_seg
= region
->seg_list
;
178 for (i
= 0; i
< region
->seg_count
; i
++) {
179 seg
[i
].pg_start
= user_seg
[i
].pg_start
;
180 seg
[i
].pg_count
= user_seg
[i
].pg_count
;
181 seg
[i
].prot
= agp_convert_mmap_flags(user_seg
[i
].prot
);
183 kfree(region
->seg_list
);
184 region
->seg_list
= NULL
;
186 ret_seg
= kmalloc(sizeof(void *), GFP_KERNEL
);
187 if (ret_seg
== NULL
) {
192 agp_add_seg_to_client(client
, ret_seg
, region
->seg_count
);
196 /* End - Routines for managing each client's segment list */
198 /* This function must only be called when current_controller != NULL */
199 static void agp_insert_into_pool(struct agp_memory
* temp
)
201 struct agp_memory
*prev
;
203 prev
= agp_fe
.current_controller
->pool
;
209 agp_fe
.current_controller
->pool
= temp
;
213 /* File private list routines */
215 struct agp_file_private
*agp_find_private(pid_t pid
)
217 struct agp_file_private
*curr
;
219 curr
= agp_fe
.file_priv_list
;
221 while (curr
!= NULL
) {
222 if (curr
->my_pid
== pid
)
230 static void agp_insert_file_private(struct agp_file_private
* priv
)
232 struct agp_file_private
*prev
;
234 prev
= agp_fe
.file_priv_list
;
239 agp_fe
.file_priv_list
= priv
;
242 static void agp_remove_file_private(struct agp_file_private
* priv
)
244 struct agp_file_private
*next
;
245 struct agp_file_private
*prev
;
260 agp_fe
.file_priv_list
= next
;
264 /* End - File flag list routines */
267 * Wrappers for agp_free_memory & agp_allocate_memory
268 * These make sure that internal lists are kept updated.
270 void agp_free_memory_wrap(struct agp_memory
*memory
)
272 agp_remove_from_pool(memory
);
273 agp_free_memory(memory
);
276 struct agp_memory
*agp_allocate_memory_wrap(size_t pg_count
, u32 type
)
278 struct agp_memory
*memory
;
280 memory
= agp_allocate_memory(agp_bridge
, pg_count
, type
);
284 agp_insert_into_pool(memory
);
288 /* Routines for managing the list of controllers -
289 * These routines manage the current controller, and the list of
293 static struct agp_controller
*agp_find_controller_by_pid(pid_t id
)
295 struct agp_controller
*controller
;
297 controller
= agp_fe
.controllers
;
299 while (controller
!= NULL
) {
300 if (controller
->pid
== id
)
302 controller
= controller
->next
;
308 static struct agp_controller
*agp_create_controller(pid_t id
)
310 struct agp_controller
*controller
;
312 controller
= kzalloc(sizeof(struct agp_controller
), GFP_KERNEL
);
313 if (controller
== NULL
)
316 controller
->pid
= id
;
320 static int agp_insert_controller(struct agp_controller
*controller
)
322 struct agp_controller
*prev_controller
;
324 prev_controller
= agp_fe
.controllers
;
325 controller
->next
= prev_controller
;
327 if (prev_controller
!= NULL
)
328 prev_controller
->prev
= controller
;
330 agp_fe
.controllers
= controller
;
335 static void agp_remove_all_clients(struct agp_controller
*controller
)
337 struct agp_client
*client
;
338 struct agp_client
*temp
;
340 client
= controller
->clients
;
343 struct agp_file_private
*priv
;
346 agp_remove_seg_from_client(temp
);
347 priv
= agp_find_private(temp
->pid
);
350 clear_bit(AGP_FF_IS_VALID
, &priv
->access_flags
);
351 clear_bit(AGP_FF_IS_CLIENT
, &priv
->access_flags
);
353 client
= client
->next
;
358 static void agp_remove_all_memory(struct agp_controller
*controller
)
360 struct agp_memory
*memory
;
361 struct agp_memory
*temp
;
363 memory
= controller
->pool
;
367 memory
= memory
->next
;
368 agp_free_memory_wrap(temp
);
372 static int agp_remove_controller(struct agp_controller
*controller
)
374 struct agp_controller
*prev_controller
;
375 struct agp_controller
*next_controller
;
377 prev_controller
= controller
->prev
;
378 next_controller
= controller
->next
;
380 if (prev_controller
!= NULL
) {
381 prev_controller
->next
= next_controller
;
382 if (next_controller
!= NULL
)
383 next_controller
->prev
= prev_controller
;
386 if (next_controller
!= NULL
)
387 next_controller
->prev
= NULL
;
389 agp_fe
.controllers
= next_controller
;
392 agp_remove_all_memory(controller
);
393 agp_remove_all_clients(controller
);
395 if (agp_fe
.current_controller
== controller
) {
396 agp_fe
.current_controller
= NULL
;
397 agp_fe
.backend_acquired
= false;
398 agp_backend_release(agp_bridge
);
404 static void agp_controller_make_current(struct agp_controller
*controller
)
406 struct agp_client
*clients
;
408 clients
= controller
->clients
;
410 while (clients
!= NULL
) {
411 struct agp_file_private
*priv
;
413 priv
= agp_find_private(clients
->pid
);
416 set_bit(AGP_FF_IS_VALID
, &priv
->access_flags
);
417 set_bit(AGP_FF_IS_CLIENT
, &priv
->access_flags
);
419 clients
= clients
->next
;
422 agp_fe
.current_controller
= controller
;
425 static void agp_controller_release_current(struct agp_controller
*controller
,
426 struct agp_file_private
*controller_priv
)
428 struct agp_client
*clients
;
430 clear_bit(AGP_FF_IS_VALID
, &controller_priv
->access_flags
);
431 clients
= controller
->clients
;
433 while (clients
!= NULL
) {
434 struct agp_file_private
*priv
;
436 priv
= agp_find_private(clients
->pid
);
439 clear_bit(AGP_FF_IS_VALID
, &priv
->access_flags
);
441 clients
= clients
->next
;
444 agp_fe
.current_controller
= NULL
;
445 agp_fe
.used_by_controller
= false;
446 agp_backend_release(agp_bridge
);
450 * Routines for managing client lists -
451 * These routines are for managing the list of auth'ed clients.
454 static struct agp_client
455 *agp_find_client_in_controller(struct agp_controller
*controller
, pid_t id
)
457 struct agp_client
*client
;
459 if (controller
== NULL
)
462 client
= controller
->clients
;
464 while (client
!= NULL
) {
465 if (client
->pid
== id
)
467 client
= client
->next
;
473 static struct agp_controller
*agp_find_controller_for_client(pid_t id
)
475 struct agp_controller
*controller
;
477 controller
= agp_fe
.controllers
;
479 while (controller
!= NULL
) {
480 if ((agp_find_client_in_controller(controller
, id
)) != NULL
)
482 controller
= controller
->next
;
488 struct agp_client
*agp_find_client_by_pid(pid_t id
)
490 struct agp_client
*temp
;
492 if (agp_fe
.current_controller
== NULL
)
495 temp
= agp_find_client_in_controller(agp_fe
.current_controller
, id
);
499 static void agp_insert_client(struct agp_client
*client
)
501 struct agp_client
*prev_client
;
503 prev_client
= agp_fe
.current_controller
->clients
;
504 client
->next
= prev_client
;
506 if (prev_client
!= NULL
)
507 prev_client
->prev
= client
;
509 agp_fe
.current_controller
->clients
= client
;
510 agp_fe
.current_controller
->num_clients
++;
513 struct agp_client
*agp_create_client(pid_t id
)
515 struct agp_client
*new_client
;
517 new_client
= kzalloc(sizeof(struct agp_client
), GFP_KERNEL
);
518 if (new_client
== NULL
)
521 new_client
->pid
= id
;
522 agp_insert_client(new_client
);
526 int agp_remove_client(pid_t id
)
528 struct agp_client
*client
;
529 struct agp_client
*prev_client
;
530 struct agp_client
*next_client
;
531 struct agp_controller
*controller
;
533 controller
= agp_find_controller_for_client(id
);
534 if (controller
== NULL
)
537 client
= agp_find_client_in_controller(controller
, id
);
541 prev_client
= client
->prev
;
542 next_client
= client
->next
;
544 if (prev_client
!= NULL
) {
545 prev_client
->next
= next_client
;
546 if (next_client
!= NULL
)
547 next_client
->prev
= prev_client
;
550 if (next_client
!= NULL
)
551 next_client
->prev
= NULL
;
552 controller
->clients
= next_client
;
555 controller
->num_clients
--;
556 agp_remove_seg_from_client(client
);
561 /* End - Routines for managing client lists */
563 /* File Operations */
565 static int agp_mmap(struct file
*file
, struct vm_area_struct
*vma
)
567 unsigned int size
, current_size
;
568 unsigned long offset
;
569 struct agp_client
*client
;
570 struct agp_file_private
*priv
= file
->private_data
;
571 struct agp_kern_info kerninfo
;
573 mutex_lock(&(agp_fe
.agp_mutex
));
575 if (agp_fe
.backend_acquired
!= true)
578 if (!(test_bit(AGP_FF_IS_VALID
, &priv
->access_flags
)))
581 agp_copy_info(agp_bridge
, &kerninfo
);
582 size
= vma
->vm_end
- vma
->vm_start
;
583 current_size
= kerninfo
.aper_size
;
584 current_size
= current_size
* 0x100000;
585 offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
586 DBG("%lx:%lx", offset
, offset
+size
);
588 if (test_bit(AGP_FF_IS_CLIENT
, &priv
->access_flags
)) {
589 if ((size
+ offset
) > current_size
)
592 client
= agp_find_client_by_pid(current
->pid
);
597 if (!agp_find_seg_in_client(client
, offset
, size
, vma
->vm_page_prot
))
600 DBG("client vm_ops=%p", kerninfo
.vm_ops
);
601 if (kerninfo
.vm_ops
) {
602 vma
->vm_ops
= kerninfo
.vm_ops
;
603 } else if (io_remap_pfn_range(vma
, vma
->vm_start
,
604 (kerninfo
.aper_base
+ offset
) >> PAGE_SHIFT
,
606 pgprot_writecombine(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
,
623 pgprot_writecombine(vma
->vm_page_prot
))) {
626 mutex_unlock(&(agp_fe
.agp_mutex
));
631 mutex_unlock(&(agp_fe
.agp_mutex
));
635 mutex_unlock(&(agp_fe
.agp_mutex
));
639 mutex_unlock(&(agp_fe
.agp_mutex
));
643 static int agp_release(struct inode
*inode
, struct file
*file
)
645 struct agp_file_private
*priv
= file
->private_data
;
647 mutex_lock(&(agp_fe
.agp_mutex
));
649 DBG("priv=%p", priv
);
651 if (test_bit(AGP_FF_IS_CONTROLLER
, &priv
->access_flags
)) {
652 struct agp_controller
*controller
;
654 controller
= agp_find_controller_by_pid(priv
->my_pid
);
656 if (controller
!= NULL
) {
657 if (controller
== agp_fe
.current_controller
)
658 agp_controller_release_current(controller
, priv
);
659 agp_remove_controller(controller
);
664 if (test_bit(AGP_FF_IS_CLIENT
, &priv
->access_flags
))
665 agp_remove_client(priv
->my_pid
);
667 agp_remove_file_private(priv
);
669 file
->private_data
= NULL
;
670 mutex_unlock(&(agp_fe
.agp_mutex
));
674 static int agp_open(struct inode
*inode
, struct file
*file
)
676 int minor
= iminor(inode
);
677 struct agp_file_private
*priv
;
678 struct agp_client
*client
;
680 if (minor
!= AGPGART_MINOR
)
683 mutex_lock(&(agp_fe
.agp_mutex
));
685 priv
= kzalloc(sizeof(struct agp_file_private
), GFP_KERNEL
);
687 mutex_unlock(&(agp_fe
.agp_mutex
));
691 set_bit(AGP_FF_ALLOW_CLIENT
, &priv
->access_flags
);
692 priv
->my_pid
= current
->pid
;
694 if (capable(CAP_SYS_RAWIO
))
695 /* Root priv, can be controller */
696 set_bit(AGP_FF_ALLOW_CONTROLLER
, &priv
->access_flags
);
698 client
= agp_find_client_by_pid(current
->pid
);
700 if (client
!= NULL
) {
701 set_bit(AGP_FF_IS_CLIENT
, &priv
->access_flags
);
702 set_bit(AGP_FF_IS_VALID
, &priv
->access_flags
);
704 file
->private_data
= (void *) priv
;
705 agp_insert_file_private(priv
);
706 DBG("private=%p, client=%p", priv
, client
);
708 mutex_unlock(&(agp_fe
.agp_mutex
));
713 static int agpioc_info_wrap(struct agp_file_private
*priv
, void __user
*arg
)
715 struct agp_info userinfo
;
716 struct agp_kern_info kerninfo
;
718 agp_copy_info(agp_bridge
, &kerninfo
);
720 memset(&userinfo
, 0, sizeof(userinfo
));
721 userinfo
.version
.major
= kerninfo
.version
.major
;
722 userinfo
.version
.minor
= kerninfo
.version
.minor
;
723 userinfo
.bridge_id
= kerninfo
.device
->vendor
|
724 (kerninfo
.device
->device
<< 16);
725 userinfo
.agp_mode
= kerninfo
.mode
;
726 userinfo
.aper_base
= kerninfo
.aper_base
;
727 userinfo
.aper_size
= kerninfo
.aper_size
;
728 userinfo
.pg_total
= userinfo
.pg_system
= kerninfo
.max_memory
;
729 userinfo
.pg_used
= kerninfo
.current_memory
;
731 if (copy_to_user(arg
, &userinfo
, sizeof(struct agp_info
)))
737 int agpioc_acquire_wrap(struct agp_file_private
*priv
)
739 struct agp_controller
*controller
;
743 if (!(test_bit(AGP_FF_ALLOW_CONTROLLER
, &priv
->access_flags
)))
746 if (agp_fe
.current_controller
!= NULL
)
752 if (atomic_read(&agp_bridge
->agp_in_use
))
755 atomic_inc(&agp_bridge
->agp_in_use
);
757 agp_fe
.backend_acquired
= true;
759 controller
= agp_find_controller_by_pid(priv
->my_pid
);
761 if (controller
!= NULL
) {
762 agp_controller_make_current(controller
);
764 controller
= agp_create_controller(priv
->my_pid
);
766 if (controller
== NULL
) {
767 agp_fe
.backend_acquired
= false;
768 agp_backend_release(agp_bridge
);
771 agp_insert_controller(controller
);
772 agp_controller_make_current(controller
);
775 set_bit(AGP_FF_IS_CONTROLLER
, &priv
->access_flags
);
776 set_bit(AGP_FF_IS_VALID
, &priv
->access_flags
);
780 int agpioc_release_wrap(struct agp_file_private
*priv
)
783 agp_controller_release_current(agp_fe
.current_controller
, priv
);
787 int agpioc_setup_wrap(struct agp_file_private
*priv
, void __user
*arg
)
789 struct agp_setup mode
;
792 if (copy_from_user(&mode
, arg
, sizeof(struct agp_setup
)))
795 agp_enable(agp_bridge
, mode
.agp_mode
);
799 static int agpioc_reserve_wrap(struct agp_file_private
*priv
, void __user
*arg
)
801 struct agp_region reserve
;
802 struct agp_client
*client
;
803 struct agp_file_private
*client_priv
;
806 if (copy_from_user(&reserve
, arg
, sizeof(struct agp_region
)))
809 if ((unsigned) reserve
.seg_count
>= ~0U/sizeof(struct agp_segment
))
812 client
= agp_find_client_by_pid(reserve
.pid
);
814 if (reserve
.seg_count
== 0) {
815 /* remove a client */
816 client_priv
= agp_find_private(reserve
.pid
);
818 if (client_priv
!= NULL
) {
819 set_bit(AGP_FF_IS_CLIENT
, &client_priv
->access_flags
);
820 set_bit(AGP_FF_IS_VALID
, &client_priv
->access_flags
);
822 if (client
== NULL
) {
823 /* client is already removed */
826 return agp_remove_client(reserve
.pid
);
828 struct agp_segment
*segment
;
830 if (reserve
.seg_count
>= 16384)
833 segment
= kmalloc((sizeof(struct agp_segment
) * reserve
.seg_count
),
839 if (copy_from_user(segment
, (void __user
*) reserve
.seg_list
,
840 sizeof(struct agp_segment
) * reserve
.seg_count
)) {
844 reserve
.seg_list
= segment
;
846 if (client
== NULL
) {
847 /* Create the client and add the segment */
848 client
= agp_create_client(reserve
.pid
);
850 if (client
== NULL
) {
854 client_priv
= agp_find_private(reserve
.pid
);
856 if (client_priv
!= NULL
) {
857 set_bit(AGP_FF_IS_CLIENT
, &client_priv
->access_flags
);
858 set_bit(AGP_FF_IS_VALID
, &client_priv
->access_flags
);
861 return agp_create_segment(client
, &reserve
);
863 /* Will never really happen */
867 int agpioc_protect_wrap(struct agp_file_private
*priv
)
870 /* This function is not currently implemented */
874 static int agpioc_allocate_wrap(struct agp_file_private
*priv
, void __user
*arg
)
876 struct agp_memory
*memory
;
877 struct agp_allocate alloc
;
880 if (copy_from_user(&alloc
, arg
, sizeof(struct agp_allocate
)))
883 if (alloc
.type
>= AGP_USER_TYPES
)
886 memory
= agp_allocate_memory_wrap(alloc
.pg_count
, alloc
.type
);
891 alloc
.key
= memory
->key
;
892 alloc
.physical
= memory
->physical
;
894 if (copy_to_user(arg
, &alloc
, sizeof(struct agp_allocate
))) {
895 agp_free_memory_wrap(memory
);
901 int agpioc_deallocate_wrap(struct agp_file_private
*priv
, int arg
)
903 struct agp_memory
*memory
;
906 memory
= agp_find_mem_by_key(arg
);
911 agp_free_memory_wrap(memory
);
915 static int agpioc_bind_wrap(struct agp_file_private
*priv
, void __user
*arg
)
917 struct agp_bind bind_info
;
918 struct agp_memory
*memory
;
921 if (copy_from_user(&bind_info
, arg
, sizeof(struct agp_bind
)))
924 memory
= agp_find_mem_by_key(bind_info
.key
);
929 return agp_bind_memory(memory
, bind_info
.pg_start
);
932 static int agpioc_unbind_wrap(struct agp_file_private
*priv
, void __user
*arg
)
934 struct agp_memory
*memory
;
935 struct agp_unbind unbind
;
938 if (copy_from_user(&unbind
, arg
, sizeof(struct agp_unbind
)))
941 memory
= agp_find_mem_by_key(unbind
.key
);
946 return agp_unbind_memory(memory
);
949 static long agp_ioctl(struct file
*file
,
950 unsigned int cmd
, unsigned long arg
)
952 struct agp_file_private
*curr_priv
= file
->private_data
;
953 int ret_val
= -ENOTTY
;
955 DBG("priv=%p, cmd=%x", curr_priv
, cmd
);
956 mutex_lock(&(agp_fe
.agp_mutex
));
958 if ((agp_fe
.current_controller
== NULL
) &&
959 (cmd
!= AGPIOC_ACQUIRE
)) {
963 if ((agp_fe
.backend_acquired
!= true) &&
964 (cmd
!= AGPIOC_ACQUIRE
)) {
968 if (cmd
!= AGPIOC_ACQUIRE
) {
969 if (!(test_bit(AGP_FF_IS_CONTROLLER
, &curr_priv
->access_flags
))) {
973 /* Use the original pid of the controller,
974 * in case it's threaded */
976 if (agp_fe
.current_controller
->pid
!= curr_priv
->my_pid
) {
984 ret_val
= agpioc_info_wrap(curr_priv
, (void __user
*) arg
);
988 ret_val
= agpioc_acquire_wrap(curr_priv
);
992 ret_val
= agpioc_release_wrap(curr_priv
);
996 ret_val
= agpioc_setup_wrap(curr_priv
, (void __user
*) arg
);
1000 ret_val
= agpioc_reserve_wrap(curr_priv
, (void __user
*) arg
);
1003 case AGPIOC_PROTECT
:
1004 ret_val
= agpioc_protect_wrap(curr_priv
);
1007 case AGPIOC_ALLOCATE
:
1008 ret_val
= agpioc_allocate_wrap(curr_priv
, (void __user
*) arg
);
1011 case AGPIOC_DEALLOCATE
:
1012 ret_val
= agpioc_deallocate_wrap(curr_priv
, (int) arg
);
1016 ret_val
= agpioc_bind_wrap(curr_priv
, (void __user
*) arg
);
1020 ret_val
= agpioc_unbind_wrap(curr_priv
, (void __user
*) arg
);
1023 case AGPIOC_CHIPSET_FLUSH
:
1028 DBG("ioctl returns %d\n", ret_val
);
1029 mutex_unlock(&(agp_fe
.agp_mutex
));
1033 static const struct file_operations agp_fops
=
1035 .owner
= THIS_MODULE
,
1036 .llseek
= no_llseek
,
1037 .unlocked_ioctl
= agp_ioctl
,
1038 #ifdef CONFIG_COMPAT
1039 .compat_ioctl
= compat_agp_ioctl
,
1043 .release
= agp_release
,
1046 static struct miscdevice agp_miscdev
=
1048 .minor
= AGPGART_MINOR
,
1053 int agp_frontend_initialize(void)
1055 memset(&agp_fe
, 0, sizeof(struct agp_front_data
));
1056 mutex_init(&(agp_fe
.agp_mutex
));
1058 if (misc_register(&agp_miscdev
)) {
1059 printk(KERN_ERR PFX
"unable to get minor: %d\n", AGPGART_MINOR
);
1065 void agp_frontend_cleanup(void)
1067 misc_deregister(&agp_miscdev
);