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 | |
| 25 | #include <core/object.h> |
| 26 | #include <core/class.h> |
| 27 | |
| 28 | #include <subdev/fb.h> |
Ben Skeggs | bc98540 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 29 | |
| 30 | #include "priv.h" |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 31 | |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 32 | static int |
| 33 | nouveau_dmaobj_ctor(struct nouveau_object *parent, |
| 34 | struct nouveau_object *engine, |
| 35 | struct nouveau_oclass *oclass, void *data, u32 size, |
| 36 | struct nouveau_object **pobject) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 37 | { |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 38 | struct nouveau_dmaeng *dmaeng = (void *)engine; |
| 39 | struct nouveau_dmaobj *dmaobj; |
| 40 | struct nouveau_gpuobj *gpuobj; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 41 | struct nv_dma_class *args = data; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 42 | int ret; |
| 43 | |
| 44 | if (size < sizeof(*args)) |
| 45 | return -EINVAL; |
| 46 | |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 47 | ret = nouveau_object_create(parent, engine, oclass, 0, &dmaobj); |
| 48 | *pobject = nv_object(dmaobj); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 49 | if (ret) |
| 50 | return ret; |
| 51 | |
| 52 | switch (args->flags & NV_DMA_TARGET_MASK) { |
| 53 | case NV_DMA_TARGET_VM: |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 54 | dmaobj->target = NV_MEM_TARGET_VM; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 55 | break; |
| 56 | case NV_DMA_TARGET_VRAM: |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 57 | dmaobj->target = NV_MEM_TARGET_VRAM; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 58 | break; |
| 59 | case NV_DMA_TARGET_PCI: |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 60 | dmaobj->target = NV_MEM_TARGET_PCI; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 61 | break; |
| 62 | case NV_DMA_TARGET_PCI_US: |
| 63 | case NV_DMA_TARGET_AGP: |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 64 | dmaobj->target = NV_MEM_TARGET_PCI_NOSNOOP; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 65 | break; |
| 66 | default: |
| 67 | return -EINVAL; |
| 68 | } |
| 69 | |
| 70 | switch (args->flags & NV_DMA_ACCESS_MASK) { |
| 71 | case NV_DMA_ACCESS_VM: |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 72 | dmaobj->access = NV_MEM_ACCESS_VM; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 73 | break; |
| 74 | case NV_DMA_ACCESS_RD: |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 75 | dmaobj->access = NV_MEM_ACCESS_RO; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 76 | break; |
| 77 | case NV_DMA_ACCESS_WR: |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 78 | dmaobj->access = NV_MEM_ACCESS_WO; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 79 | break; |
| 80 | case NV_DMA_ACCESS_RDWR: |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 81 | dmaobj->access = NV_MEM_ACCESS_RW; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 82 | break; |
| 83 | default: |
| 84 | return -EINVAL; |
| 85 | } |
| 86 | |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 87 | dmaobj->start = args->start; |
| 88 | dmaobj->limit = args->limit; |
Ben Skeggs | f756944 | 2012-10-08 14:29:16 +1000 | [diff] [blame] | 89 | dmaobj->conf0 = args->conf0; |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 90 | |
| 91 | switch (nv_mclass(parent)) { |
Ben Skeggs | 586491e | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 92 | case NV_DEVICE: |
Ben Skeggs | 6c1689a | 2012-10-08 12:58:23 +1000 | [diff] [blame] | 93 | /* delayed, or no, binding */ |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 94 | break; |
| 95 | default: |
Ben Skeggs | 6c1689a | 2012-10-08 12:58:23 +1000 | [diff] [blame] | 96 | ret = dmaeng->bind(dmaeng, *pobject, dmaobj, &gpuobj); |
| 97 | if (ret == 0) { |
| 98 | nouveau_object_ref(NULL, pobject); |
| 99 | *pobject = nv_object(gpuobj); |
| 100 | } |
| 101 | break; |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | return ret; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 105 | } |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 106 | |
| 107 | static struct nouveau_ofuncs |
| 108 | nouveau_dmaobj_ofuncs = { |
| 109 | .ctor = nouveau_dmaobj_ctor, |
| 110 | .dtor = nouveau_object_destroy, |
| 111 | .init = nouveau_object_init, |
| 112 | .fini = nouveau_object_fini, |
| 113 | }; |
| 114 | |
Ben Skeggs | bc98540 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 115 | static struct nouveau_oclass |
Ben Skeggs | f86770a | 2012-08-29 10:54:49 +1000 | [diff] [blame] | 116 | nouveau_dmaobj_sclass[] = { |
| 117 | { NV_DMA_FROM_MEMORY_CLASS, &nouveau_dmaobj_ofuncs }, |
| 118 | { NV_DMA_TO_MEMORY_CLASS, &nouveau_dmaobj_ofuncs }, |
| 119 | { NV_DMA_IN_MEMORY_CLASS, &nouveau_dmaobj_ofuncs }, |
| 120 | {} |
| 121 | }; |
Ben Skeggs | bc98540 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 122 | |
| 123 | int |
| 124 | _nvkm_dmaeng_ctor(struct nouveau_object *parent, struct nouveau_object *engine, |
| 125 | struct nouveau_oclass *oclass, void *data, u32 size, |
| 126 | struct nouveau_object **pobject) |
| 127 | { |
| 128 | const struct nvkm_dmaeng_impl *impl = (void *)oclass; |
| 129 | struct nouveau_dmaeng *dmaeng; |
| 130 | int ret; |
| 131 | |
| 132 | ret = nouveau_engine_create(parent, engine, oclass, true, "DMAOBJ", |
| 133 | "dmaobj", &dmaeng); |
| 134 | *pobject = nv_object(dmaeng); |
| 135 | if (ret) |
| 136 | return ret; |
| 137 | |
| 138 | nv_engine(dmaeng)->sclass = nouveau_dmaobj_sclass; |
| 139 | dmaeng->bind = impl->bind; |
| 140 | return 0; |
| 141 | } |