Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2018 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  */
0022 #include "priv.h"
0023 
0024 #include <core/memory.h>
0025 #include <subdev/mmu.h>
0026 
0027 #include <nvif/clb069.h>
0028 #include <nvif/unpack.h>
0029 
0030 static int
0031 nvkm_ufault_map(struct nvkm_object *object, void *argv, u32 argc,
0032         enum nvkm_object_map *type, u64 *addr, u64 *size)
0033 {
0034     struct nvkm_fault_buffer *buffer = nvkm_fault_buffer(object);
0035     struct nvkm_device *device = buffer->fault->subdev.device;
0036     *type = NVKM_OBJECT_MAP_IO;
0037     *addr = device->func->resource_addr(device, 3) + buffer->addr;
0038     *size = nvkm_memory_size(buffer->mem);
0039     return 0;
0040 }
0041 
0042 static int
0043 nvkm_ufault_ntfy(struct nvkm_object *object, u32 type,
0044          struct nvkm_event **pevent)
0045 {
0046     struct nvkm_fault_buffer *buffer = nvkm_fault_buffer(object);
0047     if (type == NVB069_V0_NTFY_FAULT) {
0048         *pevent = &buffer->fault->event;
0049         return 0;
0050     }
0051     return -EINVAL;
0052 }
0053 
0054 static int
0055 nvkm_ufault_fini(struct nvkm_object *object, bool suspend)
0056 {
0057     struct nvkm_fault_buffer *buffer = nvkm_fault_buffer(object);
0058     buffer->fault->func->buffer.fini(buffer);
0059     return 0;
0060 }
0061 
0062 static int
0063 nvkm_ufault_init(struct nvkm_object *object)
0064 {
0065     struct nvkm_fault_buffer *buffer = nvkm_fault_buffer(object);
0066     buffer->fault->func->buffer.init(buffer);
0067     return 0;
0068 }
0069 
0070 static void *
0071 nvkm_ufault_dtor(struct nvkm_object *object)
0072 {
0073     return NULL;
0074 }
0075 
0076 static const struct nvkm_object_func
0077 nvkm_ufault = {
0078     .dtor = nvkm_ufault_dtor,
0079     .init = nvkm_ufault_init,
0080     .fini = nvkm_ufault_fini,
0081     .ntfy = nvkm_ufault_ntfy,
0082     .map = nvkm_ufault_map,
0083 };
0084 
0085 int
0086 nvkm_ufault_new(struct nvkm_device *device, const struct nvkm_oclass *oclass,
0087         void *argv, u32 argc, struct nvkm_object **pobject)
0088 {
0089     union {
0090         struct nvif_clb069_v0 v0;
0091     } *args = argv;
0092     struct nvkm_fault *fault = device->fault;
0093     struct nvkm_fault_buffer *buffer = fault->buffer[fault->func->user.rp];
0094     int ret = -ENOSYS;
0095 
0096     if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) {
0097         args->v0.entries = buffer->entries;
0098         args->v0.get = buffer->get;
0099         args->v0.put = buffer->put;
0100     } else
0101         return ret;
0102 
0103     nvkm_object_ctor(&nvkm_ufault, oclass, &buffer->object);
0104     *pobject = &buffer->object;
0105     return 0;
0106 }