Commit 627664de authored by Ben Skeggs's avatar Ben Skeggs Committed by Dave Airlie
Browse files

drm/nouveau: add helper functions for allocating pinned/cpu-mapped bos



Replace some awkward sequences that are repeated in a number of places
with helper functions.

Signed-off-by: default avatarBen Skeggs <bskeggs@nvidia.com>
Reviewed-by: default avatarDave Airlie <airlied@redhat.com>
Reviewed-by: default avatarTimur Tabi <ttabi@nvidia.com>
Tested-by: default avatarTimur Tabi <ttabi@nvidia.com>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent 44f93b20
Loading
Loading
Loading
Loading
+5 −17
Original line number Diff line number Diff line
@@ -768,9 +768,7 @@ static void nv_crtc_destroy(struct drm_crtc *crtc)
		disp->image[nv_crtc->index] = NULL;
	}

	nouveau_bo_unmap(nv_crtc->cursor.nvbo);
	nouveau_bo_unpin(nv_crtc->cursor.nvbo);
	nouveau_bo_fini(nv_crtc->cursor.nvbo);
	nouveau_bo_unpin_del(&nv_crtc->cursor.nvbo);
	nvif_event_dtor(&nv_crtc->vblank);
	nvif_head_dtor(&nv_crtc->head);
	kfree(nv_crtc);
