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.
25 #include <core/object.h>
27 #include <subdev/fb.h>
28 #include <subdev/vm.h>
32 struct nouveau_barobj {
33 struct nouveau_object base;
34 struct nouveau_vma vma;
39 nouveau_barobj_ctor(struct nouveau_object *parent,
40 struct nouveau_object *engine,
41 struct nouveau_oclass *oclass, void *mem, u32 size,
42 struct nouveau_object **pobject)
44 struct nouveau_bar *bar = (void *)engine;
45 struct nouveau_barobj *barobj;
48 ret = nouveau_object_create(parent, engine, oclass, 0, &barobj);
49 *pobject = nv_object(barobj);
53 ret = bar->kmap(bar, mem, NV_MEM_ACCESS_RW, &barobj->vma);
57 barobj->iomem = bar->iomem + (u32)barobj->vma.offset;
62 nouveau_barobj_dtor(struct nouveau_object *object)
64 struct nouveau_bar *bar = (void *)object->engine;
65 struct nouveau_barobj *barobj = (void *)object;
67 bar->unmap(bar, &barobj->vma);
68 nouveau_object_destroy(&barobj->base);
72 nouveau_barobj_rd32(struct nouveau_object *object, u64 addr)
74 struct nouveau_barobj *barobj = (void *)object;
75 return ioread32_native(barobj->iomem + addr);
79 nouveau_barobj_wr32(struct nouveau_object *object, u64 addr, u32 data)
81 struct nouveau_barobj *barobj = (void *)object;
82 iowrite32_native(data, barobj->iomem + addr);
85 static struct nouveau_oclass
86 nouveau_barobj_oclass = {
87 .ofuncs = &(struct nouveau_ofuncs) {
88 .ctor = nouveau_barobj_ctor,
89 .dtor = nouveau_barobj_dtor,
90 .init = nouveau_object_init,
91 .fini = nouveau_object_fini,
92 .rd32 = nouveau_barobj_rd32,
93 .wr32 = nouveau_barobj_wr32,
98 nouveau_bar_alloc(struct nouveau_bar *bar, struct nouveau_object *parent,
99 struct nouveau_mem *mem, struct nouveau_object **pobject)
101 struct nouveau_object *engine = nv_object(bar);
102 return nouveau_object_ctor(parent, engine, &nouveau_barobj_oclass,
107 nouveau_bar_create_(struct nouveau_object *parent,
108 struct nouveau_object *engine,
109 struct nouveau_oclass *oclass, int length, void **pobject)
111 struct nouveau_device *device = nv_device(parent);
112 struct nouveau_bar *bar;
115 ret = nouveau_subdev_create_(parent, engine, oclass, 0, "BARCTL",
116 "bar", length, pobject);
121 bar->iomem = ioremap(pci_resource_start(device->pdev, 3),
122 pci_resource_len(device->pdev, 3));
127 nouveau_bar_destroy(struct nouveau_bar *bar)
131 nouveau_subdev_destroy(&bar->base);
135 _nouveau_bar_dtor(struct nouveau_object *object)
137 struct nouveau_bar *bar = (void *)object;
138 nouveau_bar_destroy(bar);