/*******************************************************************************
    Copyright (c) 2013 NVidia Corporation

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to
    deal in the Software without restriction, including without limitation the
    rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    sell copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

        The above copyright notice and this permission notice shall be
        included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    DEALINGS IN THE SOFTWARE.
*******************************************************************************/

//
//     uvmtypes.h
//
//     This file contains basic datatypes that UVM requires.
//

#ifndef _UVMTYPES_H_
#define _UVMTYPES_H_

#include "nvtypes.h"
#include "rmretval.h"
#include "nv_uvm_types.h"

/*******************************************************************************
    UVM stream types
*******************************************************************************/

typedef enum
{
    UvmStreamTypeRegular = 0,
    UvmStreamTypeAll = 1,
    UvmStreamTypeNone = 2
} UvmStreamType;

#define UVM_STREAM_INVALID  ((UvmStream)0ULL)
#define UVM_STREAM_ALL      ((UvmStream)2ULL)
#define UVM_STREAM_NONE     ((UvmStream)3ULL)

typedef unsigned long long UvmStream;

#define UVM_MAX_GPUS         32
#define UVM_MAX_DEVICES      UVM_MAX_GPUS
#define UVM_MAX_SUBDEVICES   8

typedef NvU64 UvmRangeGroupId;

#define UVM_RANGE_GROUP_ID_NONE        ((UvmRangeGroupId)0)

typedef NvProcessorUuid UvmProcessorUuid;

/*******************************************************************************
 * UVM GPU mapping types
 * 
 * These types indicate the kinds of accesses allowed from a given GPU at the
 * specified virtual address range. There are 3 basic kinds of accesses: read,
 * write and atomics. Each type indicates what kinds of accesses are allowed.
 * Accesses of any disallowed kind are fatal.
 ******************************************************************************/

typedef enum
{
    UvmGpuMappingTypeNoAccess = 0,
    UvmGpuMappingTypeReadOnly = 1,
    UvmGpuMappingTypeReadWrite = 2,
    UvmGpuMappingTypeReadWriteAtomics = 3
} UvmGpuMappingType;

/*******************************************************************************
 * UVM GPU caching types
 * 
 * These types indicate the cacheability of the specified virtual address range
 * from a given GPU. The "Default" type specifies that the UVM driver should
 * set caching on or off as required to follow the UVM coherence model. The 
 * "ForceUncached" and "ForceCached" types will always turn caching off or on
 * respectively. These two types override the cacheability specified by the UVM
 * coherence model.
 ******************************************************************************/

typedef enum
{
    UvmGpuCachingTypeDefault = 0,
    UvmGpuCachingTypeForceUncached = 1,
    UvmGpuCachingTypeForceCached = 2
} UvmGpuCachingType;

/*******************************************************************************
 * TODO: Remove these flags and all their references in uvm.h
 * UvmSingleGpuAttribute.gpuAttrFlags notes:
 *
 * If UVM_GPU_ATTRIBUTE_FLAGS_MAPPED is not set for a given GPU's attribute,
 * then you may not set either UVM_GPU_ATTRIBUTE_FLAGS_GPU_CACHEABLE or
 * UVM_GPU_ATTRIBUTE_FLAGS_ATOMICS_ENABLED for that GPU.
 *
 * For the various API calls that accept GPU attributes as an input, these
 * attributes will override any previously set attributes.
 */

#define UVM_GPU_ATTRIBUTE_FLAGS_MAPPED           0x00000001
#define UVM_GPU_ATTRIBUTE_FLAGS_GPU_CACHEABLE    0x00000002
#define UVM_GPU_ATTRIBUTE_FLAGS_ATOMICS_ENABLED  0x00000004
#define UVM_GPU_ATTRIBUTE_FLAGS_READ_ONLY        0x00000008

typedef struct tagUvmGpuAttributes
{
    UvmGpuUuid gpuUuid;
    UvmGpuMappingType gpuMappingType;
    UvmGpuCachingType gpuCachingType;
    NvU32 gpuAttrFlags; // TODO: Remove this
} UvmGpuAttributes;

#endif // _UVMTYPES_H_
