| 1 | /* $NetBSD: nouveau_core_subdev.c,v 1.3 2016/04/13 07:59:05 riastradh Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2012 Red Hat Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: Ben Skeggs |
| 25 | */ |
| 26 | |
| 27 | #include <sys/cdefs.h> |
| 28 | __KERNEL_RCSID(0, "$NetBSD: nouveau_core_subdev.c,v 1.3 2016/04/13 07:59:05 riastradh Exp $" ); |
| 29 | |
| 30 | #include <core/object.h> |
| 31 | #include <core/subdev.h> |
| 32 | #include <core/device.h> |
| 33 | #include <core/option.h> |
| 34 | |
| 35 | void |
| 36 | nouveau_subdev_reset(struct nouveau_object *subdev) |
| 37 | { |
| 38 | nv_trace(subdev, "resetting...\n" ); |
| 39 | nv_ofuncs(subdev)->fini(subdev, false); |
| 40 | nv_debug(subdev, "reset\n" ); |
| 41 | } |
| 42 | |
| 43 | int |
| 44 | nouveau_subdev_init(struct nouveau_subdev *subdev) |
| 45 | { |
| 46 | int ret = nouveau_object_init(&subdev->base); |
| 47 | if (ret) |
| 48 | return ret; |
| 49 | |
| 50 | nouveau_subdev_reset(&subdev->base); |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | int |
| 55 | _nouveau_subdev_init(struct nouveau_object *object) |
| 56 | { |
| 57 | return nouveau_subdev_init(nv_subdev(object)); |
| 58 | } |
| 59 | |
| 60 | int |
| 61 | nouveau_subdev_fini(struct nouveau_subdev *subdev, bool suspend) |
| 62 | { |
| 63 | if (subdev->unit) { |
| 64 | nv_mask(subdev, 0x000200, subdev->unit, 0x00000000); |
| 65 | nv_mask(subdev, 0x000200, subdev->unit, subdev->unit); |
| 66 | } |
| 67 | |
| 68 | return nouveau_object_fini(&subdev->base, suspend); |
| 69 | } |
| 70 | |
| 71 | int |
| 72 | _nouveau_subdev_fini(struct nouveau_object *object, bool suspend) |
| 73 | { |
| 74 | return nouveau_subdev_fini(nv_subdev(object), suspend); |
| 75 | } |
| 76 | |
| 77 | void |
| 78 | nouveau_subdev_destroy(struct nouveau_subdev *subdev) |
| 79 | { |
| 80 | int subidx = nv_hclass(subdev) & 0xff; |
| 81 | nv_device(subdev)->subdev[subidx] = NULL; |
| 82 | linux_mutex_destroy(&subdev->mutex); |
| 83 | nouveau_object_destroy(&subdev->base); |
| 84 | } |
| 85 | |
| 86 | void |
| 87 | _nouveau_subdev_dtor(struct nouveau_object *object) |
| 88 | { |
| 89 | nouveau_subdev_destroy(nv_subdev(object)); |
| 90 | } |
| 91 | |
| 92 | int |
| 93 | nouveau_subdev_create_(struct nouveau_object *parent, |
| 94 | struct nouveau_object *engine, |
| 95 | struct nouveau_oclass *oclass, u32 pclass, |
| 96 | const char *subname, const char *sysname, |
| 97 | int size, void **pobject) |
| 98 | { |
| 99 | struct nouveau_subdev *subdev; |
| 100 | int ret; |
| 101 | |
| 102 | ret = nouveau_object_create_(parent, engine, oclass, pclass | |
| 103 | NV_SUBDEV_CLASS, size, pobject); |
| 104 | subdev = *pobject; |
| 105 | if (ret) |
| 106 | return ret; |
| 107 | |
| 108 | __mutex_init(&subdev->mutex, subname, &oclass->lock_class_key); |
| 109 | subdev->name = subname; |
| 110 | |
| 111 | if (parent) { |
| 112 | struct nouveau_device *device = nv_device(parent); |
| 113 | subdev->debug = nouveau_dbgopt(device->dbgopt, subname); |
| 114 | #ifdef __NetBSD__ |
| 115 | subdev->mmiot = nv_subdev(device)->mmiot; |
| 116 | subdev->mmioh = nv_subdev(device)->mmioh; |
| 117 | subdev->mmiosz = nv_subdev(device)->mmiosz; |
| 118 | #else |
| 119 | subdev->mmio = nv_subdev(device)->mmio; |
| 120 | #endif |
| 121 | } |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |