2007-06-24 03:03:35 -06:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Ben Skeggs.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* 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 THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "drmP.h"
|
|
|
|
#include "drm.h"
|
|
|
|
#include "nouveau_drv.h"
|
|
|
|
|
|
|
|
int
|
2007-08-05 11:40:43 -06:00
|
|
|
nouveau_notifier_init_channel(struct nouveau_channel *chan)
|
2007-06-24 03:03:35 -06:00
|
|
|
{
|
2007-08-05 11:40:43 -06:00
|
|
|
struct drm_device *dev = chan->dev;
|
2007-07-12 23:09:31 -06:00
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
2007-06-24 03:03:35 -06:00
|
|
|
int flags, ret;
|
|
|
|
|
|
|
|
/*TODO: PCI notifier blocks */
|
2007-07-15 01:18:15 -06:00
|
|
|
if (dev_priv->agp_heap &&
|
|
|
|
dev_priv->gart_info.type != NOUVEAU_GART_SGDMA)
|
2007-06-24 03:03:35 -06:00
|
|
|
flags = NOUVEAU_MEM_AGP | NOUVEAU_MEM_FB_ACCEPTABLE;
|
2007-07-27 07:48:04 -06:00
|
|
|
else if ( dev_priv->pci_heap )
|
|
|
|
flags = NOUVEAU_MEM_PCI;
|
2007-06-24 03:03:35 -06:00
|
|
|
else
|
|
|
|
flags = NOUVEAU_MEM_FB;
|
2007-07-09 07:58:00 -06:00
|
|
|
flags |= NOUVEAU_MEM_MAPPED;
|
2007-06-24 03:03:35 -06:00
|
|
|
|
2007-08-05 11:40:43 -06:00
|
|
|
DRM_DEBUG("Allocating notifier block in %d\n", flags);
|
2007-07-20 07:39:25 -06:00
|
|
|
chan->notifier_block = nouveau_mem_alloc(dev, 0, PAGE_SIZE, flags,
|
2007-08-05 11:40:43 -06:00
|
|
|
(struct drm_file *)-2);
|
2007-06-24 03:03:35 -06:00
|
|
|
if (!chan->notifier_block)
|
2007-07-19 18:00:17 -06:00
|
|
|
return -ENOMEM;
|
2007-06-24 03:03:35 -06:00
|
|
|
|
|
|
|
ret = nouveau_mem_init_heap(&chan->notifier_heap,
|
|
|
|
0, chan->notifier_block->size);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-08-05 11:40:43 -06:00
|
|
|
nouveau_notifier_takedown_channel(struct nouveau_channel *chan)
|
2007-06-24 03:03:35 -06:00
|
|
|
{
|
2007-08-05 11:40:43 -06:00
|
|
|
struct drm_device *dev = chan->dev;
|
2007-06-24 03:03:35 -06:00
|
|
|
|
|
|
|
if (chan->notifier_block) {
|
|
|
|
nouveau_mem_free(dev, chan->notifier_block);
|
|
|
|
chan->notifier_block = NULL;
|
|
|
|
}
|
|
|
|
|
2007-08-05 11:40:43 -06:00
|
|
|
nouveau_mem_takedown(&chan->notifier_heap);
|
2007-06-24 03:03:35 -06:00
|
|
|
}
|
|
|
|
|
2007-08-06 05:45:18 -06:00
|
|
|
static void
|
|
|
|
nouveau_notifier_gpuobj_dtor(struct drm_device *dev,
|
|
|
|
struct nouveau_gpuobj *gpuobj)
|
|
|
|
{
|
|
|
|
DRM_DEBUG("\n");
|
|
|
|
|
|
|
|
if (gpuobj->priv)
|
|
|
|
nouveau_mem_free_block(gpuobj->priv);
|
|
|
|
}
|
|
|
|
|
2007-06-24 03:03:35 -06:00
|
|
|
int
|
2007-08-05 11:40:43 -06:00
|
|
|
nouveau_notifier_alloc(struct nouveau_channel *chan, uint32_t handle,
|
2007-06-24 03:03:35 -06:00
|
|
|
int count, uint32_t *b_offset)
|
|
|
|
{
|
2007-08-05 11:40:43 -06:00
|
|
|
struct drm_device *dev = chan->dev;
|
2007-07-12 23:09:31 -06:00
|
|
|
struct nouveau_gpuobj *nobj = NULL;
|
2007-06-24 03:03:35 -06:00
|
|
|
struct mem_block *mem;
|
|
|
|
uint32_t offset;
|
2007-07-02 03:31:18 -06:00
|
|
|
int target, ret;
|
2007-06-24 03:03:35 -06:00
|
|
|
|
|
|
|
if (!chan->notifier_heap) {
|
|
|
|
DRM_ERROR("Channel %d doesn't have a notifier heap!\n",
|
2007-08-05 11:40:43 -06:00
|
|
|
chan->id);
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EINVAL;
|
2007-06-24 03:03:35 -06:00
|
|
|
}
|
|
|
|
|
2007-07-20 07:39:25 -06:00
|
|
|
mem = nouveau_mem_alloc_block(chan->notifier_heap, 32, 0,
|
2007-08-06 05:45:18 -06:00
|
|
|
(struct drm_file *)-2);
|
2007-06-24 03:03:35 -06:00
|
|
|
if (!mem) {
|
2007-08-05 11:40:43 -06:00
|
|
|
DRM_ERROR("Channel %d notifier block full\n", chan->id);
|
2007-07-19 18:00:17 -06:00
|
|
|
return -ENOMEM;
|
2007-06-24 03:03:35 -06:00
|
|
|
}
|
|
|
|
mem->flags = NOUVEAU_MEM_NOTIFIER;
|
|
|
|
|
|
|
|
offset = chan->notifier_block->start + mem->start;
|
|
|
|
if (chan->notifier_block->flags & NOUVEAU_MEM_FB) {
|
|
|
|
target = NV_DMA_TARGET_VIDMEM;
|
|
|
|
} else if (chan->notifier_block->flags & NOUVEAU_MEM_AGP) {
|
|
|
|
target = NV_DMA_TARGET_AGP;
|
2007-07-27 07:48:04 -06:00
|
|
|
} else if (chan->notifier_block->flags & NOUVEAU_MEM_PCI) {
|
|
|
|
target = NV_DMA_TARGET_PCI_NONLINEAR;
|
2007-06-24 03:03:35 -06:00
|
|
|
} else {
|
|
|
|
DRM_ERROR("Bad DMA target, flags 0x%08x!\n",
|
|
|
|
chan->notifier_block->flags);
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EINVAL;
|
2007-06-24 03:03:35 -06:00
|
|
|
}
|
|
|
|
|
2007-08-05 11:40:43 -06:00
|
|
|
if ((ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_IN_MEMORY,
|
2007-07-02 03:31:18 -06:00
|
|
|
offset, mem->size,
|
|
|
|
NV_DMA_ACCESS_RW, target, &nobj))) {
|
2007-06-24 03:03:35 -06:00
|
|
|
nouveau_mem_free_block(mem);
|
2007-07-02 03:31:18 -06:00
|
|
|
DRM_ERROR("Error creating notifier ctxdma: %d\n", ret);
|
|
|
|
return ret;
|
2007-06-24 03:03:35 -06:00
|
|
|
}
|
2007-08-06 05:45:18 -06:00
|
|
|
nobj->dtor = nouveau_notifier_gpuobj_dtor;
|
|
|
|
nobj->priv = mem;
|
2007-06-24 03:03:35 -06:00
|
|
|
|
2007-08-05 11:40:43 -06:00
|
|
|
if ((ret = nouveau_gpuobj_ref_add(dev, chan, handle, nobj, NULL))) {
|
2007-07-02 03:31:18 -06:00
|
|
|
nouveau_gpuobj_del(dev, &nobj);
|
2007-06-24 03:03:35 -06:00
|
|
|
nouveau_mem_free_block(mem);
|
2007-07-02 03:31:18 -06:00
|
|
|
DRM_ERROR("Error referencing notifier ctxdma: %d\n", ret);
|
|
|
|
return ret;
|
2007-06-24 03:03:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
*b_offset = mem->start;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-08-05 11:40:43 -06:00
|
|
|
nouveau_ioctl_notifier_alloc(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2007-06-24 03:03:35 -06:00
|
|
|
{
|
2007-08-06 05:45:18 -06:00
|
|
|
struct drm_nouveau_notifierobj_alloc *na = data;
|
2007-08-05 11:40:43 -06:00
|
|
|
struct nouveau_channel *chan;
|
2007-06-24 03:03:35 -06:00
|
|
|
int ret;
|
|
|
|
|
2007-08-06 05:45:18 -06:00
|
|
|
NOUVEAU_CHECK_INITIALISED_WITH_RETURN;
|
2007-08-05 11:40:43 -06:00
|
|
|
NOUVEAU_GET_USER_CHANNEL_WITH_RETURN(na->channel, file_priv, chan);
|
2007-06-24 03:03:35 -06:00
|
|
|
|
2007-08-05 11:40:43 -06:00
|
|
|
ret = nouveau_notifier_alloc(chan, na->handle, na->count, &na->offset);
|
2007-06-24 03:03:35 -06:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|