2 * Copyright (C) 2007 Ben Skeggs.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #include "nouveau_drv.h"
33 nouveau_notifier_init_channel(struct nouveau_channel *chan)
35 struct drm_device *dev = chan->dev;
38 flags = (NOUVEAU_MEM_PCI | NOUVEAU_MEM_MAPPED |
39 NOUVEAU_MEM_FB_ACCEPTABLE);
41 chan->notifier_block = nouveau_mem_alloc(dev, 0, PAGE_SIZE, flags,
42 (struct drm_file *)-2);
43 if (!chan->notifier_block)
45 DRM_DEBUG("Allocated notifier block in 0x%08x\n",
46 chan->notifier_block->flags);
48 ret = nouveau_mem_init_heap(&chan->notifier_heap,
49 0, chan->notifier_block->size);
57 nouveau_notifier_takedown_channel(struct nouveau_channel *chan)
59 struct drm_device *dev = chan->dev;
61 if (chan->notifier_block) {
62 nouveau_mem_free(dev, chan->notifier_block);
63 chan->notifier_block = NULL;
66 nouveau_mem_takedown(&chan->notifier_heap);
70 nouveau_notifier_gpuobj_dtor(struct drm_device *dev,
71 struct nouveau_gpuobj *gpuobj)
76 nouveau_mem_free_block(gpuobj->priv);
80 nouveau_notifier_alloc(struct nouveau_channel *chan, uint32_t handle,
81 int count, uint32_t *b_offset)
83 struct drm_device *dev = chan->dev;
84 struct drm_nouveau_private *dev_priv = dev->dev_private;
85 struct nouveau_gpuobj *nobj = NULL;
86 struct mem_block *mem;
90 if (!chan->notifier_heap) {
91 DRM_ERROR("Channel %d doesn't have a notifier heap!\n",
96 mem = nouveau_mem_alloc_block(chan->notifier_heap, count*32, 0,
97 (struct drm_file *)-2, 0);
99 DRM_ERROR("Channel %d notifier block full\n", chan->id);
102 mem->flags = NOUVEAU_MEM_NOTIFIER;
104 offset = chan->notifier_block->start;
105 if (chan->notifier_block->flags & NOUVEAU_MEM_FB) {
106 target = NV_DMA_TARGET_VIDMEM;
108 if (chan->notifier_block->flags & NOUVEAU_MEM_AGP) {
109 if (dev_priv->gart_info.type == NOUVEAU_GART_SGDMA &&
110 dev_priv->card_type < NV_50) {
111 ret = nouveau_sgdma_get_page(dev, offset, &offset);
114 target = NV_DMA_TARGET_PCI;
116 target = NV_DMA_TARGET_AGP;
119 if (chan->notifier_block->flags & NOUVEAU_MEM_PCI) {
120 target = NV_DMA_TARGET_PCI_NONLINEAR;
122 DRM_ERROR("Bad DMA target, flags 0x%08x!\n",
123 chan->notifier_block->flags);
126 offset += mem->start;
128 if ((ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_IN_MEMORY,
130 NV_DMA_ACCESS_RW, target, &nobj))) {
131 nouveau_mem_free_block(mem);
132 DRM_ERROR("Error creating notifier ctxdma: %d\n", ret);
135 nobj->dtor = nouveau_notifier_gpuobj_dtor;
138 if ((ret = nouveau_gpuobj_ref_add(dev, chan, handle, nobj, NULL))) {
139 nouveau_gpuobj_del(dev, &nobj);
140 nouveau_mem_free_block(mem);
141 DRM_ERROR("Error referencing notifier ctxdma: %d\n", ret);
145 *b_offset = mem->start;
150 nouveau_ioctl_notifier_alloc(struct drm_device *dev, void *data,
151 struct drm_file *file_priv)
153 struct drm_nouveau_notifierobj_alloc *na = data;
154 struct nouveau_channel *chan;
157 NOUVEAU_CHECK_INITIALISED_WITH_RETURN;
158 NOUVEAU_GET_USER_CHANNEL_WITH_RETURN(na->channel, file_priv, chan);
160 ret = nouveau_notifier_alloc(chan, na->handle, na->count, &na->offset);