Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Red Hat Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | * |
| 22 | * Authors: Ben Skeggs |
| 23 | */ |
| 24 | |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 25 | #include <core/device.h> |
Ben Skeggs | 82d23ae | 2012-10-08 13:39:13 +1000 | [diff] [blame] | 26 | #include <core/gpuobj.h> |
| 27 | #include <core/class.h> |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 28 | |
Ben Skeggs | 82d23ae | 2012-10-08 13:39:13 +1000 | [diff] [blame] | 29 | #include <subdev/fb.h> |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 30 | |
Ben Skeggs | bc98540 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 31 | #include "priv.h" |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 32 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 33 | static int |
Ben Skeggs | 82d23ae | 2012-10-08 13:39:13 +1000 | [diff] [blame] | 34 | nvc0_dmaobj_bind(struct nouveau_dmaeng *dmaeng, |
| 35 | struct nouveau_object *parent, |
| 36 | struct nouveau_dmaobj *dmaobj, |
| 37 | struct nouveau_gpuobj **pgpuobj) |
| 38 | { |
Ben Skeggs | 80fe155 | 2012-10-08 14:34:35 +1000 | [diff] [blame] | 39 | u32 flags0 = nv_mclass(dmaobj); |
| 40 | u32 flags5 = 0x00000000; |
| 41 | int ret; |
Ben Skeggs | 82d23ae | 2012-10-08 13:39:13 +1000 | [diff] [blame] | 42 | |
| 43 | if (!nv_iclass(parent, NV_ENGCTX_CLASS)) { |
| 44 | switch (nv_mclass(parent->parent)) { |
Ben Skeggs | 370c00f | 2012-08-14 14:11:49 +1000 | [diff] [blame] | 45 | case NVA3_DISP_MAST_CLASS: |
| 46 | case NVA3_DISP_SYNC_CLASS: |
| 47 | case NVA3_DISP_OVLY_CLASS: |
| 48 | break; |
Ben Skeggs | 82d23ae | 2012-10-08 13:39:13 +1000 | [diff] [blame] | 49 | default: |
| 50 | return -EINVAL; |
| 51 | } |
| 52 | } else |
| 53 | return 0; |
| 54 | |
Ben Skeggs | 80fe155 | 2012-10-08 14:34:35 +1000 | [diff] [blame] | 55 | if (!(dmaobj->conf0 & NVC0_DMA_CONF0_ENABLE)) { |
| 56 | if (dmaobj->target == NV_MEM_TARGET_VM) { |
| 57 | dmaobj->conf0 = NVC0_DMA_CONF0_PRIV_VM; |
| 58 | dmaobj->conf0 |= NVC0_DMA_CONF0_TYPE_VM; |
| 59 | } else { |
| 60 | dmaobj->conf0 = NVC0_DMA_CONF0_PRIV_US; |
| 61 | dmaobj->conf0 |= NVC0_DMA_CONF0_TYPE_LINEAR; |
| 62 | dmaobj->conf0 |= 0x00020000; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | flags0 |= (dmaobj->conf0 & NVC0_DMA_CONF0_TYPE) << 22; |
| 67 | flags0 |= (dmaobj->conf0 & NVC0_DMA_CONF0_PRIV); |
| 68 | flags5 |= (dmaobj->conf0 & NVC0_DMA_CONF0_UNKN); |
| 69 | |
| 70 | switch (dmaobj->target) { |
| 71 | case NV_MEM_TARGET_VM: |
| 72 | flags0 |= 0x00000000; |
| 73 | break; |
| 74 | case NV_MEM_TARGET_VRAM: |
| 75 | flags0 |= 0x00010000; |
| 76 | break; |
| 77 | case NV_MEM_TARGET_PCI: |
| 78 | flags0 |= 0x00020000; |
| 79 | break; |
| 80 | case NV_MEM_TARGET_PCI_NOSNOOP: |
| 81 | flags0 |= 0x00030000; |
| 82 | break; |
| 83 | default: |
| 84 | return -EINVAL; |
| 85 | } |
| 86 | |
| 87 | switch (dmaobj->access) { |
| 88 | case NV_MEM_ACCESS_VM: |
| 89 | break; |
| 90 | case NV_MEM_ACCESS_RO: |
| 91 | flags0 |= 0x00040000; |
| 92 | break; |
| 93 | case NV_MEM_ACCESS_WO: |
| 94 | case NV_MEM_ACCESS_RW: |
| 95 | flags0 |= 0x00080000; |
| 96 | break; |
| 97 | } |
| 98 | |
| 99 | ret = nouveau_gpuobj_new(parent, parent, 24, 32, 0, pgpuobj); |
| 100 | if (ret == 0) { |
| 101 | nv_wo32(*pgpuobj, 0x00, flags0); |
| 102 | nv_wo32(*pgpuobj, 0x04, lower_32_bits(dmaobj->limit)); |
| 103 | nv_wo32(*pgpuobj, 0x08, lower_32_bits(dmaobj->start)); |
| 104 | nv_wo32(*pgpuobj, 0x0c, upper_32_bits(dmaobj->limit) << 24 | |
| 105 | upper_32_bits(dmaobj->start)); |
| 106 | nv_wo32(*pgpuobj, 0x10, 0x00000000); |
| 107 | nv_wo32(*pgpuobj, 0x14, flags5); |
| 108 | } |
| 109 | |
Ben Skeggs | 82d23ae | 2012-10-08 13:39:13 +1000 | [diff] [blame] | 110 | return ret; |
| 111 | } |
| 112 | |
Ben Skeggs | bc98540 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 113 | struct nouveau_oclass * |
| 114 | nvc0_dmaeng_oclass = &(struct nvkm_dmaeng_impl) { |
| 115 | .base.handle = NV_ENGINE(DMAOBJ, 0xc0), |
| 116 | .base.ofuncs = &(struct nouveau_ofuncs) { |
| 117 | .ctor = _nvkm_dmaeng_ctor, |
| 118 | .dtor = _nvkm_dmaeng_dtor, |
| 119 | .init = _nvkm_dmaeng_init, |
| 120 | .fini = _nvkm_dmaeng_fini, |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 121 | }, |
Ben Skeggs | bc98540 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 122 | .bind = nvc0_dmaobj_bind, |
| 123 | }.base; |