linux/drivers/gpu/drm/nouveau/core/core/client.c
<<
>>
Prefs
   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
  25#include <core/object.h>
  26#include <core/client.h>
  27#include <core/handle.h>
  28#include <core/option.h>
  29
  30#include <engine/device.h>
  31
  32static void
  33nouveau_client_dtor(struct nouveau_object *object)
  34{
  35        struct nouveau_client *client = (void *)object;
  36        nouveau_object_ref(NULL, &client->device);
  37        nouveau_handle_destroy(client->root);
  38        nouveau_namedb_destroy(&client->base);
  39}
  40
  41static struct nouveau_oclass
  42nouveau_client_oclass = {
  43        .ofuncs = &(struct nouveau_ofuncs) {
  44                .dtor = nouveau_client_dtor,
  45        },
  46};
  47
  48int
  49nouveau_client_create_(const char *name, u64 devname, const char *cfg,
  50                       const char *dbg, int length, void **pobject)
  51{
  52        struct nouveau_object *device;
  53        struct nouveau_client *client;
  54        int ret;
  55
  56        device = (void *)nouveau_device_find(devname);
  57        if (!device)
  58                return -ENODEV;
  59
  60        ret = nouveau_namedb_create_(NULL, NULL, &nouveau_client_oclass,
  61                                     NV_CLIENT_CLASS, NULL,
  62                                     (1ULL << NVDEV_ENGINE_DEVICE),
  63                                     length, pobject);
  64        client = *pobject;
  65        if (ret)
  66                return ret;
  67
  68        ret = nouveau_handle_create(nv_object(client), ~0, ~0,
  69                                    nv_object(client), &client->root);
  70        if (ret)
  71                return ret;
  72
  73        /* prevent init/fini being called, os in in charge of this */
  74        atomic_set(&nv_object(client)->usecount, 2);
  75
  76        nouveau_object_ref(device, &client->device);
  77        snprintf(client->name, sizeof(client->name), "%s", name);
  78        client->debug = nouveau_dbgopt(dbg, "CLIENT");
  79        return 0;
  80}
  81
  82int
  83nouveau_client_init(struct nouveau_client *client)
  84{
  85        int ret;
  86        nv_debug(client, "init running\n");
  87        ret = nouveau_handle_init(client->root);
  88        nv_debug(client, "init completed with %d\n", ret);
  89        return ret;
  90}
  91
  92int
  93nouveau_client_fini(struct nouveau_client *client, bool suspend)
  94{
  95        const char *name[2] = { "fini", "suspend" };
  96        int ret;
  97
  98        nv_debug(client, "%s running\n", name[suspend]);
  99        ret = nouveau_handle_fini(client->root, suspend);
 100        nv_debug(client, "%s completed with %d\n", name[suspend], ret);
 101        return ret;
 102}
 103
 104const char *
 105nouveau_client_name(void *obj)
 106{
 107        const char *client_name = "unknown";
 108        struct nouveau_client *client = nouveau_client(obj);
 109        if (client)
 110                client_name = client->name;
 111        return client_name;
 112}
 113