Lines Matching +full:memory +full:- +full:controller

4  * Copyright (C) 2002-2003 Dave Jones
55 curr = agp_fe.current_controller->pool; in agp_find_mem_by_key()
58 if (curr->key == key) in agp_find_mem_by_key()
60 curr = curr->next; in agp_find_mem_by_key()
63 DBG("key=%d -> mem=%p", key, curr); in agp_find_mem_by_key()
72 /* Check to see if this is even in the memory pool */ in agp_remove_from_pool()
75 if (agp_find_mem_by_key(temp->key) != NULL) { in agp_remove_from_pool()
76 next = temp->next; in agp_remove_from_pool()
77 prev = temp->prev; in agp_remove_from_pool()
80 prev->next = next; in agp_remove_from_pool()
82 next->prev = prev; in agp_remove_from_pool()
87 next->prev = NULL; in agp_remove_from_pool()
89 agp_fe.current_controller->pool = next; in agp_remove_from_pool()
95 * Routines for managing each client's segment list -
112 seg = *(client->segments); in agp_find_seg_in_client()
113 num_segments = client->num_segments; in agp_find_seg_in_client()
115 for (i = 0; i < client->num_segments; i++) { in agp_find_seg_in_client()
130 if (client->segments != NULL) { in agp_remove_seg_from_client()
131 if (*(client->segments) != NULL) { in agp_remove_seg_from_client()
132 DBG("Freeing %p from client %p", *(client->segments), client); in agp_remove_seg_from_client()
133 kfree(*(client->segments)); in agp_remove_seg_from_client()
135 DBG("Freeing %p from client %p", client->segments, client); in agp_remove_seg_from_client()
136 kfree(client->segments); in agp_remove_seg_from_client()
137 client->segments = NULL; in agp_remove_seg_from_client()
146 prev_seg = client->segments; in agp_add_seg_to_client()
152 client->num_segments = num_segments; in agp_add_seg_to_client()
153 client->segments = seg; in agp_add_seg_to_client()
171 seg = kzalloc((sizeof(struct agp_segment_priv) * region->seg_count), GFP_KERNEL); in agp_create_segment()
173 kfree(region->seg_list); in agp_create_segment()
174 region->seg_list = NULL; in agp_create_segment()
175 return -ENOMEM; in agp_create_segment()
177 user_seg = region->seg_list; in agp_create_segment()
179 for (i = 0; i < region->seg_count; i++) { in agp_create_segment()
184 kfree(region->seg_list); in agp_create_segment()
185 region->seg_list = NULL; in agp_create_segment()
190 return -ENOMEM; in agp_create_segment()
193 agp_add_seg_to_client(client, ret_seg, region->seg_count); in agp_create_segment()
197 /* End - Routines for managing each client's segment list */
204 prev = agp_fe.current_controller->pool; in agp_insert_into_pool()
207 prev->prev = temp; in agp_insert_into_pool()
208 temp->next = prev; in agp_insert_into_pool()
210 agp_fe.current_controller->pool = temp; in agp_insert_into_pool()
223 if (curr->my_pid == pid) in agp_find_private()
225 curr = curr->next; in agp_find_private()
238 prev->prev = priv; in agp_insert_file_private()
239 priv->next = prev; in agp_insert_file_private()
248 next = priv->next; in agp_remove_file_private()
249 prev = priv->prev; in agp_remove_file_private()
252 prev->next = next; in agp_remove_file_private()
255 next->prev = prev; in agp_remove_file_private()
259 next->prev = NULL; in agp_remove_file_private()
265 /* End - File flag list routines */
271 void agp_free_memory_wrap(struct agp_memory *memory) in agp_free_memory_wrap() argument
273 agp_remove_from_pool(memory); in agp_free_memory_wrap()
274 agp_free_memory(memory); in agp_free_memory_wrap()
279 struct agp_memory *memory; in agp_allocate_memory_wrap() local
281 memory = agp_allocate_memory(agp_bridge, pg_count, type); in agp_allocate_memory_wrap()
282 if (memory == NULL) in agp_allocate_memory_wrap()
285 agp_insert_into_pool(memory); in agp_allocate_memory_wrap()
286 return memory; in agp_allocate_memory_wrap()
289 /* Routines for managing the list of controllers -
290 * These routines manage the current controller, and the list of
296 struct agp_controller *controller; in agp_find_controller_by_pid() local
298 controller = agp_fe.controllers; in agp_find_controller_by_pid()
300 while (controller != NULL) { in agp_find_controller_by_pid()
301 if (controller->pid == id) in agp_find_controller_by_pid()
302 return controller; in agp_find_controller_by_pid()
303 controller = controller->next; in agp_find_controller_by_pid()
311 struct agp_controller *controller; in agp_create_controller() local
313 controller = kzalloc(sizeof(struct agp_controller), GFP_KERNEL); in agp_create_controller()
314 if (controller == NULL) in agp_create_controller()
317 controller->pid = id; in agp_create_controller()
318 return controller; in agp_create_controller()
321 static int agp_insert_controller(struct agp_controller *controller) in agp_insert_controller() argument
326 controller->next = prev_controller; in agp_insert_controller()
329 prev_controller->prev = controller; in agp_insert_controller()
331 agp_fe.controllers = controller; in agp_insert_controller()
336 static void agp_remove_all_clients(struct agp_controller *controller) in agp_remove_all_clients() argument
341 client = controller->clients; in agp_remove_all_clients()
348 priv = agp_find_private(temp->pid); in agp_remove_all_clients()
351 clear_bit(AGP_FF_IS_VALID, &priv->access_flags); in agp_remove_all_clients()
352 clear_bit(AGP_FF_IS_CLIENT, &priv->access_flags); in agp_remove_all_clients()
354 client = client->next; in agp_remove_all_clients()
359 static void agp_remove_all_memory(struct agp_controller *controller) in agp_remove_all_memory() argument
361 struct agp_memory *memory; in agp_remove_all_memory() local
364 memory = controller->pool; in agp_remove_all_memory()
366 while (memory) { in agp_remove_all_memory()
367 temp = memory; in agp_remove_all_memory()
368 memory = memory->next; in agp_remove_all_memory()
373 static int agp_remove_controller(struct agp_controller *controller) in agp_remove_controller() argument
378 prev_controller = controller->prev; in agp_remove_controller()
379 next_controller = controller->next; in agp_remove_controller()
382 prev_controller->next = next_controller; in agp_remove_controller()
384 next_controller->prev = prev_controller; in agp_remove_controller()
388 next_controller->prev = NULL; in agp_remove_controller()
393 agp_remove_all_memory(controller); in agp_remove_controller()
394 agp_remove_all_clients(controller); in agp_remove_controller()
396 if (agp_fe.current_controller == controller) { in agp_remove_controller()
401 kfree(controller); in agp_remove_controller()
405 static void agp_controller_make_current(struct agp_controller *controller) in agp_controller_make_current() argument
409 clients = controller->clients; in agp_controller_make_current()
414 priv = agp_find_private(clients->pid); in agp_controller_make_current()
417 set_bit(AGP_FF_IS_VALID, &priv->access_flags); in agp_controller_make_current()
418 set_bit(AGP_FF_IS_CLIENT, &priv->access_flags); in agp_controller_make_current()
420 clients = clients->next; in agp_controller_make_current()
423 agp_fe.current_controller = controller; in agp_controller_make_current()
426 static void agp_controller_release_current(struct agp_controller *controller, in agp_controller_release_current() argument
431 clear_bit(AGP_FF_IS_VALID, &controller_priv->access_flags); in agp_controller_release_current()
432 clients = controller->clients; in agp_controller_release_current()
437 priv = agp_find_private(clients->pid); in agp_controller_release_current()
440 clear_bit(AGP_FF_IS_VALID, &priv->access_flags); in agp_controller_release_current()
442 clients = clients->next; in agp_controller_release_current()
451 * Routines for managing client lists -
456 *agp_find_client_in_controller(struct agp_controller *controller, pid_t id) in agp_find_client_in_controller() argument
460 if (controller == NULL) in agp_find_client_in_controller()
463 client = controller->clients; in agp_find_client_in_controller()
466 if (client->pid == id) in agp_find_client_in_controller()
468 client = client->next; in agp_find_client_in_controller()
476 struct agp_controller *controller; in agp_find_controller_for_client() local
478 controller = agp_fe.controllers; in agp_find_controller_for_client()
480 while (controller != NULL) { in agp_find_controller_for_client()
481 if ((agp_find_client_in_controller(controller, id)) != NULL) in agp_find_controller_for_client()
482 return controller; in agp_find_controller_for_client()
483 controller = controller->next; in agp_find_controller_for_client()
504 prev_client = agp_fe.current_controller->clients; in agp_insert_client()
505 client->next = prev_client; in agp_insert_client()
508 prev_client->prev = client; in agp_insert_client()
510 agp_fe.current_controller->clients = client; in agp_insert_client()
511 agp_fe.current_controller->num_clients++; in agp_insert_client()
522 new_client->pid = id; in agp_create_client()
532 struct agp_controller *controller; in agp_remove_client() local
534 controller = agp_find_controller_for_client(id); in agp_remove_client()
535 if (controller == NULL) in agp_remove_client()
536 return -EINVAL; in agp_remove_client()
538 client = agp_find_client_in_controller(controller, id); in agp_remove_client()
540 return -EINVAL; in agp_remove_client()
542 prev_client = client->prev; in agp_remove_client()
543 next_client = client->next; in agp_remove_client()
546 prev_client->next = next_client; in agp_remove_client()
548 next_client->prev = prev_client; in agp_remove_client()
552 next_client->prev = NULL; in agp_remove_client()
553 controller->clients = next_client; in agp_remove_client()
556 controller->num_clients--; in agp_remove_client()
562 /* End - Routines for managing client lists */
571 struct agp_file_private *priv = file->private_data; in agp_mmap()
579 if (!(test_bit(AGP_FF_IS_VALID, &priv->access_flags))) in agp_mmap()
583 size = vma->vm_end - vma->vm_start; in agp_mmap()
586 offset = vma->vm_pgoff << PAGE_SHIFT; in agp_mmap()
589 if (test_bit(AGP_FF_IS_CLIENT, &priv->access_flags)) { in agp_mmap()
593 client = agp_find_client_by_pid(current->pid); in agp_mmap()
598 if (!agp_find_seg_in_client(client, offset, size, vma->vm_page_prot)) in agp_mmap()
603 vma->vm_ops = kerninfo.vm_ops; in agp_mmap()
604 } else if (io_remap_pfn_range(vma, vma->vm_start, in agp_mmap()
606 size, vma->vm_page_prot)) { in agp_mmap()
613 if (test_bit(AGP_FF_IS_CONTROLLER, &priv->access_flags)) { in agp_mmap()
617 DBG("controller vm_ops=%p", kerninfo.vm_ops); in agp_mmap()
619 vma->vm_ops = kerninfo.vm_ops; in agp_mmap()
620 } else if (io_remap_pfn_range(vma, vma->vm_start, in agp_mmap()
622 size, vma->vm_page_prot)) { in agp_mmap()
631 return -EPERM; in agp_mmap()
635 return -EINVAL; in agp_mmap()
639 return -EAGAIN; in agp_mmap()
644 struct agp_file_private *priv = file->private_data; in agp_release()
650 if (test_bit(AGP_FF_IS_CONTROLLER, &priv->access_flags)) { in agp_release()
651 struct agp_controller *controller; in agp_release() local
653 controller = agp_find_controller_by_pid(priv->my_pid); in agp_release()
655 if (controller != NULL) { in agp_release()
656 if (controller == agp_fe.current_controller) in agp_release()
657 agp_controller_release_current(controller, priv); in agp_release()
658 agp_remove_controller(controller); in agp_release()
659 controller = NULL; in agp_release()
663 if (test_bit(AGP_FF_IS_CLIENT, &priv->access_flags)) in agp_release()
664 agp_remove_client(priv->my_pid); in agp_release()
668 file->private_data = NULL; in agp_release()
680 return -ENXIO; in agp_open()
687 return -ENOMEM; in agp_open()
690 set_bit(AGP_FF_ALLOW_CLIENT, &priv->access_flags); in agp_open()
691 priv->my_pid = current->pid; in agp_open()
694 /* Root priv, can be controller */ in agp_open()
695 set_bit(AGP_FF_ALLOW_CONTROLLER, &priv->access_flags); in agp_open()
697 client = agp_find_client_by_pid(current->pid); in agp_open()
700 set_bit(AGP_FF_IS_CLIENT, &priv->access_flags); in agp_open()
701 set_bit(AGP_FF_IS_VALID, &priv->access_flags); in agp_open()
703 file->private_data = (void *) priv; in agp_open()
716 return -EINVAL; in agp_read()
722 return -EINVAL; in agp_write()
734 userinfo.bridge_id = kerninfo.device->vendor | in agpioc_info_wrap()
735 (kerninfo.device->device << 16); in agpioc_info_wrap()
743 return -EFAULT; in agpioc_info_wrap()
750 struct agp_controller *controller; in agpioc_acquire_wrap() local
754 if (!(test_bit(AGP_FF_ALLOW_CONTROLLER, &priv->access_flags))) in agpioc_acquire_wrap()
755 return -EPERM; in agpioc_acquire_wrap()
758 return -EBUSY; in agpioc_acquire_wrap()
761 return -ENODEV; in agpioc_acquire_wrap()
763 if (atomic_read(&agp_bridge->agp_in_use)) in agpioc_acquire_wrap()
764 return -EBUSY; in agpioc_acquire_wrap()
766 atomic_inc(&agp_bridge->agp_in_use); in agpioc_acquire_wrap()
770 controller = agp_find_controller_by_pid(priv->my_pid); in agpioc_acquire_wrap()
772 if (controller != NULL) { in agpioc_acquire_wrap()
773 agp_controller_make_current(controller); in agpioc_acquire_wrap()
775 controller = agp_create_controller(priv->my_pid); in agpioc_acquire_wrap()
777 if (controller == NULL) { in agpioc_acquire_wrap()
780 return -ENOMEM; in agpioc_acquire_wrap()
782 agp_insert_controller(controller); in agpioc_acquire_wrap()
783 agp_controller_make_current(controller); in agpioc_acquire_wrap()
786 set_bit(AGP_FF_IS_CONTROLLER, &priv->access_flags); in agpioc_acquire_wrap()
787 set_bit(AGP_FF_IS_VALID, &priv->access_flags); in agpioc_acquire_wrap()
804 return -EFAULT; in agpioc_setup_wrap()
818 return -EFAULT; in agpioc_reserve_wrap()
821 return -EFAULT; in agpioc_reserve_wrap()
830 set_bit(AGP_FF_IS_CLIENT, &client_priv->access_flags); in agpioc_reserve_wrap()
831 set_bit(AGP_FF_IS_VALID, &client_priv->access_flags); in agpioc_reserve_wrap()
842 return -EINVAL; in agpioc_reserve_wrap()
848 return -ENOMEM; in agpioc_reserve_wrap()
853 return -EFAULT; in agpioc_reserve_wrap()
863 return -ENOMEM; in agpioc_reserve_wrap()
868 set_bit(AGP_FF_IS_CLIENT, &client_priv->access_flags); in agpioc_reserve_wrap()
869 set_bit(AGP_FF_IS_VALID, &client_priv->access_flags); in agpioc_reserve_wrap()
875 return -EINVAL; in agpioc_reserve_wrap()
882 return -EINVAL; in agpioc_protect_wrap()
887 struct agp_memory *memory; in agpioc_allocate_wrap() local
892 return -EFAULT; in agpioc_allocate_wrap()
895 return -EINVAL; in agpioc_allocate_wrap()
897 memory = agp_allocate_memory_wrap(alloc.pg_count, alloc.type); in agpioc_allocate_wrap()
899 if (memory == NULL) in agpioc_allocate_wrap()
900 return -ENOMEM; in agpioc_allocate_wrap()
902 alloc.key = memory->key; in agpioc_allocate_wrap()
903 alloc.physical = memory->physical; in agpioc_allocate_wrap()
906 agp_free_memory_wrap(memory); in agpioc_allocate_wrap()
907 return -EFAULT; in agpioc_allocate_wrap()
914 struct agp_memory *memory; in agpioc_deallocate_wrap() local
917 memory = agp_find_mem_by_key(arg); in agpioc_deallocate_wrap()
919 if (memory == NULL) in agpioc_deallocate_wrap()
920 return -EINVAL; in agpioc_deallocate_wrap()
922 agp_free_memory_wrap(memory); in agpioc_deallocate_wrap()
929 struct agp_memory *memory; in agpioc_bind_wrap() local
933 return -EFAULT; in agpioc_bind_wrap()
935 memory = agp_find_mem_by_key(bind_info.key); in agpioc_bind_wrap()
937 if (memory == NULL) in agpioc_bind_wrap()
938 return -EINVAL; in agpioc_bind_wrap()
940 return agp_bind_memory(memory, bind_info.pg_start); in agpioc_bind_wrap()
945 struct agp_memory *memory; in agpioc_unbind_wrap() local
950 return -EFAULT; in agpioc_unbind_wrap()
952 memory = agp_find_mem_by_key(unbind.key); in agpioc_unbind_wrap()
954 if (memory == NULL) in agpioc_unbind_wrap()
955 return -EINVAL; in agpioc_unbind_wrap()
957 return agp_unbind_memory(memory); in agpioc_unbind_wrap()
963 struct agp_file_private *curr_priv = file->private_data; in agp_ioctl()
964 int ret_val = -ENOTTY; in agp_ioctl()
971 ret_val = -EINVAL; in agp_ioctl()
976 ret_val = -EBUSY; in agp_ioctl()
980 if (!(test_bit(AGP_FF_IS_CONTROLLER, &curr_priv->access_flags))) { in agp_ioctl()
981 ret_val = -EPERM; in agp_ioctl()
984 /* Use the original pid of the controller, in agp_ioctl()
987 if (agp_fe.current_controller->pid != curr_priv->my_pid) { in agp_ioctl()
988 ret_val = -EBUSY; in agp_ioctl()
1073 return -EIO; in agp_frontend_initialize()