···153153#define NVOBJ_ENGINE_CRYPT 2154154#define NVOBJ_ENGINE_COPY0 3155155#define NVOBJ_ENGINE_COPY1 4156156+#define NVOBJ_ENGINE_MPEG 5156157#define NVOBJ_ENGINE_DISPLAY 15157158#define NVOBJ_ENGINE_NR 16158159···1154115311551154/* nvc0_copy.c */11561155extern int nvc0_copy_create(struct drm_device *dev, int engine);11561156+11571157+/* nv40_mpeg.c */11581158+extern int nv40_mpeg_create(struct drm_device *dev);1157115911581160/* nv04_instmem.c */11591161extern int nv04_instmem_init(struct drm_device *);
+3
drivers/gpu/drm/nouveau/nouveau_state.c
···617617 break;618618 }619619620620+ if (dev_priv->card_type == NV_40)621621+ nv40_mpeg_create(dev);622622+620623 if (!nouveau_noaccel) {621624 for (e = 0; e < NVOBJ_ENGINE_NR; e++) {622625 if (dev_priv->eng[e]) {
+2
drivers/gpu/drm/nouveau/nv40_fifo.c
···115115 nv_wr32(dev, 0x32e8, nv_ri32(dev, fc + 68));116116 nv_wr32(dev, 0x2088, nv_ri32(dev, fc + 76));117117 nv_wr32(dev, 0x3300, nv_ri32(dev, fc + 80));118118+ nv_wr32(dev, 0x330c, nv_ri32(dev, fc + 84));118119119120 nv_wr32(dev, NV03_PFIFO_CACHE1_GET, 0);120121 nv_wr32(dev, NV03_PFIFO_CACHE1_PUT, 0);···187186 tmp |= (nv_rd32(dev, NV04_PFIFO_CACHE1_PUT) << 16);188187 nv_wi32(dev, fc + 72, tmp);189188#endif189189+ nv_wi32(dev, fc + 84, nv_rd32(dev, 0x330c));190190191191 nv40_fifo_do_load_context(dev, pfifo->channels - 1);192192 nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1,
+311
drivers/gpu/drm/nouveau/nv40_mpeg.c
···11+/*22+ * Copyright 2011 Red Hat Inc.33+ *44+ * Permission is hereby granted, free of charge, to any person obtaining a55+ * copy of this software and associated documentation files (the "Software"),66+ * to deal in the Software without restriction, including without limitation77+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,88+ * and/or sell copies of the Software, and to permit persons to whom the99+ * Software is furnished to do so, subject to the following conditions:1010+ *1111+ * The above copyright notice and this permission notice shall be included in1212+ * all copies or substantial portions of the Software.1313+ *1414+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1515+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1616+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1717+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR1818+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,1919+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2020+ * OTHER DEALINGS IN THE SOFTWARE.2121+ *2222+ * Authors: Ben Skeggs2323+ */2424+2525+#include "drmP.h"2626+#include "nouveau_drv.h"2727+#include "nouveau_ramht.h"2828+2929+struct nv40_mpeg_engine {3030+ struct nouveau_exec_engine base;3131+};3232+3333+static int3434+nv40_mpeg_context_new(struct nouveau_channel *chan, int engine)3535+{3636+ struct drm_device *dev = chan->dev;3737+ struct drm_nouveau_private *dev_priv = dev->dev_private;3838+ struct nouveau_gpuobj *ctx = NULL;3939+ unsigned long flags;4040+ int ret;4141+4242+ NV_DEBUG(dev, "ch%d\n", chan->id);4343+4444+ ret = nouveau_gpuobj_new(dev, NULL, 264 * 4, 16, NVOBJ_FLAG_ZERO_ALLOC |4545+ NVOBJ_FLAG_ZERO_FREE, &ctx);4646+ if (ret)4747+ return ret;4848+4949+ nv_wo32(ctx, 0x78, 0x02001ec1);5050+5151+ spin_lock_irqsave(&dev_priv->context_switch_lock, flags);5252+ nv_mask(dev, 0x002500, 0x00000001, 0x00000000);5353+ if ((nv_rd32(dev, 0x003204) & 0x1f) == chan->id)5454+ nv_wr32(dev, 0x00330c, ctx->pinst >> 4);5555+ nv_wo32(chan->ramfc, 0x54, ctx->pinst >> 4);5656+ nv_mask(dev, 0x002500, 0x00000001, 0x00000001);5757+ spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);5858+5959+ chan->engctx[engine] = ctx;6060+ return 0;6161+}6262+6363+static void6464+nv40_mpeg_context_del(struct nouveau_channel *chan, int engine)6565+{6666+ struct drm_nouveau_private *dev_priv = chan->dev->dev_private;6767+ struct nouveau_gpuobj *ctx = chan->engctx[engine];6868+ struct drm_device *dev = chan->dev;6969+ unsigned long flags;7070+ u32 inst = 0x80000000 | (ctx->pinst >> 4);7171+7272+ spin_lock_irqsave(&dev_priv->context_switch_lock, flags);7373+ nv_mask(dev, 0x00b32c, 0x00000001, 0x00000000);7474+ if (nv_rd32(dev, 0x00b318) == inst)7575+ nv_mask(dev, 0x00b318, 0x80000000, 0x00000000);7676+ nv_mask(dev, 0x00b32c, 0x00000001, 0x00000001);7777+ spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);7878+7979+ nouveau_gpuobj_ref(NULL, &ctx);8080+ chan->engctx[engine] = NULL;8181+}8282+8383+static int8484+nv40_mpeg_object_new(struct nouveau_channel *chan, int engine,8585+ u32 handle, u16 class)8686+{8787+ struct drm_device *dev = chan->dev;8888+ struct nouveau_gpuobj *obj = NULL;8989+ int ret;9090+9191+ ret = nouveau_gpuobj_new(dev, chan, 20, 16, NVOBJ_FLAG_ZERO_ALLOC |9292+ NVOBJ_FLAG_ZERO_FREE, &obj);9393+ if (ret)9494+ return ret;9595+ obj->engine = 2;9696+ obj->class = class;9797+9898+ nv_wo32(obj, 0x00, class);9999+100100+ ret = nouveau_ramht_insert(chan, handle, obj);101101+ nouveau_gpuobj_ref(NULL, &obj);102102+ return ret;103103+}104104+105105+static int106106+nv40_mpeg_init(struct drm_device *dev, int engine)107107+{108108+ struct drm_nouveau_private *dev_priv = dev->dev_private;109109+ struct nv40_mpeg_engine *pmpeg = nv_engine(dev, engine);110110+ int i;111111+112112+ /* VPE init */113113+ nv_mask(dev, 0x000200, 0x00000002, 0x00000000);114114+ nv_mask(dev, 0x000200, 0x00000002, 0x00000002);115115+ nv_wr32(dev, 0x00b0e0, 0x00000020); /* nvidia: rd 0x01, wr 0x20 */116116+ nv_wr32(dev, 0x00b0e8, 0x00000020); /* nvidia: rd 0x01, wr 0x20 */117117+118118+ for (i = 0; i < dev_priv->engine.fb.num_tiles; i++)119119+ pmpeg->base.set_tile_region(dev, i);120120+121121+ /* PMPEG init */122122+ nv_wr32(dev, 0x00b32c, 0x00000000);123123+ nv_wr32(dev, 0x00b314, 0x00000100);124124+ nv_wr32(dev, 0x00b220, 0x00000044);125125+ nv_wr32(dev, 0x00b300, 0x02001ec1);126126+ nv_mask(dev, 0x00b32c, 0x00000001, 0x00000001);127127+128128+ nv_wr32(dev, 0x00b100, 0xffffffff);129129+ nv_wr32(dev, 0x00b140, 0xffffffff);130130+131131+ if (!nv_wait(dev, 0x00b200, 0x00000001, 0x00000000)) {132132+ NV_ERROR(dev, "PMPEG init: 0x%08x\n", nv_rd32(dev, 0x00b200));133133+ return -EBUSY;134134+ }135135+136136+ return 0;137137+}138138+139139+static int140140+nv40_mpeg_fini(struct drm_device *dev, int engine)141141+{142142+ /*XXX: context save? */143143+ nv_mask(dev, 0x00b32c, 0x00000001, 0x00000000);144144+ nv_wr32(dev, 0x00b140, 0x00000000);145145+ return 0;146146+}147147+148148+static int149149+nv40_mpeg_mthd_dma(struct nouveau_channel *chan, u32 class, u32 mthd, u32 data)150150+{151151+ struct drm_device *dev = chan->dev;152152+ u32 inst = data << 4;153153+ u32 dma0 = nv_ri32(dev, inst + 0);154154+ u32 dma1 = nv_ri32(dev, inst + 4);155155+ u32 dma2 = nv_ri32(dev, inst + 8);156156+ u32 base = (dma2 & 0xfffff000) | (dma0 >> 20);157157+ u32 size = dma1 + 1;158158+159159+ /* only allow linear DMA objects */160160+ if (!(dma0 & 0x00002000))161161+ return -EINVAL;162162+163163+ if (mthd == 0x0190) {164164+ /* DMA_CMD */165165+ nv_mask(dev, 0x00b300, 0x00030000, (dma0 & 0x00030000));166166+ nv_wr32(dev, 0x00b334, base);167167+ nv_wr32(dev, 0x00b324, size);168168+ } else169169+ if (mthd == 0x01a0) {170170+ /* DMA_DATA */171171+ nv_mask(dev, 0x00b300, 0x000c0000, (dma0 & 0x00030000) << 2);172172+ nv_wr32(dev, 0x00b360, base);173173+ nv_wr32(dev, 0x00b364, size);174174+ } else {175175+ /* DMA_IMAGE, VRAM only */176176+ if (dma0 & 0x000c0000)177177+ return -EINVAL;178178+179179+ nv_wr32(dev, 0x00b370, base);180180+ nv_wr32(dev, 0x00b374, size);181181+ }182182+183183+ return 0;184184+}185185+186186+static int187187+nv40_mpeg_isr_chid(struct drm_device *dev, u32 inst)188188+{189189+ struct drm_nouveau_private *dev_priv = dev->dev_private;190190+ struct nouveau_gpuobj *ctx;191191+ unsigned long flags;192192+ int i;193193+194194+ spin_lock_irqsave(&dev_priv->channels.lock, flags);195195+ for (i = 0; i < dev_priv->engine.fifo.channels; i++) {196196+ if (!dev_priv->channels.ptr[i])197197+ continue;198198+199199+ ctx = dev_priv->channels.ptr[i]->engctx[NVOBJ_ENGINE_MPEG];200200+ if (ctx && ctx->pinst == inst)201201+ break;202202+ }203203+ spin_unlock_irqrestore(&dev_priv->channels.lock, flags);204204+ return i;205205+}206206+207207+static void208208+nv40_vpe_set_tile_region(struct drm_device *dev, int i)209209+{210210+ struct drm_nouveau_private *dev_priv = dev->dev_private;211211+ struct nouveau_tile_reg *tile = &dev_priv->tile.reg[i];212212+213213+ nv_wr32(dev, 0x00b008 + (i * 0x10), tile->pitch);214214+ nv_wr32(dev, 0x00b004 + (i * 0x10), tile->limit);215215+ nv_wr32(dev, 0x00b000 + (i * 0x10), tile->addr);216216+}217217+218218+static void219219+nv40_mpeg_isr(struct drm_device *dev)220220+{221221+ u32 inst = (nv_rd32(dev, 0x00b318) & 0x000fffff) << 4;222222+ u32 chid = nv40_mpeg_isr_chid(dev, inst);223223+ u32 stat = nv_rd32(dev, 0x00b100);224224+ u32 type = nv_rd32(dev, 0x00b230);225225+ u32 mthd = nv_rd32(dev, 0x00b234);226226+ u32 data = nv_rd32(dev, 0x00b238);227227+ u32 show = stat;228228+229229+ if (stat & 0x01000000) {230230+ /* happens on initial binding of the object */231231+ if (type == 0x00000020 && mthd == 0x0000) {232232+ nv_mask(dev, 0x00b308, 0x00000000, 0x00000000);233233+ show &= ~0x01000000;234234+ }235235+236236+ if (type == 0x00000010) {237237+ if (!nouveau_gpuobj_mthd_call2(dev, chid, 0x3174, mthd, data))238238+ show &= ~0x01000000;239239+ }240240+ }241241+242242+ nv_wr32(dev, 0x00b100, stat);243243+ nv_wr32(dev, 0x00b230, 0x00000001);244244+245245+ if (show && nouveau_ratelimit()) {246246+ NV_INFO(dev, "PMPEG: Ch %d [0x%08x] 0x%08x 0x%08x 0x%08x 0x%08x\n",247247+ chid, inst, stat, type, mthd, data);248248+ }249249+}250250+251251+static void252252+nv40_vpe_isr(struct drm_device *dev)253253+{254254+ if (nv_rd32(dev, 0x00b100))255255+ nv40_mpeg_isr(dev);256256+257257+ if (nv_rd32(dev, 0x00b800)) {258258+ u32 stat = nv_rd32(dev, 0x00b800);259259+ NV_INFO(dev, "PMSRCH: 0x%08x\n", stat);260260+ nv_wr32(dev, 0xb800, stat);261261+ }262262+}263263+264264+static void265265+nv40_mpeg_destroy(struct drm_device *dev, int engine)266266+{267267+ struct nv40_mpeg_engine *pmpeg = nv_engine(dev, engine);268268+269269+ nouveau_irq_unregister(dev, 0);270270+271271+ NVOBJ_ENGINE_DEL(dev, MPEG);272272+ kfree(pmpeg);273273+}274274+275275+int276276+nv40_mpeg_create(struct drm_device *dev)277277+{278278+ struct nv40_mpeg_engine *pmpeg;279279+280280+ pmpeg = kzalloc(sizeof(*pmpeg), GFP_KERNEL);281281+ if (!pmpeg)282282+ return -ENOMEM;283283+284284+ pmpeg->base.destroy = nv40_mpeg_destroy;285285+ pmpeg->base.init = nv40_mpeg_init;286286+ pmpeg->base.fini = nv40_mpeg_fini;287287+ pmpeg->base.context_new = nv40_mpeg_context_new;288288+ pmpeg->base.context_del = nv40_mpeg_context_del;289289+ pmpeg->base.object_new = nv40_mpeg_object_new;290290+291291+ /* ISR vector, PMC_ENABLE bit, and TILE regs are shared between292292+ * all VPE engines, for this driver's purposes the PMPEG engine293293+ * will be treated as the "master" and handle the global VPE294294+ * bits too295295+ */296296+ pmpeg->base.set_tile_region = nv40_vpe_set_tile_region;297297+ nouveau_irq_register(dev, 0, nv40_vpe_isr);298298+299299+ NVOBJ_ENGINE_ADD(dev, MPEG, &pmpeg->base);300300+ NVOBJ_CLASS(dev, 0x3174, MPEG);301301+ NVOBJ_MTHD (dev, 0x3174, 0x0190, nv40_mpeg_mthd_dma);302302+ NVOBJ_MTHD (dev, 0x3174, 0x01a0, nv40_mpeg_mthd_dma);303303+ NVOBJ_MTHD (dev, 0x3174, 0x01b0, nv40_mpeg_mthd_dma);304304+305305+#if 0306306+ NVOBJ_ENGINE_ADD(dev, ME, &pme->base);307307+ NVOBJ_CLASS(dev, 0x4075, ME);308308+#endif309309+ return 0;310310+311311+}