@@ -1303,6 +1301,7 @@ nv04_crtc_vblank_handler(struct nvif_event *event, void *repv, u32 repc)
int
nv04_crtc_create(struct drm_device *dev, int crtc_num)
{
	struct nouveau_cli *cli = &nouveau_drm(dev)->client;
	struct nouveau_display *disp = nouveau_display(dev);
	struct nouveau_crtc *nv_crtc;
	struct drm_plane *primary;
@@ -1336,20 +1335,9 @@ nv04_crtc_create(struct drm_device *dev, int crtc_num)
	drm_crtc_helper_add(&nv_crtc->base, &nv04_crtc_helper_funcs);
	drm_mode_crtc_set_gamma_size(&nv_crtc->base, 256);

	ret = nouveau_bo_new(&nouveau_drm(dev)->client, 64*64*4, 0x100,
			     NOUVEAU_GEM_DOMAIN_VRAM, 0, 0x0000, NULL, NULL,
			     &nv_crtc->cursor.nvbo);
	if (!ret) {
		ret = nouveau_bo_pin(nv_crtc->cursor.nvbo,
				     NOUVEAU_GEM_DOMAIN_VRAM, false);
		if (!ret) {
			ret = nouveau_bo_map(nv_crtc->cursor.nvbo);
	ret = nouveau_bo_new_map(cli, NOUVEAU_GEM_DOMAIN_VRAM, 64 * 64 * 4, &nv_crtc->cursor.nvbo);
	if (ret)
				nouveau_bo_unpin(nv_crtc->cursor.nvbo);
		}
		if (ret)
			nouveau_bo_fini(nv_crtc->cursor.nvbo);
	}
		return ret;

	nv04_cursor_init(nv_crtc);

+2 −18
Original line number Diff line number Diff line
@@ -2808,10 +2808,7 @@ nv50_display_destroy(struct drm_device *dev)
	nvif_object_dtor(&disp->caps);
	nv50_core_del(&disp->core);

	nouveau_bo_unmap(disp->sync);
	if (disp->sync)
		nouveau_bo_unpin(disp->sync);
	nouveau_bo_fini(disp->sync);
	nouveau_bo_unpin_del(&disp->sync);

	nouveau_display(dev)->priv = NULL;
	kfree(disp);
@@ -2843,20 +2840,7 @@ nv50_display_create(struct drm_device *dev)
	dev->mode_config.normalize_zpos = true;

	/* small shared memory area we use for notifiers and semaphores */
	ret = nouveau_bo_new(&drm->client, 4096, 0x1000,
			     NOUVEAU_GEM_DOMAIN_VRAM,
			     0, 0x0000, NULL, NULL, &disp->sync);
	if (!ret) {
		ret = nouveau_bo_pin(disp->sync, NOUVEAU_GEM_DOMAIN_VRAM, true);
		if (!ret) {
			ret = nouveau_bo_map(disp->sync);
			if (ret)
				nouveau_bo_unpin(disp->sync);
		}
		if (ret)
			nouveau_bo_fini(disp->sync);
	}

	ret = nouveau_bo_new_map(&drm->client, NOUVEAU_GEM_DOMAIN_VRAM, PAGE_SIZE, &disp->sync);
	if (ret)
		goto out;

+55 −0
Original line number Diff line number Diff line
@@ -401,6 +401,61 @@ nouveau_bo_new(struct nouveau_cli *cli, u64 size, int align,
	return 0;
}

void
nouveau_bo_unpin_del(struct nouveau_bo **pnvbo)
{
	struct nouveau_bo *nvbo = *pnvbo;

	if (!nvbo)
		return;

	nouveau_bo_unmap(nvbo);
	nouveau_bo_unpin(nvbo);
	nouveau_bo_fini(nvbo);

	*pnvbo = NULL;
}

int
nouveau_bo_new_pin(struct nouveau_cli *cli, u32 domain, u32 size, struct nouveau_bo **pnvbo)
{
	struct nouveau_bo *nvbo;
	int ret;

	ret = nouveau_bo_new(cli, size, 0, domain, 0, 0, NULL, NULL, &nvbo);
	if (ret)
		return ret;

	ret = nouveau_bo_pin(nvbo, domain, false);
	if (ret) {
		nouveau_bo_fini(nvbo);
		return ret;
	}

	*pnvbo = nvbo;
	return 0;
}

int
nouveau_bo_new_map(struct nouveau_cli *cli, u32 domain, u32 size, struct nouveau_bo **pnvbo)
{
	struct nouveau_bo *nvbo;
	int ret;

	ret = nouveau_bo_new_pin(cli, domain, size, &nvbo);
	if (ret)
		return ret;

	ret = nouveau_bo_map(nvbo);
	if (ret) {
		nouveau_bo_unpin_del(&nvbo);
		return ret;
	}

	*pnvbo = nvbo;
	return 0;
}

static void
set_placement_range(struct nouveau_bo *nvbo, uint32_t domain)
{
+5 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ struct nouveau_channel;
struct nouveau_cli;
struct nouveau_drm;
struct nouveau_fence;
struct nouveau_vma;

struct nouveau_bo {
	struct ttm_buffer_object bo;
@@ -89,6 +90,10 @@ void nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo);
void nouveau_bo_add_io_reserve_lru(struct ttm_buffer_object *bo);
void nouveau_bo_del_io_reserve_lru(struct ttm_buffer_object *bo);

int nouveau_bo_new_pin(struct nouveau_cli *, u32 domain, u32 size, struct nouveau_bo **);
int nouveau_bo_new_map(struct nouveau_cli *, u32 domain, u32 size, struct nouveau_bo **);
void nouveau_bo_unpin_del(struct nouveau_bo **);

/* TODO: submit equivalent to TTM generic API upstream? */
static inline void __iomem *
nvbo_kmap_obj_iovirtual(struct nouveau_bo *nvbo)
+2 −12
Original line number Diff line number Diff line
@@ -105,10 +105,7 @@ nouveau_channel_del(struct nouveau_channel **pchan)
		nvif_mem_dtor(&chan->mem_userd);
		nvif_object_dtor(&chan->push.ctxdma);
		nouveau_vma_del(&chan->push.vma);
		nouveau_bo_unmap(chan->push.buffer);
		if (chan->push.buffer && chan->push.buffer->bo.pin_count)
			nouveau_bo_unpin(chan->push.buffer);
		nouveau_bo_fini(chan->push.buffer);
		nouveau_bo_unpin_del(&chan->push.buffer);
		kfree(chan);
	}
	*pchan = NULL;
@@ -163,14 +160,7 @@ nouveau_channel_prep(struct nouveau_cli *cli,
	if (nouveau_vram_pushbuf)
		target = NOUVEAU_GEM_DOMAIN_VRAM;

	ret = nouveau_bo_new(cli, size, 0, target, 0, 0, NULL, NULL,
			    &chan->push.buffer);
	if (ret == 0) {
		ret = nouveau_bo_pin(chan->push.buffer, target, false);
		if (ret == 0)
			ret = nouveau_bo_map(chan->push.buffer);
	}

	ret = nouveau_bo_new_map(cli, target, size, &chan->push.buffer);
	if (ret) {
		nouveau_channel_del(pchan);
		return ret;
Loading