OSDN Git Service

mach64: fix after vblank-rework
[android-x86/external-libdrm.git] / shared-core / via_drv.c
1 /*
2  * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3  * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sub license,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19  * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24
25 #include "drmP.h"
26 #include "via_drm.h"
27 #include "via_drv.h"
28
29 #include "drm_pciids.h"
30
31
32 static int dri_library_name(struct drm_device * dev, char * buf)
33 {
34         return snprintf(buf, PAGE_SIZE, "unichrome\n");
35 }
36
37 static struct pci_device_id pciidlist[] = {
38         viadrv_PCI_IDS
39 };
40
41
42 #ifdef VIA_HAVE_FENCE
43 static struct drm_fence_driver via_fence_driver = {
44         .num_classes = 1,
45         .wrap_diff = (1 << 30),
46         .flush_diff = (1 << 20),
47         .sequence_mask = 0xffffffffU,
48         .lazy_capable = 1,
49         .emit = via_fence_emit_sequence,
50         .poke_flush = via_poke_flush,
51         .has_irq = via_fence_has_irq,
52 };
53 #endif
54 #ifdef VIA_HAVE_BUFFER
55
56 /**
57  * If there's no thrashing. This is the preferred memory type order.
58  */
59 static uint32_t via_mem_prios[] = {DRM_BO_MEM_PRIV0, DRM_BO_MEM_VRAM, DRM_BO_MEM_TT, DRM_BO_MEM_LOCAL};
60
61 /**
62  * If we have thrashing, most memory will be evicted to TT anyway, so we might as well
63  * just move the new buffer into TT from the start.
64  */
65 static uint32_t via_busy_prios[] = {DRM_BO_MEM_TT, DRM_BO_MEM_PRIV0, DRM_BO_MEM_VRAM, DRM_BO_MEM_LOCAL};
66
67
68 static struct drm_bo_driver via_bo_driver = {
69         .mem_type_prio = via_mem_prios,
70         .mem_busy_prio = via_busy_prios,
71         .num_mem_type_prio = ARRAY_SIZE(via_mem_prios),
72         .num_mem_busy_prio = ARRAY_SIZE(via_busy_prios),
73         .create_ttm_backend_entry = via_create_ttm_backend_entry,
74         .fence_type = via_fence_types,
75         .invalidate_caches = via_invalidate_caches,
76         .init_mem_type = via_init_mem_type,
77         .evict_flags = via_evict_flags,
78         .move = NULL,
79 };
80 #endif
81
82 static int probe(struct pci_dev *pdev, const struct pci_device_id *ent);
83 static struct drm_driver driver = {
84         .driver_features =
85             DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_IRQ |
86             DRIVER_IRQ_SHARED,
87         .load = via_driver_load,
88         .unload = via_driver_unload,
89 #ifndef VIA_HAVE_CORE_MM
90         .context_ctor = via_init_context,
91 #endif
92         .context_dtor = via_final_context,
93         .get_vblank_counter = via_get_vblank_counter,
94         .enable_vblank = via_enable_vblank,
95         .disable_vblank = via_disable_vblank,
96         .irq_preinstall = via_driver_irq_preinstall,
97         .irq_postinstall = via_driver_irq_postinstall,
98         .irq_uninstall = via_driver_irq_uninstall,
99         .irq_handler = via_driver_irq_handler,
100         .dma_quiescent = via_driver_dma_quiescent,
101         .dri_library_name = dri_library_name,
102         .reclaim_buffers = drm_core_reclaim_buffers,
103         .reclaim_buffers_locked = NULL,
104 #ifdef VIA_HAVE_CORE_MM
105         .reclaim_buffers_idlelocked = via_reclaim_buffers_locked,
106         .lastclose = via_lastclose,
107 #endif
108         .get_map_ofs = drm_core_get_map_ofs,
109         .get_reg_ofs = drm_core_get_reg_ofs,
110         .ioctls = via_ioctls,
111         .fops = {
112                 .owner = THIS_MODULE,
113                 .open = drm_open,
114                 .release = drm_release,
115                 .ioctl = drm_ioctl,
116                 .mmap = drm_mmap,
117                 .poll = drm_poll,
118                 .fasync = drm_fasync,
119                 },
120         .pci_driver = {
121                 .name = DRIVER_NAME,
122                 .id_table = pciidlist,
123                 .probe = probe,
124                 .remove = __devexit_p(drm_cleanup_pci),
125         },
126 #ifdef VIA_HAVE_FENCE
127         .fence_driver = &via_fence_driver,
128 #endif
129 #ifdef VIA_HAVE_BUFFER
130         .bo_driver = &via_bo_driver,
131 #endif
132         .name = DRIVER_NAME,
133         .desc = DRIVER_DESC,
134         .date = VIA_DRM_DRIVER_DATE,
135         .major = VIA_DRM_DRIVER_MAJOR,
136         .minor = VIA_DRM_DRIVER_MINOR,
137         .patchlevel = VIA_DRM_DRIVER_PATCHLEVEL
138 };
139
140 static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)
141 {
142         return drm_get_dev(pdev, ent, &driver);
143 }
144
145 static int __init via_init(void)
146 {
147         driver.num_ioctls = via_max_ioctl;
148
149         via_init_command_verifier();
150         return drm_init(&driver, pciidlist);
151 }
152
153 static void __exit via_exit(void)
154 {
155         drm_exit(&driver);
156 }
157
158 module_init(via_init);
159 module_exit(via_exit);
160
161 MODULE_AUTHOR(DRIVER_AUTHOR);
162 MODULE_DESCRIPTION(DRIVER_DESC);
163 MODULE_LICENSE("GPL and additional rights");