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>
40 #include <asm/uaccess.h>
41 #include <asm/pgtable.h>
44 static struct agp_front_data agp_fe
;
46 static struct agp_memory
*agp_find_mem_by_key(int key
)
48 struct agp_memory
*curr
;
50 if (agp_fe
.current_controller
== NULL
)
53 curr
= agp_fe
.current_controller
->pool
;
55 while (curr
!= NULL
) {
61 DBG("key=%d -> mem=%p", key
, curr
);
65 static void agp_remove_from_pool(struct agp_memory
*temp
)
67 struct agp_memory
*prev
;
68 struct agp_memory
*next
;
70 /* Check to see if this is even in the memory pool */
73 if (agp_find_mem_by_key(temp
->key
) != NULL
) {
83 /* This is the first item on the list */
87 agp_fe
.current_controller
->pool
= next
;
93 * Routines for managing each client's segment list -
94 * These routines handle adding and removing segments
95 * to each auth'ed client.
99 agp_segment_priv
*agp_find_seg_in_client(const struct agp_client
*client
,
100 unsigned long offset
,
101 int size
, pgprot_t page_prot
)
103 struct agp_segment_priv
*seg
;
108 pg_start
= offset
/ 4096;
109 pg_count
= size
/ 4096;
110 seg
= *(client
->segments
);
111 num_segments
= client
->num_segments
;
113 for (i
= 0; i
< client
->num_segments
; i
++) {
114 if ((seg
[i
].pg_start
== pg_start
) &&
115 (seg
[i
].pg_count
== pg_count
) &&
116 (pgprot_val(seg
[i
].prot
) == pgprot_val(page_prot
))) {
124 static void agp_remove_seg_from_client(struct agp_client
*client
)
126 DBG("client=%p", client
);
128 if (client
->segments
!= NULL
) {
129 if (*(client
->segments
) != NULL
) {
130 DBG("Freeing %p from client %p", *(client
->segments
), client
);
131 kfree(*(client
->segments
));
133 DBG("Freeing %p from client %p", client
->segments
, client
);
134 kfree(client
->segments
);
135 client
->segments
= NULL
;
139 static void agp_add_seg_to_client(struct agp_client
*client
,
140 struct agp_segment_priv
** seg
, int num_segments
)
142 struct agp_segment_priv
**prev_seg
;
144 prev_seg
= client
->segments
;
146 if (prev_seg
!= NULL
)
147 agp_remove_seg_from_client(client
);
149 DBG("Adding seg %p (%d segments) to client %p", seg
, num_segments
, client
);
150 client
->num_segments
= num_segments
;
151 client
->segments
= seg
;
154 /* Originally taken from linux/mm/mmap.c from the array
156 * The original really should be exported to modules, or
157 * some routine which does the conversion for you
160 static const pgprot_t my_protect_map
[16] =
162 __P000
, __P001
, __P010
, __P011
, __P100
, __P101
, __P110
, __P111
,
163 __S000
, __S001
, __S010
, __S011
, __S100
, __S101
, __S110
, __S111
166 static pgprot_t
agp_convert_mmap_flags(int prot
)
168 #define _trans(x,bit1,bit2) \
169 ((bit1==bit2)?(x&bit1):(x&bit1)?bit2:0)
171 unsigned long prot_bits
;
174 prot_bits
= _trans(prot
, PROT_READ
, VM_READ
) |
175 _trans(prot
, PROT_WRITE
, VM_WRITE
) |
176 _trans(prot
, PROT_EXEC
, VM_EXEC
);
178 prot_bits
|= VM_SHARED
;
180 temp
= my_protect_map
[prot_bits
& 0x0000000f];
185 static int agp_create_segment(struct agp_client
*client
, struct agp_region
*region
)
187 struct agp_segment_priv
**ret_seg
;
188 struct agp_segment_priv
*seg
;
189 struct agp_segment
*user_seg
;
192 seg
= kzalloc((sizeof(struct agp_segment_priv
) * region
->seg_count
), GFP_KERNEL
);
194 kfree(region
->seg_list
);
195 region
->seg_list
= NULL
;
198 user_seg
= region
->seg_list
;
200 for (i
= 0; i
< region
->seg_count
; i
++) {
201 seg
[i
].pg_start
= user_seg
[i
].pg_start
;
202 seg
[i
].pg_count
= user_seg
[i
].pg_count
;
203 seg
[i
].prot
= agp_convert_mmap_flags(user_seg
[i
].prot
);
205 kfree(region
->seg_list
);
206 region
->seg_list
= NULL
;
208 ret_seg
= kmalloc(sizeof(void *), GFP_KERNEL
);
209 if (ret_seg
== NULL
) {
214 agp_add_seg_to_client(client
, ret_seg
, region
->seg_count
);
218 /* End - Routines for managing each client's segment list */
220 /* This function must only be called when current_controller != NULL */
221 static void agp_insert_into_pool(struct agp_memory
* temp
)
223 struct agp_memory
*prev
;
225 prev
= agp_fe
.current_controller
->pool
;
231 agp_fe
.current_controller
->pool
= temp
;
235 /* File private list routines */
237 static struct agp_file_private
*agp_find_private(pid_t pid
)
239 struct agp_file_private
*curr
;
241 curr
= agp_fe
.file_priv_list
;
243 while (curr
!= NULL
) {
244 if (curr
->my_pid
== pid
)
252 static void agp_insert_file_private(struct agp_file_private
* priv
)
254 struct agp_file_private
*prev
;
256 prev
= agp_fe
.file_priv_list
;
261 agp_fe
.file_priv_list
= priv
;
264 static void agp_remove_file_private(struct agp_file_private
* priv
)
266 struct agp_file_private
*next
;
267 struct agp_file_private
*prev
;
282 agp_fe
.file_priv_list
= next
;
286 /* End - File flag list routines */
289 * Wrappers for agp_free_memory & agp_allocate_memory
290 * These make sure that internal lists are kept updated.
292 static void agp_free_memory_wrap(struct agp_memory
*memory
)
294 agp_remove_from_pool(memory
);
295 agp_free_memory(memory
);
298 static struct agp_memory
*agp_allocate_memory_wrap(size_t pg_count
, u32 type
)
300 struct agp_memory
*memory
;
302 memory
= agp_allocate_memory(agp_bridge
, pg_count
, type
);
306 agp_insert_into_pool(memory
);
310 /* Routines for managing the list of controllers -
311 * These routines manage the current controller, and the list of
315 static struct agp_controller
*agp_find_controller_by_pid(pid_t id
)
317 struct agp_controller
*controller
;
319 controller
= agp_fe
.controllers
;
321 while (controller
!= NULL
) {
322 if (controller
->pid
== id
)
324 controller
= controller
->next
;
330 static struct agp_controller
*agp_create_controller(pid_t id
)
332 struct agp_controller
*controller
;
334 controller
= kzalloc(sizeof(struct agp_controller
), GFP_KERNEL
);
335 if (controller
== NULL
)
338 controller
->pid
= id
;
342 static int agp_insert_controller(struct agp_controller
*controller
)
344 struct agp_controller
*prev_controller
;
346 prev_controller
= agp_fe
.controllers
;
347 controller
->next
= prev_controller
;
349 if (prev_controller
!= NULL
)
350 prev_controller
->prev
= controller
;
352 agp_fe
.controllers
= controller
;
357 static void agp_remove_all_clients(struct agp_controller
*controller
)
359 struct agp_client
*client
;
360 struct agp_client
*temp
;
362 client
= controller
->clients
;
365 struct agp_file_private
*priv
;
368 agp_remove_seg_from_client(temp
);
369 priv
= agp_find_private(temp
->pid
);
372 clear_bit(AGP_FF_IS_VALID
, &priv
->access_flags
);
373 clear_bit(AGP_FF_IS_CLIENT
, &priv
->access_flags
);
375 client
= client
->next
;
380 static void agp_remove_all_memory(struct agp_controller
*controller
)
382 struct agp_memory
*memory
;
383 struct agp_memory
*temp
;
385 memory
= controller
->pool
;
389 memory
= memory
->next
;
390 agp_free_memory_wrap(temp
);
394 static int agp_remove_controller(struct agp_controller
*controller
)
396 struct agp_controller
*prev_controller
;
397 struct agp_controller
*next_controller
;
399 prev_controller
= controller
->prev
;
400 next_controller
= controller
->next
;
402 if (prev_controller
!= NULL
) {
403 prev_controller
->next
= next_controller
;
404 if (next_controller
!= NULL
)
405 next_controller
->prev
= prev_controller
;
408 if (next_controller
!= NULL
)
409 next_controller
->prev
= NULL
;
411 agp_fe
.controllers
= next_controller
;
414 agp_remove_all_memory(controller
);
415 agp_remove_all_clients(controller
);
417 if (agp_fe
.current_controller
== controller
) {
418 agp_fe
.current_controller
= NULL
;
419 agp_fe
.backend_acquired
= FALSE
;
420 agp_backend_release(agp_bridge
);
426 static void agp_controller_make_current(struct agp_controller
*controller
)
428 struct agp_client
*clients
;
430 clients
= controller
->clients
;
432 while (clients
!= NULL
) {
433 struct agp_file_private
*priv
;
435 priv
= agp_find_private(clients
->pid
);
438 set_bit(AGP_FF_IS_VALID
, &priv
->access_flags
);
439 set_bit(AGP_FF_IS_CLIENT
, &priv
->access_flags
);
441 clients
= clients
->next
;
444 agp_fe
.current_controller
= controller
;
447 static void agp_controller_release_current(struct agp_controller
*controller
,
448 struct agp_file_private
*controller_priv
)
450 struct agp_client
*clients
;
452 clear_bit(AGP_FF_IS_VALID
, &controller_priv
->access_flags
);
453 clients
= controller
->clients
;
455 while (clients
!= NULL
) {
456 struct agp_file_private
*priv
;
458 priv
= agp_find_private(clients
->pid
);
461 clear_bit(AGP_FF_IS_VALID
, &priv
->access_flags
);
463 clients
= clients
->next
;
466 agp_fe
.current_controller
= NULL
;
467 agp_fe
.used_by_controller
= FALSE
;
468 agp_backend_release(agp_bridge
);
472 * Routines for managing client lists -
473 * These routines are for managing the list of auth'ed clients.
476 static struct agp_client
477 *agp_find_client_in_controller(struct agp_controller
*controller
, pid_t id
)
479 struct agp_client
*client
;
481 if (controller
== NULL
)
484 client
= controller
->clients
;
486 while (client
!= NULL
) {
487 if (client
->pid
== id
)
489 client
= client
->next
;
495 static struct agp_controller
*agp_find_controller_for_client(pid_t id
)
497 struct agp_controller
*controller
;
499 controller
= agp_fe
.controllers
;
501 while (controller
!= NULL
) {
502 if ((agp_find_client_in_controller(controller
, id
)) != NULL
)
504 controller
= controller
->next
;
510 static struct agp_client
*agp_find_client_by_pid(pid_t id
)
512 struct agp_client
*temp
;
514 if (agp_fe
.current_controller
== NULL
)
517 temp
= agp_find_client_in_controller(agp_fe
.current_controller
, id
);
521 static void agp_insert_client(struct agp_client
*client
)
523 struct agp_client
*prev_client
;
525 prev_client
= agp_fe
.current_controller
->clients
;
526 client
->next
= prev_client
;
528 if (prev_client
!= NULL
)
529 prev_client
->prev
= client
;
531 agp_fe
.current_controller
->clients
= client
;
532 agp_fe
.current_controller
->num_clients
++;
535 static struct agp_client
*agp_create_client(pid_t id
)
537 struct agp_client
*new_client
;
539 new_client
= kzalloc(sizeof(struct agp_client
), GFP_KERNEL
);
540 if (new_client
== NULL
)
543 new_client
->pid
= id
;
544 agp_insert_client(new_client
);
548 static int agp_remove_client(pid_t id
)
550 struct agp_client
*client
;
551 struct agp_client
*prev_client
;
552 struct agp_client
*next_client
;
553 struct agp_controller
*controller
;
555 controller
= agp_find_controller_for_client(id
);
556 if (controller
== NULL
)
559 client
= agp_find_client_in_controller(controller
, id
);
563 prev_client
= client
->prev
;
564 next_client
= client
->next
;
566 if (prev_client
!= NULL
) {
567 prev_client
->next
= next_client
;
568 if (next_client
!= NULL
)
569 next_client
->prev
= prev_client
;
572 if (next_client
!= NULL
)
573 next_client
->prev
= NULL
;
574 controller
->clients
= next_client
;
577 controller
->num_clients
--;
578 agp_remove_seg_from_client(client
);
583 /* End - Routines for managing client lists */
585 /* File Operations */
587 static int agp_mmap(struct file
*file
, struct vm_area_struct
*vma
)
589 unsigned int size
, current_size
;
590 unsigned long offset
;
591 struct agp_client
*client
;
592 struct agp_file_private
*priv
= file
->private_data
;
593 struct agp_kern_info kerninfo
;
595 mutex_lock(&(agp_fe
.agp_mutex
));
597 if (agp_fe
.backend_acquired
!= TRUE
)
600 if (!(test_bit(AGP_FF_IS_VALID
, &priv
->access_flags
)))
603 agp_copy_info(agp_bridge
, &kerninfo
);
604 size
= vma
->vm_end
- vma
->vm_start
;
605 current_size
= kerninfo
.aper_size
;
606 current_size
= current_size
* 0x100000;
607 offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
608 DBG("%lx:%lx", offset
, offset
+size
);
610 if (test_bit(AGP_FF_IS_CLIENT
, &priv
->access_flags
)) {
611 if ((size
+ offset
) > current_size
)
614 client
= agp_find_client_by_pid(current
->pid
);
619 if (!agp_find_seg_in_client(client
, offset
, size
, vma
->vm_page_prot
))
622 DBG("client vm_ops=%p", kerninfo
.vm_ops
);
623 if (kerninfo
.vm_ops
) {
624 vma
->vm_ops
= kerninfo
.vm_ops
;
625 } else if (io_remap_pfn_range(vma
, vma
->vm_start
,
626 (kerninfo
.aper_base
+ offset
) >> PAGE_SHIFT
,
627 size
, vma
->vm_page_prot
)) {
630 mutex_unlock(&(agp_fe
.agp_mutex
));
634 if (test_bit(AGP_FF_IS_CONTROLLER
, &priv
->access_flags
)) {
635 if (size
!= current_size
)
638 DBG("controller vm_ops=%p", kerninfo
.vm_ops
);
639 if (kerninfo
.vm_ops
) {
640 vma
->vm_ops
= kerninfo
.vm_ops
;
641 } else if (io_remap_pfn_range(vma
, vma
->vm_start
,
642 kerninfo
.aper_base
>> PAGE_SHIFT
,
643 size
, vma
->vm_page_prot
)) {
646 mutex_unlock(&(agp_fe
.agp_mutex
));
651 mutex_unlock(&(agp_fe
.agp_mutex
));
655 mutex_unlock(&(agp_fe
.agp_mutex
));
659 mutex_unlock(&(agp_fe
.agp_mutex
));
663 static int agp_release(struct inode
*inode
, struct file
*file
)
665 struct agp_file_private
*priv
= file
->private_data
;
667 mutex_lock(&(agp_fe
.agp_mutex
));
669 DBG("priv=%p", priv
);
671 if (test_bit(AGP_FF_IS_CONTROLLER
, &priv
->access_flags
)) {
672 struct agp_controller
*controller
;
674 controller
= agp_find_controller_by_pid(priv
->my_pid
);
676 if (controller
!= NULL
) {
677 if (controller
== agp_fe
.current_controller
)
678 agp_controller_release_current(controller
, priv
);
679 agp_remove_controller(controller
);
684 if (test_bit(AGP_FF_IS_CLIENT
, &priv
->access_flags
))
685 agp_remove_client(priv
->my_pid
);
687 agp_remove_file_private(priv
);
689 file
->private_data
= NULL
;
690 mutex_unlock(&(agp_fe
.agp_mutex
));
694 static int agp_open(struct inode
*inode
, struct file
*file
)
696 int minor
= iminor(inode
);
697 struct agp_file_private
*priv
;
698 struct agp_client
*client
;
701 mutex_lock(&(agp_fe
.agp_mutex
));
703 if (minor
!= AGPGART_MINOR
)
706 priv
= kzalloc(sizeof(struct agp_file_private
), GFP_KERNEL
);
710 set_bit(AGP_FF_ALLOW_CLIENT
, &priv
->access_flags
);
711 priv
->my_pid
= current
->pid
;
713 if ((current
->uid
== 0) || (current
->suid
== 0)) {
714 /* Root priv, can be controller */
715 set_bit(AGP_FF_ALLOW_CONTROLLER
, &priv
->access_flags
);
717 client
= agp_find_client_by_pid(current
->pid
);
719 if (client
!= NULL
) {
720 set_bit(AGP_FF_IS_CLIENT
, &priv
->access_flags
);
721 set_bit(AGP_FF_IS_VALID
, &priv
->access_flags
);
723 file
->private_data
= (void *) priv
;
724 agp_insert_file_private(priv
);
725 DBG("private=%p, client=%p", priv
, client
);
726 mutex_unlock(&(agp_fe
.agp_mutex
));
732 mutex_unlock(&(agp_fe
.agp_mutex
));
737 static ssize_t
agp_read(struct file
*file
, char __user
*buf
,
738 size_t count
, loff_t
* ppos
)
743 static ssize_t
agp_write(struct file
*file
, const char __user
*buf
,
744 size_t count
, loff_t
* ppos
)
749 static int agpioc_info_wrap(struct agp_file_private
*priv
, void __user
*arg
)
751 struct agp_info userinfo
;
752 struct agp_kern_info kerninfo
;
754 agp_copy_info(agp_bridge
, &kerninfo
);
756 userinfo
.version
.major
= kerninfo
.version
.major
;
757 userinfo
.version
.minor
= kerninfo
.version
.minor
;
758 userinfo
.bridge_id
= kerninfo
.device
->vendor
|
759 (kerninfo
.device
->device
<< 16);
760 userinfo
.agp_mode
= kerninfo
.mode
;
761 userinfo
.aper_base
= kerninfo
.aper_base
;
762 userinfo
.aper_size
= kerninfo
.aper_size
;
763 userinfo
.pg_total
= userinfo
.pg_system
= kerninfo
.max_memory
;
764 userinfo
.pg_used
= kerninfo
.current_memory
;
766 if (copy_to_user(arg
, &userinfo
, sizeof(struct agp_info
)))
772 static int agpioc_acquire_wrap(struct agp_file_private
*priv
)
774 struct agp_controller
*controller
;
778 if (!(test_bit(AGP_FF_ALLOW_CONTROLLER
, &priv
->access_flags
)))
781 if (agp_fe
.current_controller
!= NULL
)
787 if (atomic_read(&agp_bridge
->agp_in_use
))
790 atomic_inc(&agp_bridge
->agp_in_use
);
792 agp_fe
.backend_acquired
= TRUE
;
794 controller
= agp_find_controller_by_pid(priv
->my_pid
);
796 if (controller
!= NULL
) {
797 agp_controller_make_current(controller
);
799 controller
= agp_create_controller(priv
->my_pid
);
801 if (controller
== NULL
) {
802 agp_fe
.backend_acquired
= FALSE
;
803 agp_backend_release(agp_bridge
);
806 agp_insert_controller(controller
);
807 agp_controller_make_current(controller
);
810 set_bit(AGP_FF_IS_CONTROLLER
, &priv
->access_flags
);
811 set_bit(AGP_FF_IS_VALID
, &priv
->access_flags
);
815 static int agpioc_release_wrap(struct agp_file_private
*priv
)
818 agp_controller_release_current(agp_fe
.current_controller
, priv
);
822 static int agpioc_setup_wrap(struct agp_file_private
*priv
, void __user
*arg
)
824 struct agp_setup mode
;
827 if (copy_from_user(&mode
, arg
, sizeof(struct agp_setup
)))
830 agp_enable(agp_bridge
, mode
.agp_mode
);
834 static int agpioc_reserve_wrap(struct agp_file_private
*priv
, void __user
*arg
)
836 struct agp_region reserve
;
837 struct agp_client
*client
;
838 struct agp_file_private
*client_priv
;
841 if (copy_from_user(&reserve
, arg
, sizeof(struct agp_region
)))
844 if ((unsigned) reserve
.seg_count
>= ~0U/sizeof(struct agp_segment
))
847 client
= agp_find_client_by_pid(reserve
.pid
);
849 if (reserve
.seg_count
== 0) {
850 /* remove a client */
851 client_priv
= agp_find_private(reserve
.pid
);
853 if (client_priv
!= NULL
) {
854 set_bit(AGP_FF_IS_CLIENT
, &client_priv
->access_flags
);
855 set_bit(AGP_FF_IS_VALID
, &client_priv
->access_flags
);
857 if (client
== NULL
) {
858 /* client is already removed */
861 return agp_remove_client(reserve
.pid
);
863 struct agp_segment
*segment
;
865 if (reserve
.seg_count
>= 16384)
868 segment
= kmalloc((sizeof(struct agp_segment
) * reserve
.seg_count
),
874 if (copy_from_user(segment
, (void __user
*) reserve
.seg_list
,
875 sizeof(struct agp_segment
) * reserve
.seg_count
)) {
879 reserve
.seg_list
= segment
;
881 if (client
== NULL
) {
882 /* Create the client and add the segment */
883 client
= agp_create_client(reserve
.pid
);
885 if (client
== NULL
) {
889 client_priv
= agp_find_private(reserve
.pid
);
891 if (client_priv
!= NULL
) {
892 set_bit(AGP_FF_IS_CLIENT
, &client_priv
->access_flags
);
893 set_bit(AGP_FF_IS_VALID
, &client_priv
->access_flags
);
896 return agp_create_segment(client
, &reserve
);
898 /* Will never really happen */
902 static int agpioc_protect_wrap(struct agp_file_private
*priv
)
905 /* This function is not currently implemented */
909 static int agpioc_allocate_wrap(struct agp_file_private
*priv
, void __user
*arg
)
911 struct agp_memory
*memory
;
912 struct agp_allocate alloc
;
915 if (copy_from_user(&alloc
, arg
, sizeof(struct agp_allocate
)))
918 memory
= agp_allocate_memory_wrap(alloc
.pg_count
, alloc
.type
);
923 alloc
.key
= memory
->key
;
924 alloc
.physical
= memory
->physical
;
926 if (copy_to_user(arg
, &alloc
, sizeof(struct agp_allocate
))) {
927 agp_free_memory_wrap(memory
);
933 static int agpioc_deallocate_wrap(struct agp_file_private
*priv
, int arg
)
935 struct agp_memory
*memory
;
938 memory
= agp_find_mem_by_key(arg
);
943 agp_free_memory_wrap(memory
);
947 static int agpioc_bind_wrap(struct agp_file_private
*priv
, void __user
*arg
)
949 struct agp_bind bind_info
;
950 struct agp_memory
*memory
;
953 if (copy_from_user(&bind_info
, arg
, sizeof(struct agp_bind
)))
956 memory
= agp_find_mem_by_key(bind_info
.key
);
961 return agp_bind_memory(memory
, bind_info
.pg_start
);
964 static int agpioc_unbind_wrap(struct agp_file_private
*priv
, void __user
*arg
)
966 struct agp_memory
*memory
;
967 struct agp_unbind unbind
;
970 if (copy_from_user(&unbind
, arg
, sizeof(struct agp_unbind
)))
973 memory
= agp_find_mem_by_key(unbind
.key
);
978 return agp_unbind_memory(memory
);
981 static int agp_ioctl(struct inode
*inode
, struct file
*file
,
982 unsigned int cmd
, unsigned long arg
)
984 struct agp_file_private
*curr_priv
= file
->private_data
;
985 int ret_val
= -ENOTTY
;
987 DBG("priv=%p, cmd=%x", curr_priv
, cmd
);
988 mutex_lock(&(agp_fe
.agp_mutex
));
990 if ((agp_fe
.current_controller
== NULL
) &&
991 (cmd
!= AGPIOC_ACQUIRE
)) {
995 if ((agp_fe
.backend_acquired
!= TRUE
) &&
996 (cmd
!= AGPIOC_ACQUIRE
)) {
1000 if (cmd
!= AGPIOC_ACQUIRE
) {
1001 if (!(test_bit(AGP_FF_IS_CONTROLLER
, &curr_priv
->access_flags
))) {
1005 /* Use the original pid of the controller,
1006 * in case it's threaded */
1008 if (agp_fe
.current_controller
->pid
!= curr_priv
->my_pid
) {
1016 ret_val
= agpioc_info_wrap(curr_priv
, (void __user
*) arg
);
1019 case AGPIOC_ACQUIRE
:
1020 ret_val
= agpioc_acquire_wrap(curr_priv
);
1023 case AGPIOC_RELEASE
:
1024 ret_val
= agpioc_release_wrap(curr_priv
);
1028 ret_val
= agpioc_setup_wrap(curr_priv
, (void __user
*) arg
);
1031 case AGPIOC_RESERVE
:
1032 ret_val
= agpioc_reserve_wrap(curr_priv
, (void __user
*) arg
);
1035 case AGPIOC_PROTECT
:
1036 ret_val
= agpioc_protect_wrap(curr_priv
);
1039 case AGPIOC_ALLOCATE
:
1040 ret_val
= agpioc_allocate_wrap(curr_priv
, (void __user
*) arg
);
1043 case AGPIOC_DEALLOCATE
:
1044 ret_val
= agpioc_deallocate_wrap(curr_priv
, (int) arg
);
1048 ret_val
= agpioc_bind_wrap(curr_priv
, (void __user
*) arg
);
1052 ret_val
= agpioc_unbind_wrap(curr_priv
, (void __user
*) arg
);
1057 DBG("ioctl returns %d\n", ret_val
);
1058 mutex_unlock(&(agp_fe
.agp_mutex
));
1062 static struct file_operations agp_fops
=
1064 .owner
= THIS_MODULE
,
1065 .llseek
= no_llseek
,
1071 .release
= agp_release
,
1074 static struct miscdevice agp_miscdev
=
1076 .minor
= AGPGART_MINOR
,
1081 int agp_frontend_initialize(void)
1083 memset(&agp_fe
, 0, sizeof(struct agp_front_data
));
1084 mutex_init(&(agp_fe
.agp_mutex
));
1086 if (misc_register(&agp_miscdev
)) {
1087 printk(KERN_ERR PFX
"unable to get minor: %d\n", AGPGART_MINOR
);
1093 void agp_frontend_cleanup(void)
1095 misc_deregister(&agp_miscdev
);
This page took 0.0711 seconds and 6 git commands to generate.