<commit_before>#include <linux/module.h>
#include "gdev_interface.h"
#include "nouveau_drv.h"
#include "nvc0_graph.h"

#define VS_START 0x20000000
#define VS_END (1ull << 40)

extern int nouveau_device_count;
extern struct drm_device **nouveau_drm;
extern void (*nouveau_callback_notify)(int subc, uint32_t data);

int gdev_drv_vspace_alloc(struct drm_device *drm, uint64_t size, struct gdev_drv_vspace *drv_vspace)
{
	struct nouveau_channel *chan;

	if (nouveau_channel_alloc(drm, &chan, NULL, 0xbeef0201, 0xbeef0202)) {
		printk("Failed to allocate nouveau channel\n");
		return -ENOMEM;
	}

	drv_vspace->priv = (void *)chan;
	
	return 0;
}
EXPORT_SYMBOL(gdev_drv_vspace_alloc);

int gdev_drv_vspace_free(struct gdev_drv_vspace *drv_vspace)
{
	struct nouveau_channel *chan = (struct nouveau_channel *)drv_vspace->priv;

	nouveau_channel_put(&chan);
	
	return 0;
}
EXPORT_SYMBOL(gdev_drv_vspace_free);

int gdev_drv_chan_alloc(struct drm_device *drm, struct gdev_drv_vspace *drv_vspace, struct gdev_drv_chan *drv_chan)
{
	struct drm_nouveau_private *dev_priv = drm->dev_private;
	struct nouveau_channel *chan = (struct nouveau_channel *)drv_vspace->priv;
	struct nouveau_bo *ib_bo, *pb_bo;
	uint32_t cid;
	volatile uint32_t *regs;
	uint32_t *ib_map, *pb_map;
	uint32_t ib_order, pb_order;
	uint64_t ib_base, pb_base;
	uint32_t ib_mask, pb_mask;
	uint32_t pb_size;
	int ret;
	
	/* channel ID. */
	cid = chan->id;

	/* FIFO push buffer setup. */
	pb_order = 15; /* it's hardcoded. pscnv uses 20, nouveau uses 15. */
	pb_bo = chan->pushbuf_bo;
	pb_base = chan->pushbuf_vma.offset;
	pb_map = chan->pushbuf_bo->kmap.virtual;
	pb_mask = (1 << pb_order) - 1;
	pb_size = (1 << pb_order);
	if (chan->pushbuf_bo->bo.mem.size / 2 != pb_size)
		printk("Pushbuf size mismatched!\n");

	/* FIFO indirect buffer setup. */
	ib_order = 12; /* it's hardcoded. pscnv uses 9, nouveau uses 12*/
	ib_bo = NULL;
	ib_base = pb_base + pb_size;
	ib_map = (void *)((unsigned long)pb_bo->kmap.virtual + pb_size);
	ib_mask = (1 << ib_order) - 1;

	/* FIFO init: it has already been done in gdev_vas_new(). */

	switch (dev_priv->chipset & 0xf0) {
	case 0xc0:
		/* FIFO command queue registers. */
		regs = chan->user;
		/* PCOPY engines. */
		ret = dev_priv->eng[NVOBJ_ENGINE_COPY0]->context_new(chan, NVOBJ_ENGINE_COPY0);
		if (ret)
			goto fail_pcopy0;
		ret = dev_priv->eng[NVOBJ_ENGINE_COPY1]->context_new(chan, NVOBJ_ENGINE_COPY1);
		if (ret)
			goto fail_pcopy1;
		break;
	default:
		ret = -EINVAL;
		goto fail_fifo_reg;
	}

	drv_chan->priv = chan;
	drv_chan->cid = cid;
	drv_chan->regs = regs;
	drv_chan->ib_bo = ib_bo;
	drv_chan->ib_map = ib_map;
	drv_chan->ib_order = ib_order;
	drv_chan->ib_base = ib_base;
	drv_chan->ib_mask = ib_mask;
	drv_chan->pb_bo = pb_bo;
	drv_chan->pb_map = pb_map;
	drv_chan->pb_order = pb_order;
	drv_chan->pb_base = pb_base;
	drv_chan->pb_mask = pb_mask;
	drv_chan->pb_size = pb_size;

	return 0;

fail_fifo_reg:
fail_pcopy1:
	dev_priv->eng[NVOBJ_ENGINE_COPY0]->context_del(chan, NVOBJ_ENGINE_COPY0);
fail_pcopy0:
	return ret;
}
EXPORT_SYMBOL(gdev_drv_chan_alloc);

int gdev_drv_chan_free(struct gdev_drv_vspace *drv_vspace, struct gdev_drv_chan *drv_chan)
{
	struct nouveau_channel *chan = (struct nouveau_channel *)drv_vspace->priv;
	struct drm_nouveau_private *dev_priv = chan->dev->dev_private;

	dev_priv->eng[NVOBJ_ENGINE_COPY1]->context_del(chan, NVOBJ_ENGINE_COPY1);
	dev_priv->eng[NVOBJ_ENGINE_COPY0]->context_del(chan, NVOBJ_ENGINE_COPY0);

	return 0;
}
EXPORT_SYMBOL(gdev_drv_chan_free);

