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#include "priv.h"
25
26void
27nvkm_bar_flush(struct nvkm_bar *bar)
28{
29	if (bar && bar->func->flush)
30		bar->func->flush(bar);
31}
32
33struct nvkm_vm *
34nvkm_bar_kmap(struct nvkm_bar *bar)
35{
36	/* disallow kmap() until after vm has been bootstrapped */
37	if (bar && bar->func->kmap && bar->subdev.oneinit)
38		return bar->func->kmap(bar);
39	return NULL;
40}
41
42int
43nvkm_bar_umap(struct nvkm_bar *bar, u64 size, int type, struct nvkm_vma *vma)
44{
45	return bar->func->umap(bar, size, type, vma);
46}
47
48static int
49nvkm_bar_oneinit(struct nvkm_subdev *subdev)
50{
51	struct nvkm_bar *bar = nvkm_bar(subdev);
52	return bar->func->oneinit(bar);
53}
54
55static int
56nvkm_bar_init(struct nvkm_subdev *subdev)
57{
58	struct nvkm_bar *bar = nvkm_bar(subdev);
59	return bar->func->init(bar);
60}
61
62static void *
63nvkm_bar_dtor(struct nvkm_subdev *subdev)
64{
65	struct nvkm_bar *bar = nvkm_bar(subdev);
66	return bar->func->dtor(bar);
67}
68
69static const struct nvkm_subdev_func
70nvkm_bar = {
71	.dtor = nvkm_bar_dtor,
72	.oneinit = nvkm_bar_oneinit,
73	.init = nvkm_bar_init,
74};
75
76void
77nvkm_bar_ctor(const struct nvkm_bar_func *func, struct nvkm_device *device,
78	      int index, struct nvkm_bar *bar)
79{
80	nvkm_subdev_ctor(&nvkm_bar, device, index, 0, &bar->subdev);
81	bar->func = func;
82	spin_lock_init(&bar->lock);
83}
84