drm/nouveau/core: object.engine is always a nouveau_engine now
[deliverable/linux.git] / drivers / gpu / drm / nouveau / core / subdev / bar / base.c
CommitLineData
3863c9bc
BS
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>
52225551
BS
26
27#include <subdev/fb.h>
28#include <subdev/vm.h>
29
30#include "priv.h"
3863c9bc
BS
31
32struct nouveau_barobj {
33 struct nouveau_object base;
34 struct nouveau_vma vma;
35 void __iomem *iomem;
36};
37
38static int
39nouveau_barobj_ctor(struct nouveau_object *parent,
40 struct nouveau_object *engine,
e94654e2 41 struct nouveau_oclass *oclass, void *data, u32 size,
3863c9bc
BS
42 struct nouveau_object **pobject)
43{
e94654e2 44 struct nouveau_device *device = nv_device(parent);
c272d86e 45 struct nouveau_bar *bar = nouveau_bar(device);
e94654e2 46 struct nouveau_mem *mem = data;
3863c9bc
BS
47 struct nouveau_barobj *barobj;
48 int ret;
49
50 ret = nouveau_object_create(parent, engine, oclass, 0, &barobj);
51 *pobject = nv_object(barobj);
52 if (ret)
53 return ret;
54
55 ret = bar->kmap(bar, mem, NV_MEM_ACCESS_RW, &barobj->vma);
56 if (ret)
57 return ret;
58
e94654e2
BS
59 barobj->iomem = ioremap(nv_device_resource_start(device, 3) +
60 (u32)barobj->vma.offset, mem->size << 12);
61 if (!barobj->iomem) {
62 nv_warn(bar, "PRAMIN ioremap failed\n");
63 return -ENOMEM;
64 }
65
3863c9bc
BS
66 return 0;
67}
68
69static void
70nouveau_barobj_dtor(struct nouveau_object *object)
71{
c272d86e 72 struct nouveau_bar *bar = nouveau_bar(object);
3863c9bc 73 struct nouveau_barobj *barobj = (void *)object;
e94654e2
BS
74 if (barobj->vma.node) {
75 if (barobj->iomem)
76 iounmap(barobj->iomem);
3863c9bc 77 bar->unmap(bar, &barobj->vma);
e94654e2 78 }
3863c9bc
BS
79 nouveau_object_destroy(&barobj->base);
80}
81
82static u32
0a32241d 83nouveau_barobj_rd32(struct nouveau_object *object, u64 addr)
3863c9bc
BS
84{
85 struct nouveau_barobj *barobj = (void *)object;
86 return ioread32_native(barobj->iomem + addr);
87}
88
89static void
0a32241d 90nouveau_barobj_wr32(struct nouveau_object *object, u64 addr, u32 data)
3863c9bc
BS
91{
92 struct nouveau_barobj *barobj = (void *)object;
93 iowrite32_native(data, barobj->iomem + addr);
94}
95
96static struct nouveau_oclass
97nouveau_barobj_oclass = {
98 .ofuncs = &(struct nouveau_ofuncs) {
99 .ctor = nouveau_barobj_ctor,
100 .dtor = nouveau_barobj_dtor,
101 .init = nouveau_object_init,
102 .fini = nouveau_object_fini,
103 .rd32 = nouveau_barobj_rd32,
104 .wr32 = nouveau_barobj_wr32,
105 },
106};
107
108int
109nouveau_bar_alloc(struct nouveau_bar *bar, struct nouveau_object *parent,
110 struct nouveau_mem *mem, struct nouveau_object **pobject)
111{
e94654e2 112 struct nouveau_object *gpuobj;
ec0e5542 113 int ret = nouveau_object_ctor(parent, &parent->engine->subdev.object,
c272d86e 114 &nouveau_barobj_oclass,
e94654e2
BS
115 mem, 0, &gpuobj);
116 if (ret == 0)
117 *pobject = gpuobj;
e7d96929 118 return ret;
3863c9bc
BS
119}
120
121int
122nouveau_bar_create_(struct nouveau_object *parent,
123 struct nouveau_object *engine,
124 struct nouveau_oclass *oclass, int length, void **pobject)
125{
3863c9bc
BS
126 struct nouveau_bar *bar;
127 int ret;
128
129 ret = nouveau_subdev_create_(parent, engine, oclass, 0, "BARCTL",
130 "bar", length, pobject);
131 bar = *pobject;
132 if (ret)
133 return ret;
134
3863c9bc
BS
135 return 0;
136}
137
138void
139nouveau_bar_destroy(struct nouveau_bar *bar)
140{
3863c9bc
BS
141 nouveau_subdev_destroy(&bar->base);
142}
143
144void
145_nouveau_bar_dtor(struct nouveau_object *object)
146{
147 struct nouveau_bar *bar = (void *)object;
148 nouveau_bar_destroy(bar);
149}
This page took 0.152027 seconds and 5 git commands to generate.