/* It returns -EINVAL if this piece of agp_memory is not currently bound to the graphics aperture translation table or if the agp_memory pointer == NULL  */
int agp_unbind_memory(struct agp_memory *curr)
/* It returns -EINVAL if this piece of agp_memory is not currently bound to the graphics aperture translation table or if the agp_memory pointer == NULL  */
int agp_unbind_memory(struct agp_memory *curr)
{
	int ret_val;
	if (curr == NULL)
		return -EINVAL;
	if (!curr->is_bound) {
		printk(KERN_INFO PFX "memory %p was not bound!\n", curr);
		return -EINVAL;
	}
	ret_val = curr->bridge->driver->remove_memory(curr, curr->pg_start, curr->type);
	if (ret_val != 0)
		return ret_val;
	if (curr->bridge->driver->agp_unmap_memory)
		curr->bridge->driver->agp_unmap_memory(curr);
	curr->is_bound = false;
	curr->pg_start = 0;
	spin_lock(&curr->bridge->mapped_lock);
	list_del(&curr->mapped_list);
	spin_unlock(&curr->bridge->mapped_lock);
	return 0;
}