/*
* AGPGART driver frontend
+ * Copyright (C) 2004 Silicon Graphics, Inc.
* Copyright (C) 2002-2003 Dave Jones
* Copyright (C) 1999 Jeff Hartmann
* Copyright (C) 1999 Precision Insight, Inc.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * JEFF HARTMANN, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * JEFF HARTMANN, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
client->segments = seg;
}
-/* Originally taken from linux/mm/mmap.c from the array
- * protection_map.
- * The original really should be exported to modules, or
- * some routine which does the conversion for you
- */
-
-static const pgprot_t my_protect_map[16] =
-{
- __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
- __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
-};
-
static pgprot_t agp_convert_mmap_flags(int prot)
{
-#define _trans(x,bit1,bit2) \
-((bit1==bit2)?(x&bit1):(x&bit1)?bit2:0)
-
unsigned long prot_bits;
- pgprot_t temp;
-
- prot_bits = _trans(prot, PROT_READ, VM_READ) |
- _trans(prot, PROT_WRITE, VM_WRITE) |
- _trans(prot, PROT_EXEC, VM_EXEC);
- prot_bits |= VM_SHARED;
-
- temp = my_protect_map[prot_bits & 0x0000000f];
-
- return temp;
+ prot_bits = calc_vm_prot_bits(prot) | VM_SHARED;
+ return vm_get_page_prot(prot_bits);
}
static int agp_create_segment(struct agp_client *client, struct agp_region *region)
struct agp_segment *user_seg;
size_t i;
- seg = kmalloc((sizeof(struct agp_segment_priv) * region->seg_count), GFP_KERNEL);
+ seg = kzalloc((sizeof(struct agp_segment_priv) * region->seg_count), GFP_KERNEL);
if (seg == NULL) {
kfree(region->seg_list);
region->seg_list = NULL;
return -ENOMEM;
}
- memset(seg, 0, (sizeof(struct agp_segment_priv) * region->seg_count));
user_seg = region->seg_list;
for (i = 0; i < region->seg_count; i++) {
/* File private list routines */
-struct agp_file_private *agp_find_private(pid_t pid)
+static struct agp_file_private *agp_find_private(pid_t pid)
{
struct agp_file_private *curr;
return NULL;
}
-void agp_insert_file_private(struct agp_file_private * priv)
+static void agp_insert_file_private(struct agp_file_private * priv)
{
struct agp_file_private *prev;
agp_fe.file_priv_list = priv;
}
-void agp_remove_file_private(struct agp_file_private * priv)
+static void agp_remove_file_private(struct agp_file_private * priv)
{
struct agp_file_private *next;
struct agp_file_private *prev;
/* End - File flag list routines */
-/*
- * Wrappers for agp_free_memory & agp_allocate_memory
+/*
+ * Wrappers for agp_free_memory & agp_allocate_memory
* These make sure that internal lists are kept updated.
*/
static void agp_free_memory_wrap(struct agp_memory *memory)
{
struct agp_memory *memory;
- memory = agp_allocate_memory(pg_count, type);
+ memory = agp_allocate_memory(agp_bridge, pg_count, type);
if (memory == NULL)
return NULL;
{
struct agp_controller *controller;
- controller = kmalloc(sizeof(struct agp_controller), GFP_KERNEL);
-
+ controller = kzalloc(sizeof(struct agp_controller), GFP_KERNEL);
if (controller == NULL)
return NULL;
- memset(controller, 0, sizeof(struct agp_controller));
controller->pid = id;
-
return controller;
}
if (agp_fe.current_controller == controller) {
agp_fe.current_controller = NULL;
agp_fe.backend_acquired = FALSE;
- agp_backend_release();
+ agp_backend_release(agp_bridge);
}
kfree(controller);
return 0;
agp_fe.current_controller = NULL;
agp_fe.used_by_controller = FALSE;
- agp_backend_release();
+ agp_backend_release(agp_bridge);
}
-/*
+/*
* Routines for managing client lists -
* These routines are for managing the list of auth'ed clients.
*/
{
struct agp_client *new_client;
- new_client = kmalloc(sizeof(struct agp_client), GFP_KERNEL);
-
+ new_client = kzalloc(sizeof(struct agp_client), GFP_KERNEL);
if (new_client == NULL)
return NULL;
- memset(new_client, 0, sizeof(struct agp_client));
new_client->pid = id;
agp_insert_client(new_client);
return new_client;
struct agp_file_private *priv = file->private_data;
struct agp_kern_info kerninfo;
- down(&(agp_fe.agp_mutex));
+ mutex_lock(&(agp_fe.agp_mutex));
if (agp_fe.backend_acquired != TRUE)
goto out_eperm;
if (!(test_bit(AGP_FF_IS_VALID, &priv->access_flags)))
goto out_eperm;
- agp_copy_info(&kerninfo);
+ agp_copy_info(agp_bridge, &kerninfo);
size = vma->vm_end - vma->vm_start;
current_size = kerninfo.aper_size;
current_size = current_size * 0x100000;
DBG("client vm_ops=%p", kerninfo.vm_ops);
if (kerninfo.vm_ops) {
vma->vm_ops = kerninfo.vm_ops;
- } else if (remap_page_range(vma, vma->vm_start,
- (kerninfo.aper_base + offset),
+ } else if (io_remap_pfn_range(vma, vma->vm_start,
+ (kerninfo.aper_base + offset) >> PAGE_SHIFT,
size, vma->vm_page_prot)) {
goto out_again;
}
- up(&(agp_fe.agp_mutex));
+ mutex_unlock(&(agp_fe.agp_mutex));
return 0;
}
DBG("controller vm_ops=%p", kerninfo.vm_ops);
if (kerninfo.vm_ops) {
vma->vm_ops = kerninfo.vm_ops;
- } else if (remap_page_range(vma, vma->vm_start,
- kerninfo.aper_base,
+ } else if (io_remap_pfn_range(vma, vma->vm_start,
+ kerninfo.aper_base >> PAGE_SHIFT,
size, vma->vm_page_prot)) {
goto out_again;
}
- up(&(agp_fe.agp_mutex));
+ mutex_unlock(&(agp_fe.agp_mutex));
return 0;
}
out_eperm:
- up(&(agp_fe.agp_mutex));
+ mutex_unlock(&(agp_fe.agp_mutex));
return -EPERM;
out_inval:
- up(&(agp_fe.agp_mutex));
+ mutex_unlock(&(agp_fe.agp_mutex));
return -EINVAL;
out_again:
- up(&(agp_fe.agp_mutex));
+ mutex_unlock(&(agp_fe.agp_mutex));
return -EAGAIN;
}
{
struct agp_file_private *priv = file->private_data;
- down(&(agp_fe.agp_mutex));
+ mutex_lock(&(agp_fe.agp_mutex));
DBG("priv=%p", priv);
agp_remove_file_private(priv);
kfree(priv);
file->private_data = NULL;
- up(&(agp_fe.agp_mutex));
+ mutex_unlock(&(agp_fe.agp_mutex));
return 0;
}
struct agp_client *client;
int rc = -ENXIO;
- down(&(agp_fe.agp_mutex));
+ mutex_lock(&(agp_fe.agp_mutex));
if (minor != AGPGART_MINOR)
goto err_out;
- priv = kmalloc(sizeof(struct agp_file_private), GFP_KERNEL);
+ priv = kzalloc(sizeof(struct agp_file_private), GFP_KERNEL);
if (priv == NULL)
goto err_out_nomem;
- memset(priv, 0, sizeof(struct agp_file_private));
set_bit(AGP_FF_ALLOW_CLIENT, &priv->access_flags);
priv->my_pid = current->pid;
file->private_data = (void *) priv;
agp_insert_file_private(priv);
DBG("private=%p, client=%p", priv, client);
- up(&(agp_fe.agp_mutex));
+ mutex_unlock(&(agp_fe.agp_mutex));
return 0;
err_out_nomem:
rc = -ENOMEM;
err_out:
- up(&(agp_fe.agp_mutex));
+ mutex_unlock(&(agp_fe.agp_mutex));
return rc;
}
struct agp_info userinfo;
struct agp_kern_info kerninfo;
- agp_copy_info(&kerninfo);
+ agp_copy_info(agp_bridge, &kerninfo);
userinfo.version.major = kerninfo.version.major;
userinfo.version.minor = kerninfo.version.minor;
static int agpioc_acquire_wrap(struct agp_file_private *priv)
{
- int ret;
struct agp_controller *controller;
DBG("");
if (agp_fe.current_controller != NULL)
return -EBUSY;
- ret = agp_backend_acquire();
- if (ret == 0)
- agp_fe.backend_acquired = TRUE;
- else
- return ret;
+ if (!agp_bridge)
+ return -ENODEV;
+
+ if (atomic_read(&agp_bridge->agp_in_use))
+ return -EBUSY;
+
+ atomic_inc(&agp_bridge->agp_in_use);
+
+ agp_fe.backend_acquired = TRUE;
controller = agp_find_controller_by_pid(priv->my_pid);
if (controller == NULL) {
agp_fe.backend_acquired = FALSE;
- agp_backend_release();
+ agp_backend_release(agp_bridge);
return -ENOMEM;
}
agp_insert_controller(controller);
if (copy_from_user(&mode, arg, sizeof(struct agp_setup)))
return -EFAULT;
- agp_enable(mode.agp_mode);
+ agp_enable(agp_bridge, mode.agp_mode);
return 0;
}
int ret_val = -ENOTTY;
DBG("priv=%p, cmd=%x", curr_priv, cmd);
- down(&(agp_fe.agp_mutex));
+ mutex_lock(&(agp_fe.agp_mutex));
if ((agp_fe.current_controller == NULL) &&
(cmd != AGPIOC_ACQUIRE)) {
ret_val = -EINVAL;
- goto ioctl_out;
+ goto ioctl_out;
}
if ((agp_fe.backend_acquired != TRUE) &&
(cmd != AGPIOC_ACQUIRE)) {
ret_val = -EBUSY;
- goto ioctl_out;
+ goto ioctl_out;
}
if (cmd != AGPIOC_ACQUIRE) {
if (!(test_bit(AGP_FF_IS_CONTROLLER, &curr_priv->access_flags))) {
ret_val = -EPERM;
- goto ioctl_out;
+ goto ioctl_out;
}
/* Use the original pid of the controller,
* in case it's threaded */
if (agp_fe.current_controller->pid != curr_priv->my_pid) {
ret_val = -EBUSY;
- goto ioctl_out;
+ goto ioctl_out;
}
}
case AGPIOC_ACQUIRE:
ret_val = agpioc_acquire_wrap(curr_priv);
break;
-
+
case AGPIOC_RELEASE:
ret_val = agpioc_release_wrap(curr_priv);
break;
-
+
case AGPIOC_SETUP:
ret_val = agpioc_setup_wrap(curr_priv, (void __user *) arg);
break;
-
+
case AGPIOC_RESERVE:
ret_val = agpioc_reserve_wrap(curr_priv, (void __user *) arg);
break;
-
+
case AGPIOC_PROTECT:
ret_val = agpioc_protect_wrap(curr_priv);
break;
-
+
case AGPIOC_ALLOCATE:
ret_val = agpioc_allocate_wrap(curr_priv, (void __user *) arg);
break;
-
+
case AGPIOC_DEALLOCATE:
ret_val = agpioc_deallocate_wrap(curr_priv, (int) arg);
break;
-
+
case AGPIOC_BIND:
ret_val = agpioc_bind_wrap(curr_priv, (void __user *) arg);
break;
-
+
case AGPIOC_UNBIND:
ret_val = agpioc_unbind_wrap(curr_priv, (void __user *) arg);
break;
ioctl_out:
DBG("ioctl returns %d\n", ret_val);
- up(&(agp_fe.agp_mutex));
+ mutex_unlock(&(agp_fe.agp_mutex));
return ret_val;
}
-static struct file_operations agp_fops =
+static const struct file_operations agp_fops =
{
.owner = THIS_MODULE,
.llseek = no_llseek,
int agp_frontend_initialize(void)
{
memset(&agp_fe, 0, sizeof(struct agp_front_data));
- sema_init(&(agp_fe.agp_mutex), 1);
+ mutex_init(&(agp_fe.agp_mutex));
if (misc_register(&agp_miscdev)) {
printk(KERN_ERR PFX "unable to get minor: %d\n", AGPGART_MINOR);