Lines Matching +full:memory +full:- +full:controller
4 * Copyright (C) 2002-2003 Dave Jones
53 curr = agp_fe.current_controller->pool; in agp_find_mem_by_key()
56 if (curr->key == key) in agp_find_mem_by_key()
58 curr = curr->next; in agp_find_mem_by_key()
61 DBG("key=%d -> mem=%p", key, curr); in agp_find_mem_by_key()
70 /* Check to see if this is even in the memory pool */ in agp_remove_from_pool()
73 if (agp_find_mem_by_key(temp->key) != NULL) { in agp_remove_from_pool()
74 next = temp->next; in agp_remove_from_pool()
75 prev = temp->prev; in agp_remove_from_pool()
78 prev->next = next; in agp_remove_from_pool()
80 next->prev = prev; in agp_remove_from_pool()
85 next->prev = NULL; in agp_remove_from_pool()
87 agp_fe.current_controller->pool = next; in agp_remove_from_pool()
93 * Routines for managing each client's segment list -
110 seg = *(client->segments); in agp_find_seg_in_client()
112 for (i = 0; i < client->num_segments; i++) { in agp_find_seg_in_client()
127 if (client->segments != NULL) { in agp_remove_seg_from_client()
128 if (*(client->segments) != NULL) { in agp_remove_seg_from_client()
129 DBG("Freeing %p from client %p", *(client->segments), client); in agp_remove_seg_from_client()
130 kfree(*(client->segments)); 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()
134 client->segments = NULL; in agp_remove_seg_from_client()
143 prev_seg = client->segments; in agp_add_seg_to_client()
149 client->num_segments = num_segments; in agp_add_seg_to_client()
150 client->segments = seg; in agp_add_seg_to_client()
168 seg = kzalloc((sizeof(struct agp_segment_priv) * region->seg_count), GFP_KERNEL); in agp_create_segment()
170 kfree(region->seg_list); in agp_create_segment()
171 region->seg_list = NULL; in agp_create_segment()
172 return -ENOMEM; in agp_create_segment()
174 user_seg = region->seg_list; in agp_create_segment()
176 for (i = 0; i < region->seg_count; i++) { in agp_create_segment()
181 kfree(region->seg_list); in agp_create_segment()
182 region->seg_list = NULL; in agp_create_segment()
187 return -ENOMEM; in agp_create_segment()
190 agp_add_seg_to_client(client, ret_seg, region->seg_count); in agp_create_segment()
194 /* End - Routines for managing each client's segment list */
201 prev = agp_fe.current_controller->pool; in agp_insert_into_pool()
204 prev->prev = temp; in agp_insert_into_pool()
205 temp->next = prev; in agp_insert_into_pool()
207 agp_fe.current_controller->pool = temp; in agp_insert_into_pool()
220 if (curr->my_pid == pid) in agp_find_private()
222 curr = curr->next; in agp_find_private()
235 prev->prev = priv; in agp_insert_file_private()
236 priv->next = prev; in agp_insert_file_private()
245 next = priv->next; in agp_remove_file_private()
246 prev = priv->prev; in agp_remove_file_private()
249 prev->next = next; in agp_remove_file_private()
252 next->prev = prev; in agp_remove_file_private()
256 next->prev = NULL; in agp_remove_file_private()
262 /* End - File flag list routines */
268 void agp_free_memory_wrap(struct agp_memory *memory) in agp_free_memory_wrap() argument
270 agp_remove_from_pool(memory); in agp_free_memory_wrap()
271 agp_free_memory(memory); in agp_free_memory_wrap()
276 struct agp_memory *memory; in agp_allocate_memory_wrap() local
278 memory = agp_allocate_memory(agp_bridge, pg_count, type); in agp_allocate_memory_wrap()
279 if (memory == NULL) in agp_allocate_memory_wrap()
282 agp_insert_into_pool(memory); in agp_allocate_memory_wrap()
283 return memory; in agp_allocate_memory_wrap()
286 /* Routines for managing the list of controllers -
287 * These routines manage the current controller, and the list of
293 struct agp_controller *controller; in agp_find_controller_by_pid() local
295 controller = agp_fe.controllers; in agp_find_controller_by_pid()
297 while (controller != NULL) { in agp_find_controller_by_pid()
298 if (controller->pid == id) in agp_find_controller_by_pid()
299 return controller; in agp_find_controller_by_pid()
300 controller = controller->next; in agp_find_controller_by_pid()
308 struct agp_controller *controller; in agp_create_controller() local
310 controller = kzalloc(sizeof(struct agp_controller), GFP_KERNEL); in agp_create_controller()
311 if (controller == NULL) in agp_create_controller()
314 controller->pid = id; in agp_create_controller()
315 return controller; in agp_create_controller()
318 static int agp_insert_controller(struct agp_controller *controller) in agp_insert_controller() argument
323 controller->next = prev_controller; in agp_insert_controller()
326 prev_controller->prev = controller; in agp_insert_controller()
328 agp_fe.controllers = controller; in agp_insert_controller()
333 static void agp_remove_all_clients(struct agp_controller *controller) in agp_remove_all_clients() argument
338 client = controller->clients; in agp_remove_all_clients()
345 priv = agp_find_private(temp->pid); in agp_remove_all_clients()
348 clear_bit(AGP_FF_IS_VALID, &priv->access_flags); in agp_remove_all_clients()
349 clear_bit(AGP_FF_IS_CLIENT, &priv->access_flags); in agp_remove_all_clients()
351 client = client->next; in agp_remove_all_clients()
356 static void agp_remove_all_memory(struct agp_controller *controller) in agp_remove_all_memory() argument
358 struct agp_memory *memory; in agp_remove_all_memory() local
361 memory = controller->pool; in agp_remove_all_memory()
363 while (memory) { in agp_remove_all_memory()
364 temp = memory; in agp_remove_all_memory()
365 memory = memory->next; in agp_remove_all_memory()
370 static int agp_remove_controller(struct agp_controller *controller) in agp_remove_controller() argument
375 prev_controller = controller->prev; in agp_remove_controller()
376 next_controller = controller->next; in agp_remove_controller()
379 prev_controller->next = next_controller; in agp_remove_controller()
381 next_controller->prev = prev_controller; in agp_remove_controller()
385 next_controller->prev = NULL; in agp_remove_controller()
390 agp_remove_all_memory(controller); in agp_remove_controller()
391 agp_remove_all_clients(controller); in agp_remove_controller()
393 if (agp_fe.current_controller == controller) { in agp_remove_controller()
398 kfree(controller); in agp_remove_controller()
402 static void agp_controller_make_current(struct agp_controller *controller) in agp_controller_make_current() argument
406 clients = controller->clients; in agp_controller_make_current()
411 priv = agp_find_private(clients->pid); in agp_controller_make_current()
414 set_bit(AGP_FF_IS_VALID, &priv->access_flags); in agp_controller_make_current()
415 set_bit(AGP_FF_IS_CLIENT, &priv->access_flags); in agp_controller_make_current()
417 clients = clients->next; in agp_controller_make_current()
420 agp_fe.current_controller = controller; in agp_controller_make_current()
423 static void agp_controller_release_current(struct agp_controller *controller, in agp_controller_release_current() argument
428 clear_bit(AGP_FF_IS_VALID, &controller_priv->access_flags); in agp_controller_release_current()
429 clients = controller->clients; in agp_controller_release_current()
434 priv = agp_find_private(clients->pid); in agp_controller_release_current()
437 clear_bit(AGP_FF_IS_VALID, &priv->access_flags); in agp_controller_release_current()
439 clients = clients->next; in agp_controller_release_current()
448 * Routines for managing client lists -
453 *agp_find_client_in_controller(struct agp_controller *controller, pid_t id) in agp_find_client_in_controller() argument
457 if (controller == NULL) in agp_find_client_in_controller()
460 client = controller->clients; in agp_find_client_in_controller()
463 if (client->pid == id) in agp_find_client_in_controller()
465 client = client->next; in agp_find_client_in_controller()
473 struct agp_controller *controller; in agp_find_controller_for_client() local
475 controller = agp_fe.controllers; in agp_find_controller_for_client()
477 while (controller != NULL) { in agp_find_controller_for_client()
478 if ((agp_find_client_in_controller(controller, id)) != NULL) in agp_find_controller_for_client()
479 return controller; in agp_find_controller_for_client()
480 controller = controller->next; in agp_find_controller_for_client()
501 prev_client = agp_fe.current_controller->clients; in agp_insert_client()
502 client->next = prev_client; in agp_insert_client()
505 prev_client->prev = client; in agp_insert_client()
507 agp_fe.current_controller->clients = client; in agp_insert_client()
508 agp_fe.current_controller->num_clients++; in agp_insert_client()
519 new_client->pid = id; in agp_create_client()
529 struct agp_controller *controller; in agp_remove_client() local
531 controller = agp_find_controller_for_client(id); in agp_remove_client()
532 if (controller == NULL) in agp_remove_client()
533 return -EINVAL; in agp_remove_client()
535 client = agp_find_client_in_controller(controller, id); in agp_remove_client()
537 return -EINVAL; in agp_remove_client()
539 prev_client = client->prev; in agp_remove_client()
540 next_client = client->next; in agp_remove_client()
543 prev_client->next = next_client; in agp_remove_client()
545 next_client->prev = prev_client; in agp_remove_client()
549 next_client->prev = NULL; in agp_remove_client()
550 controller->clients = next_client; in agp_remove_client()
553 controller->num_clients--; in agp_remove_client()
559 /* End - Routines for managing client lists */
568 struct agp_file_private *priv = file->private_data; in agp_mmap()
576 if (!(test_bit(AGP_FF_IS_VALID, &priv->access_flags))) in agp_mmap()
580 size = vma->vm_end - vma->vm_start; in agp_mmap()
583 offset = vma->vm_pgoff << PAGE_SHIFT; in agp_mmap()
586 if (test_bit(AGP_FF_IS_CLIENT, &priv->access_flags)) { in agp_mmap()
590 client = agp_find_client_by_pid(current->pid); in agp_mmap()
595 if (!agp_find_seg_in_client(client, offset, size, vma->vm_page_prot)) in agp_mmap()
600 vma->vm_ops = kerninfo.vm_ops; in agp_mmap()
601 } else if (io_remap_pfn_range(vma, vma->vm_start, in agp_mmap()
604 pgprot_writecombine(vma->vm_page_prot))) { in agp_mmap()
611 if (test_bit(AGP_FF_IS_CONTROLLER, &priv->access_flags)) { in agp_mmap()
615 DBG("controller vm_ops=%p", kerninfo.vm_ops); in agp_mmap()
617 vma->vm_ops = kerninfo.vm_ops; in agp_mmap()
618 } else if (io_remap_pfn_range(vma, vma->vm_start, in agp_mmap()
621 pgprot_writecombine(vma->vm_page_prot))) { in agp_mmap()
630 return -EPERM; in agp_mmap()
634 return -EINVAL; in agp_mmap()
638 return -EAGAIN; in agp_mmap()
643 struct agp_file_private *priv = file->private_data; in agp_release()
649 if (test_bit(AGP_FF_IS_CONTROLLER, &priv->access_flags)) { in agp_release()
650 struct agp_controller *controller; in agp_release() local
652 controller = agp_find_controller_by_pid(priv->my_pid); in agp_release()
654 if (controller != NULL) { in agp_release()
655 if (controller == agp_fe.current_controller) in agp_release()
656 agp_controller_release_current(controller, priv); in agp_release()
657 agp_remove_controller(controller); in agp_release()
658 controller = NULL; in agp_release()
662 if (test_bit(AGP_FF_IS_CLIENT, &priv->access_flags)) in agp_release()
663 agp_remove_client(priv->my_pid); in agp_release()
667 file->private_data = NULL; in agp_release()
679 return -ENXIO; in agp_open()
686 return -ENOMEM; in agp_open()
689 set_bit(AGP_FF_ALLOW_CLIENT, &priv->access_flags); in agp_open()
690 priv->my_pid = current->pid; in agp_open()
693 /* Root priv, can be controller */ in agp_open()
694 set_bit(AGP_FF_ALLOW_CONTROLLER, &priv->access_flags); in agp_open()
696 client = agp_find_client_by_pid(current->pid); in agp_open()
699 set_bit(AGP_FF_IS_CLIENT, &priv->access_flags); in agp_open()
700 set_bit(AGP_FF_IS_VALID, &priv->access_flags); in agp_open()
702 file->private_data = (void *) priv; in agp_open()
721 userinfo.bridge_id = kerninfo.device->vendor | in agpioc_info_wrap()
722 (kerninfo.device->device << 16); in agpioc_info_wrap()
730 return -EFAULT; in agpioc_info_wrap()
737 struct agp_controller *controller; in agpioc_acquire_wrap() local
741 if (!(test_bit(AGP_FF_ALLOW_CONTROLLER, &priv->access_flags))) in agpioc_acquire_wrap()
742 return -EPERM; in agpioc_acquire_wrap()
745 return -EBUSY; in agpioc_acquire_wrap()
748 return -ENODEV; in agpioc_acquire_wrap()
750 if (atomic_read(&agp_bridge->agp_in_use)) in agpioc_acquire_wrap()
751 return -EBUSY; in agpioc_acquire_wrap()
753 atomic_inc(&agp_bridge->agp_in_use); in agpioc_acquire_wrap()
757 controller = agp_find_controller_by_pid(priv->my_pid); in agpioc_acquire_wrap()
759 if (controller != NULL) { in agpioc_acquire_wrap()
760 agp_controller_make_current(controller); in agpioc_acquire_wrap()
762 controller = agp_create_controller(priv->my_pid); in agpioc_acquire_wrap()
764 if (controller == NULL) { in agpioc_acquire_wrap()
767 return -ENOMEM; in agpioc_acquire_wrap()
769 agp_insert_controller(controller); in agpioc_acquire_wrap()
770 agp_controller_make_current(controller); in agpioc_acquire_wrap()
773 set_bit(AGP_FF_IS_CONTROLLER, &priv->access_flags); in agpioc_acquire_wrap()
774 set_bit(AGP_FF_IS_VALID, &priv->access_flags); in agpioc_acquire_wrap()
791 return -EFAULT; in agpioc_setup_wrap()
805 return -EFAULT; in agpioc_reserve_wrap()
808 return -EFAULT; in agpioc_reserve_wrap()
817 set_bit(AGP_FF_IS_CLIENT, &client_priv->access_flags); in agpioc_reserve_wrap()
818 set_bit(AGP_FF_IS_VALID, &client_priv->access_flags); in agpioc_reserve_wrap()
829 return -EINVAL; in agpioc_reserve_wrap()
835 return -ENOMEM; in agpioc_reserve_wrap()
840 return -EFAULT; in agpioc_reserve_wrap()
850 return -ENOMEM; in agpioc_reserve_wrap()
855 set_bit(AGP_FF_IS_CLIENT, &client_priv->access_flags); in agpioc_reserve_wrap()
856 set_bit(AGP_FF_IS_VALID, &client_priv->access_flags); in agpioc_reserve_wrap()
862 return -EINVAL; in agpioc_reserve_wrap()
869 return -EINVAL; in agpioc_protect_wrap()
874 struct agp_memory *memory; in agpioc_allocate_wrap() local
879 return -EFAULT; in agpioc_allocate_wrap()
882 return -EINVAL; in agpioc_allocate_wrap()
884 memory = agp_allocate_memory_wrap(alloc.pg_count, alloc.type); in agpioc_allocate_wrap()
886 if (memory == NULL) in agpioc_allocate_wrap()
887 return -ENOMEM; in agpioc_allocate_wrap()
889 alloc.key = memory->key; in agpioc_allocate_wrap()
890 alloc.physical = memory->physical; in agpioc_allocate_wrap()
893 agp_free_memory_wrap(memory); in agpioc_allocate_wrap()
894 return -EFAULT; in agpioc_allocate_wrap()
901 struct agp_memory *memory; in agpioc_deallocate_wrap() local
904 memory = agp_find_mem_by_key(arg); in agpioc_deallocate_wrap()
906 if (memory == NULL) in agpioc_deallocate_wrap()
907 return -EINVAL; in agpioc_deallocate_wrap()
909 agp_free_memory_wrap(memory); in agpioc_deallocate_wrap()
916 struct agp_memory *memory; in agpioc_bind_wrap() local
920 return -EFAULT; in agpioc_bind_wrap()
922 memory = agp_find_mem_by_key(bind_info.key); in agpioc_bind_wrap()
924 if (memory == NULL) in agpioc_bind_wrap()
925 return -EINVAL; in agpioc_bind_wrap()
927 return agp_bind_memory(memory, bind_info.pg_start); in agpioc_bind_wrap()
932 struct agp_memory *memory; in agpioc_unbind_wrap() local
937 return -EFAULT; in agpioc_unbind_wrap()
939 memory = agp_find_mem_by_key(unbind.key); in agpioc_unbind_wrap()
941 if (memory == NULL) in agpioc_unbind_wrap()
942 return -EINVAL; in agpioc_unbind_wrap()
944 return agp_unbind_memory(memory); in agpioc_unbind_wrap()
950 struct agp_file_private *curr_priv = file->private_data; in agp_ioctl()
951 int ret_val = -ENOTTY; in agp_ioctl()
958 ret_val = -EINVAL; in agp_ioctl()
963 ret_val = -EBUSY; in agp_ioctl()
967 if (!(test_bit(AGP_FF_IS_CONTROLLER, &curr_priv->access_flags))) { in agp_ioctl()
968 ret_val = -EPERM; in agp_ioctl()
971 /* Use the original pid of the controller, in agp_ioctl()
974 if (agp_fe.current_controller->pid != curr_priv->my_pid) { in agp_ioctl()
975 ret_val = -EBUSY; in agp_ioctl()
1058 return -EIO; in agp_frontend_initialize()