| 1 | /* $NetBSD: nouveau_engine_software_nvc0.c,v 1.1.1.1 2014/08/06 12:36:27 riastradh Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2012 Red Hat Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: Ben Skeggs |
| 25 | */ |
| 26 | |
| 27 | #include <sys/cdefs.h> |
| 28 | __KERNEL_RCSID(0, "$NetBSD: nouveau_engine_software_nvc0.c,v 1.1.1.1 2014/08/06 12:36:27 riastradh Exp $" ); |
| 29 | |
| 30 | #include <core/os.h> |
| 31 | #include <core/class.h> |
| 32 | #include <core/engctx.h> |
| 33 | #include <core/event.h> |
| 34 | |
| 35 | #include <subdev/bar.h> |
| 36 | |
| 37 | #include <engine/software.h> |
| 38 | #include <engine/disp.h> |
| 39 | |
| 40 | #include "nv50.h" |
| 41 | |
| 42 | /******************************************************************************* |
| 43 | * software object classes |
| 44 | ******************************************************************************/ |
| 45 | |
| 46 | static int |
| 47 | nvc0_software_mthd_vblsem_offset(struct nouveau_object *object, u32 mthd, |
| 48 | void *args, u32 size) |
| 49 | { |
| 50 | struct nv50_software_chan *chan = (void *)nv_engctx(object->parent); |
| 51 | u64 data = *(u32 *)args; |
| 52 | if (mthd == 0x0400) { |
| 53 | chan->vblank.offset &= 0x00ffffffffULL; |
| 54 | chan->vblank.offset |= data << 32; |
| 55 | } else { |
| 56 | chan->vblank.offset &= 0xff00000000ULL; |
| 57 | chan->vblank.offset |= data; |
| 58 | } |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | static int |
| 63 | nvc0_software_mthd_mp_control(struct nouveau_object *object, u32 mthd, |
| 64 | void *args, u32 size) |
| 65 | { |
| 66 | struct nv50_software_chan *chan = (void *)nv_engctx(object->parent); |
| 67 | struct nv50_software_priv *priv = (void *)nv_object(chan)->engine; |
| 68 | u32 data = *(u32 *)args; |
| 69 | |
| 70 | switch (mthd) { |
| 71 | case 0x600: |
| 72 | nv_wr32(priv, 0x419e00, data); /* MP.PM_UNK000 */ |
| 73 | break; |
| 74 | case 0x644: |
| 75 | if (data & ~0x1ffffe) |
| 76 | return -EINVAL; |
| 77 | nv_wr32(priv, 0x419e44, data); /* MP.TRAP_WARP_ERROR_EN */ |
| 78 | break; |
| 79 | case 0x6ac: |
| 80 | nv_wr32(priv, 0x419eac, data); /* MP.PM_UNK0AC */ |
| 81 | break; |
| 82 | default: |
| 83 | return -EINVAL; |
| 84 | } |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | static struct nouveau_omthds |
| 89 | nvc0_software_omthds[] = { |
| 90 | { 0x0400, 0x0400, nvc0_software_mthd_vblsem_offset }, |
| 91 | { 0x0404, 0x0404, nvc0_software_mthd_vblsem_offset }, |
| 92 | { 0x0408, 0x0408, nv50_software_mthd_vblsem_value }, |
| 93 | { 0x040c, 0x040c, nv50_software_mthd_vblsem_release }, |
| 94 | { 0x0500, 0x0500, nv50_software_mthd_flip }, |
| 95 | { 0x0600, 0x0600, nvc0_software_mthd_mp_control }, |
| 96 | { 0x0644, 0x0644, nvc0_software_mthd_mp_control }, |
| 97 | { 0x06ac, 0x06ac, nvc0_software_mthd_mp_control }, |
| 98 | {} |
| 99 | }; |
| 100 | |
| 101 | static struct nouveau_oclass |
| 102 | nvc0_software_sclass[] = { |
| 103 | { 0x906e, &nouveau_object_ofuncs, nvc0_software_omthds }, |
| 104 | {} |
| 105 | }; |
| 106 | |
| 107 | /******************************************************************************* |
| 108 | * software context |
| 109 | ******************************************************************************/ |
| 110 | |
| 111 | static int |
| 112 | nvc0_software_vblsem_release(void *data, int head) |
| 113 | { |
| 114 | struct nv50_software_chan *chan = data; |
| 115 | struct nv50_software_priv *priv = (void *)nv_object(chan)->engine; |
| 116 | struct nouveau_bar *bar = nouveau_bar(priv); |
| 117 | |
| 118 | nv_wr32(priv, 0x001718, 0x80000000 | chan->vblank.channel); |
| 119 | bar->flush(bar); |
| 120 | nv_wr32(priv, 0x06000c, upper_32_bits(chan->vblank.offset)); |
| 121 | nv_wr32(priv, 0x060010, lower_32_bits(chan->vblank.offset)); |
| 122 | nv_wr32(priv, 0x060014, chan->vblank.value); |
| 123 | |
| 124 | return NVKM_EVENT_DROP; |
| 125 | } |
| 126 | |
| 127 | static struct nv50_software_cclass |
| 128 | nvc0_software_cclass = { |
| 129 | .base.handle = NV_ENGCTX(SW, 0xc0), |
| 130 | .base.ofuncs = &(struct nouveau_ofuncs) { |
| 131 | .ctor = nv50_software_context_ctor, |
| 132 | .dtor = _nouveau_software_context_dtor, |
| 133 | .init = _nouveau_software_context_init, |
| 134 | .fini = _nouveau_software_context_fini, |
| 135 | }, |
| 136 | .vblank = nvc0_software_vblsem_release, |
| 137 | }; |
| 138 | |
| 139 | /******************************************************************************* |
| 140 | * software engine/subdev functions |
| 141 | ******************************************************************************/ |
| 142 | |
| 143 | struct nouveau_oclass * |
| 144 | nvc0_software_oclass = &(struct nv50_software_oclass) { |
| 145 | .base.handle = NV_ENGINE(SW, 0xc0), |
| 146 | .base.ofuncs = &(struct nouveau_ofuncs) { |
| 147 | .ctor = nv50_software_ctor, |
| 148 | .dtor = _nouveau_software_dtor, |
| 149 | .init = _nouveau_software_init, |
| 150 | .fini = _nouveau_software_fini, |
| 151 | }, |
| 152 | .cclass = &nvc0_software_cclass.base, |
| 153 | .sclass = nvc0_software_sclass, |
| 154 | }.base; |
| 155 | |