2 * Copyright 2012 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
26 #include <core/device.h>
27 #include <subdev/fb.h>
28 #include <subdev/mmu.h>
31 struct nvkm_object base
;
37 nvkm_barobj_ctor(struct nvkm_object
*parent
, struct nvkm_object
*engine
,
38 struct nvkm_oclass
*oclass
, void *data
, u32 size
,
39 struct nvkm_object
**pobject
)
41 struct nvkm_device
*device
= nv_device(parent
);
42 struct nvkm_bar
*bar
= nvkm_bar(device
);
43 struct nvkm_mem
*mem
= data
;
44 struct nvkm_barobj
*barobj
;
47 ret
= nvkm_object_create(parent
, engine
, oclass
, 0, &barobj
);
48 *pobject
= nv_object(barobj
);
52 ret
= bar
->kmap(bar
, mem
, NV_MEM_ACCESS_RW
, &barobj
->vma
);
56 barobj
->iomem
= ioremap(nv_device_resource_start(device
, 3) +
57 (u32
)barobj
->vma
.offset
, mem
->size
<< 12);
59 nv_warn(bar
, "PRAMIN ioremap failed\n");
67 nvkm_barobj_dtor(struct nvkm_object
*object
)
69 struct nvkm_bar
*bar
= nvkm_bar(object
);
70 struct nvkm_barobj
*barobj
= (void *)object
;
71 if (barobj
->vma
.node
) {
73 iounmap(barobj
->iomem
);
74 bar
->unmap(bar
, &barobj
->vma
);
76 nvkm_object_destroy(&barobj
->base
);
80 nvkm_barobj_rd32(struct nvkm_object
*object
, u64 addr
)
82 struct nvkm_barobj
*barobj
= (void *)object
;
83 return ioread32_native(barobj
->iomem
+ addr
);
87 nvkm_barobj_wr32(struct nvkm_object
*object
, u64 addr
, u32 data
)
89 struct nvkm_barobj
*barobj
= (void *)object
;
90 iowrite32_native(data
, barobj
->iomem
+ addr
);
93 static struct nvkm_oclass
94 nvkm_barobj_oclass
= {
95 .ofuncs
= &(struct nvkm_ofuncs
) {
96 .ctor
= nvkm_barobj_ctor
,
97 .dtor
= nvkm_barobj_dtor
,
98 .init
= nvkm_object_init
,
99 .fini
= nvkm_object_fini
,
100 .rd32
= nvkm_barobj_rd32
,
101 .wr32
= nvkm_barobj_wr32
,
106 nvkm_bar_alloc(struct nvkm_bar
*bar
, struct nvkm_object
*parent
,
107 struct nvkm_mem
*mem
, struct nvkm_object
**pobject
)
109 struct nvkm_object
*gpuobj
;
110 int ret
= nvkm_object_ctor(parent
, &parent
->engine
->subdev
.object
,
111 &nvkm_barobj_oclass
, mem
, 0, &gpuobj
);
118 nvkm_bar_create_(struct nvkm_object
*parent
, struct nvkm_object
*engine
,
119 struct nvkm_oclass
*oclass
, int length
, void **pobject
)
121 struct nvkm_bar
*bar
;
124 ret
= nvkm_subdev_create_(parent
, engine
, oclass
, 0, "BARCTL",
125 "bar", length
, pobject
);
134 nvkm_bar_destroy(struct nvkm_bar
*bar
)
136 nvkm_subdev_destroy(&bar
->base
);
140 _nvkm_bar_dtor(struct nvkm_object
*object
)
142 struct nvkm_bar
*bar
= (void *)object
;
143 nvkm_bar_destroy(bar
);