int gdev_drv_bo_alloc(struct drm_device *drm, uint64_t size, uint32_t drv_flags, struct gdev_drv_vspace *drv_vspace, struct gdev_drv_bo *drv_bo)
{
	struct drm_nouveau_private *dev_priv = drm->dev_private;<commit_msg>fix exit point of fail_fifo_reg in gdev_drv_chan_alloc<commit_after>#include <linux/module.h>
#include "gdev_interface.h"
#include "nouveau_drv.h"
#include "nvc0_graph.h"

#define VS_START 0x20000000
#define VS_END (1ull << 40)

extern int nouveau_device_count;
extern struct drm_device **nouveau_drm;
extern void (*nouveau_callback_notify)(int subc, uint32_t data);

int gdev_drv_vspace_alloc(struct drm_device *drm, uint64_t size, struct gdev_drv_vspace *drv_vspace)
{
	struct nouveau_channel *chan;

	if (nouveau_channel_alloc(drm, &chan, NULL, 0xbeef0201, 0xbeef0202)) {
		printk("Failed to allocate nouveau channel\n");
		return -ENOMEM;
	}

	drv_vspace->priv = (void *)chan;
	
	return 0;
}
EXPORT_SYMBOL(gdev_drv_vspace_alloc);

int gdev_drv_vspace_free(struct gdev_drv_vspace *drv_vspace)
{
	struct nouveau_channel *chan = (struct nouveau_channel *)drv_vspace->priv;

	nouveau_channel_put(&chan);
	
	return 0;
}
EXPORT_SYMBOL(gdev_drv_vspace_free);

int gdev_drv_chan_alloc(struct drm_device *drm, struct gdev_drv_vspace *drv_vspace, struct gdev_drv_chan *drv_chan)
{
	struct drm_nouveau_private *dev_priv = drm->dev_private;
	struct nouveau_channel *chan = (struct nouveau_channel *)drv_vspace->priv;
	struct nouveau_bo *ib_bo, *pb_bo;
	uint32_t cid;
	volatile uint32_t *regs;
	uint32_t *ib_map, *pb_map;
	uint32_t ib_order, pb_order;
	uint64_t ib_base, pb_base;
	uint32_t ib_mask, pb_mask;
	uint32_t pb_size;
	int ret;
	
	/* channel ID. */
	cid = chan->id;

	/* FIFO push buffer setup. */
	pb_order = 15; /* it's hardcoded. pscnv uses 20, nouveau uses 15. */
	pb_bo = chan->pushbuf_bo;
	pb_base = chan->pushbuf_vma.offset;
	pb_map = chan->pushbuf_bo->kmap.virtual;
	pb_mask = (1 << pb_order) - 1;
	pb_size = (1 << pb_order);
	if (chan->pushbuf_bo->bo.mem.size / 2 != pb_size)
		printk("Pushbuf size mismatched!\n");

	/* FIFO indirect buffer setup. */
	ib_order = 12; /* it's hardcoded. pscnv uses 9, nouveau uses 12*/
	ib_bo = NULL;
	ib_base = pb_base + pb_size;
	ib_map = (void *)((unsigned long)pb_bo->kmap.virtual + pb_size);
	ib_mask = (1 << ib_order) - 1;

	/* FIFO init: it has already been done in gdev_vas_new(). */

	switch (dev_priv->chipset & 0xf0) {
	case 0xc0:
		/* FIFO command queue registers. */
		regs = chan->user;
		/* PCOPY engines. */
		ret = dev_priv->eng[NVOBJ_ENGINE_COPY0]->context_new(chan, NVOBJ_ENGINE_COPY0);
		if (ret)
			goto fail_pcopy0;
		ret = dev_priv->eng[NVOBJ_ENGINE_COPY1]->context_new(chan, NVOBJ_ENGINE_COPY1);
		if (ret)
			goto fail_pcopy1;
		break;
	default:
		ret = -EINVAL;
		goto fail_fifo_reg;
	}

	drv_chan->priv = chan;
	drv_chan->cid = cid;
	drv_chan->regs = regs;
	drv_chan->ib_bo = ib_bo;
	drv_chan->ib_map = ib_map;
	drv_chan->ib_order = ib_order;
	drv_chan->ib_base = ib_base;
	drv_chan->ib_mask = ib_mask;
	drv_chan->pb_bo = pb_bo;
	drv_chan->pb_map = pb_map;
	drv_chan->pb_order = pb_order;
	drv_chan->pb_base = pb_base;
	drv_chan->pb_mask = pb_mask;
	drv_chan->pb_size = pb_size;

	return 0;

fail_pcopy1:
	dev_priv->eng[NVOBJ_ENGINE_COPY0]->context_del(chan, NVOBJ_ENGINE_COPY0);
fail_fifo_reg:
fail_pcopy0:
	return ret;
}
EXPORT_SYMBOL(gdev_drv_chan_alloc);

int gdev_drv_chan_free(struct gdev_drv_vspace *drv_vspace, struct gdev_drv_chan *drv_chan)
{
	struct nouveau_channel *chan = (struct nouveau_channel *)drv_vspace->priv;
	struct drm_nouveau_private *dev_priv = chan->dev->dev_private;

	dev_priv->eng[NVOBJ_ENGINE_COPY1]->context_del(chan, NVOBJ_ENGINE_COPY1);
	dev_priv->eng[NVOBJ_ENGINE_COPY0]->context_del(chan, NVOBJ_ENGINE_COPY0);

	return 0;
}
EXPORT_SYMBOL(gdev_drv_chan_free);

int gdev_drv_bo_alloc(struct drm_device *drm, uint64_t size, uint32_t drv_flags, struct gdev_drv_vspace *drv_vspace, struct gdev_drv_bo *drv_bo)
{
	struct drm_nouveau_private *dev_priv = drm->dev_private;
{'fraction_non_alphanumeric': 0.11957827305485119, 'fraction_numerical': 0.0224209261977846, 'mean_word_length': 5.367034834324554, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6958237', 'n_tokens_mistral': 3319, 'n_tokens_neox': 3099, 'n_words': 617}