base.c 2.3 KB

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