OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [char/] [drm/] [drm_stub.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/* drm_stub.h -- -*- linux-c -*-
2
 * Created: Fri Jan 19 10:48:35 2001 by faith@acm.org
3
 *
4
 * Copyright 2001 VA Linux Systems, Inc., Sunnyvale, California.
5
 * All Rights Reserved.
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a
8
 * copy of this software and associated documentation files (the "Software"),
9
 * to deal in the Software without restriction, including without limitation
10
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
 * and/or sell copies of the Software, and to permit persons to whom the
12
 * Software is furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice (including the next
15
 * paragraph) shall be included in all copies or substantial portions of the
16
 * Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21
 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
 * DEALINGS IN THE SOFTWARE.
25
 *
26
 * Authors:
27
 *    Rickard E. (Rik) Faith <faith@valinux.com>
28
 *
29
 */
30
 
31
#include "drmP.h"
32
 
33
#define DRM_STUB_MAXCARDS 16    /* Enough for one machine */
34
 
35
static struct drm_stub_list {
36
        const char             *name;
37
        struct file_operations *fops;
38
        struct proc_dir_entry  *dev_root;
39
} *DRM(stub_list);
40
 
41
static struct proc_dir_entry *DRM(stub_root);
42
 
43
static struct drm_stub_info {
44
        int (*info_register)(const char *name, struct file_operations *fops,
45
                             drm_device_t *dev);
46
        int (*info_unregister)(int minor);
47
} DRM(stub_info);
48
 
49
static int DRM(stub_open)(struct inode *inode, struct file *filp)
50
{
51
        int                    minor = minor(inode->i_rdev);
52
        int                    err   = -ENODEV;
53
        struct file_operations *old_fops;
54
 
55
        if (!DRM(stub_list) || !DRM(stub_list)[minor].fops) return -ENODEV;
56
        old_fops   = filp->f_op;
57
        filp->f_op = fops_get(DRM(stub_list)[minor].fops);
58
        if (filp->f_op->open && (err = filp->f_op->open(inode, filp))) {
59
                fops_put(filp->f_op);
60
                filp->f_op = fops_get(old_fops);
61
        }
62
        fops_put(old_fops);
63
 
64
        return err;
65
}
66
 
67
static struct file_operations DRM(stub_fops) = {
68
        .owner = THIS_MODULE,
69
        .open  = DRM(stub_open)
70
};
71
 
72
static int DRM(stub_getminor)(const char *name, struct file_operations *fops,
73
                              drm_device_t *dev)
74
{
75
        int i;
76
 
77
        if (!DRM(stub_list)) {
78
                DRM(stub_list) = DRM(alloc)(sizeof(*DRM(stub_list))
79
                                            * DRM_STUB_MAXCARDS, DRM_MEM_STUB);
80
                if(!DRM(stub_list)) return -1;
81
                for (i = 0; i < DRM_STUB_MAXCARDS; i++) {
82
                        DRM(stub_list)[i].name = NULL;
83
                        DRM(stub_list)[i].fops = NULL;
84
                }
85
        }
86
        for (i = 0; i < DRM_STUB_MAXCARDS; i++) {
87
                if (!DRM(stub_list)[i].fops) {
88
                        DRM(stub_list)[i].name = name;
89
                        DRM(stub_list)[i].fops = fops;
90
                        DRM(stub_root) = DRM(proc_init)(dev, i, DRM(stub_root),
91
                                                        &DRM(stub_list)[i]
92
                                                        .dev_root);
93
                        return i;
94
                }
95
        }
96
        return -1;
97
}
98
 
99
static int DRM(stub_putminor)(int minor)
100
{
101
        if (minor < 0 || minor >= DRM_STUB_MAXCARDS) return -1;
102
        DRM(stub_list)[minor].name = NULL;
103
        DRM(stub_list)[minor].fops = NULL;
104
        DRM(proc_cleanup)(minor, DRM(stub_root),
105
                          DRM(stub_list)[minor].dev_root);
106
        if (minor) {
107
                inter_module_put("drm");
108
        } else {
109
                inter_module_unregister("drm");
110
                DRM(free)(DRM(stub_list),
111
                          sizeof(*DRM(stub_list)) * DRM_STUB_MAXCARDS,
112
                          DRM_MEM_STUB);
113
                unregister_chrdev(DRM_MAJOR, "drm");
114
        }
115
        return 0;
116
}
117
 
118
 
119
int DRM(stub_register)(const char *name, struct file_operations *fops,
120
                       drm_device_t *dev)
121
{
122
        struct drm_stub_info *i = NULL;
123
 
124
        DRM_DEBUG("\n");
125
        if (register_chrdev(DRM_MAJOR, "drm", &DRM(stub_fops)))
126
                i = (struct drm_stub_info *)inter_module_get("drm");
127
 
128
        if (i) {
129
                                /* Already registered */
130
                DRM(stub_info).info_register   = i->info_register;
131
                DRM(stub_info).info_unregister = i->info_unregister;
132
                DRM_DEBUG("already registered\n");
133
        } else if (DRM(stub_info).info_register != DRM(stub_getminor)) {
134
                DRM(stub_info).info_register   = DRM(stub_getminor);
135
                DRM(stub_info).info_unregister = DRM(stub_putminor);
136
                DRM_DEBUG("calling inter_module_register\n");
137
                inter_module_register("drm", THIS_MODULE, &DRM(stub_info));
138
        }
139
        if (DRM(stub_info).info_register)
140
                return DRM(stub_info).info_register(name, fops, dev);
141
        return -1;
142
}
143
 
144
int DRM(stub_unregister)(int minor)
145
{
146
        DRM_DEBUG("%d\n", minor);
147
        if (DRM(stub_info).info_unregister)
148
                return DRM(stub_info).info_unregister(minor);
149
        return -1;
150
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.