Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: MIT */
0002 #ifndef __NOUVEAU_DRV_H__
0003 #define __NOUVEAU_DRV_H__
0004 
0005 #define DRIVER_AUTHOR       "Nouveau Project"
0006 #define DRIVER_EMAIL        "nouveau@lists.freedesktop.org"
0007 
0008 #define DRIVER_NAME     "nouveau"
0009 #define DRIVER_DESC     "nVidia Riva/TNT/GeForce/Quadro/Tesla/Tegra K1+"
0010 #define DRIVER_DATE     "20120801"
0011 
0012 #define DRIVER_MAJOR        1
0013 #define DRIVER_MINOR        3
0014 #define DRIVER_PATCHLEVEL   1
0015 
0016 /*
0017  * 1.1.1:
0018  *  - added support for tiled system memory buffer objects
0019  *      - added support for NOUVEAU_GETPARAM_GRAPH_UNITS on [nvc0,nve0].
0020  *      - added support for compressed memory storage types on [nvc0,nve0].
0021  *      - added support for software methods 0x600,0x644,0x6ac on nvc0
0022  *        to control registers on the MPs to enable performance counters,
0023  *        and to control the warp error enable mask (OpenGL requires out of
0024  *        bounds access to local memory to be silently ignored / return 0).
0025  * 1.1.2:
0026  *      - fixes multiple bugs in flip completion events and timestamping
0027  * 1.2.0:
0028  *  - object api exposed to userspace
0029  *  - fermi,kepler,maxwell zbc
0030  * 1.2.1:
0031  *      - allow concurrent access to bo's mapped read/write.
0032  * 1.2.2:
0033  *      - add NOUVEAU_GEM_DOMAIN_COHERENT flag
0034  * 1.3.0:
0035  *      - NVIF ABI modified, safe because only (current) users are test
0036  *        programs that get directly linked with NVKM.
0037  * 1.3.1:
0038  *      - implemented limited ABI16/NVIF interop
0039  */
0040 
0041 #include <linux/notifier.h>
0042 
0043 #include <nvif/client.h>
0044 #include <nvif/device.h>
0045 #include <nvif/ioctl.h>
0046 #include <nvif/mmu.h>
0047 #include <nvif/vmm.h>
0048 
0049 #include <drm/drm_connector.h>
0050 #include <drm/drm_device.h>
0051 #include <drm/drm_drv.h>
0052 #include <drm/drm_file.h>
0053 
0054 #include <drm/ttm/ttm_bo_api.h>
0055 #include <drm/ttm/ttm_bo_driver.h>
0056 #include <drm/ttm/ttm_placement.h>
0057 
0058 #include <drm/drm_audio_component.h>
0059 
0060 #include "uapi/drm/nouveau_drm.h"
0061 
0062 struct nouveau_channel;
0063 struct platform_device;
0064 
0065 #include "nouveau_fence.h"
0066 #include "nouveau_bios.h"
0067 #include "nouveau_vmm.h"
0068 
0069 struct nouveau_drm_tile {
0070     struct nouveau_fence *fence;
0071     bool used;
0072 };
0073 
0074 enum nouveau_drm_object_route {
0075     NVDRM_OBJECT_NVIF = NVIF_IOCTL_V0_OWNER_NVIF,
0076     NVDRM_OBJECT_USIF,
0077     NVDRM_OBJECT_ABI16,
0078     NVDRM_OBJECT_ANY = NVIF_IOCTL_V0_OWNER_ANY,
0079 };
0080 
0081 enum nouveau_drm_notify_route {
0082     NVDRM_NOTIFY_NVIF = 0,
0083     NVDRM_NOTIFY_USIF
0084 };
0085 
0086 enum nouveau_drm_handle {
0087     NVDRM_CHAN    = 0xcccc0000, /* |= client chid */
0088     NVDRM_NVSW    = 0x55550000,
0089 };
0090 
0091 struct nouveau_cli {
0092     struct nvif_client base;
0093     struct nouveau_drm *drm;
0094     struct mutex mutex;
0095 
0096     struct nvif_device device;
0097     struct nvif_mmu mmu;
0098     struct nouveau_vmm vmm;
0099     struct nouveau_vmm svm;
0100     const struct nvif_mclass *mem;
0101 
0102     struct list_head head;
0103     void *abi16;
0104     struct list_head objects;
0105     char name[32];
0106 
0107     struct work_struct work;
0108     struct list_head worker;
0109     struct mutex lock;
0110 };
0111 
0112 struct nouveau_cli_work {
0113     void (*func)(struct nouveau_cli_work *);
0114     struct nouveau_cli *cli;
0115     struct list_head head;
0116 
0117     struct dma_fence *fence;
0118     struct dma_fence_cb cb;
0119 };
0120 
0121 void nouveau_cli_work_queue(struct nouveau_cli *, struct dma_fence *,
0122                 struct nouveau_cli_work *);
0123 
0124 static inline struct nouveau_cli *
0125 nouveau_cli(struct drm_file *fpriv)
0126 {
0127     return fpriv ? fpriv->driver_priv : NULL;
0128 }
0129 
0130 #include <nvif/object.h>
0131 #include <nvif/parent.h>
0132 
0133 struct nouveau_drm {
0134     struct nvif_parent parent;
0135     struct nouveau_cli master;
0136     struct nouveau_cli client;
0137     struct drm_device *dev;
0138 
0139     struct list_head clients;
0140 
0141     /**
0142      * @clients_lock: Protects access to the @clients list of &struct nouveau_cli.
0143      */
0144     struct mutex clients_lock;
0145 
0146     u8 old_pm_cap;
0147 
0148     struct {
0149         struct agp_bridge_data *bridge;
0150         u32 base;
0151         u32 size;
0152         bool cma;
0153     } agp;
0154 
0155     /* TTM interface support */
0156     struct {
0157         struct ttm_device bdev;
0158         atomic_t validate_sequence;
0159         int (*move)(struct nouveau_channel *,
0160                 struct ttm_buffer_object *,
0161                 struct ttm_resource *, struct ttm_resource *);
0162         struct nouveau_channel *chan;
0163         struct nvif_object copy;
0164         int mtrr;
0165         int type_vram;
0166         int type_host[2];
0167         int type_ncoh[2];
0168         struct mutex io_reserve_mutex;
0169         struct list_head io_reserve_lru;
0170     } ttm;
0171 
0172     /* GEM interface support */
0173     struct {
0174         u64 vram_available;
0175         u64 gart_available;
0176     } gem;
0177 
0178     /* synchronisation */
0179     void *fence;
0180 
0181     /* Global channel management. */
0182     struct {
0183         int nr;
0184         u64 context_base;
0185     } chan;
0186 
0187     /* context for accelerated drm-internal operations */
0188     struct nouveau_channel *cechan;
0189     struct nouveau_channel *channel;
0190     struct nvkm_gpuobj *notify;
0191     struct nouveau_fbdev *fbcon;
0192     struct nvif_object ntfy;
0193 
0194     /* nv10-nv40 tiling regions */
0195     struct {
0196         struct nouveau_drm_tile reg[15];
0197         spinlock_t lock;
0198     } tile;
0199 
0200     /* modesetting */
0201     struct nvbios vbios;
0202     struct nouveau_display *display;
0203     struct work_struct hpd_work;
0204     struct mutex hpd_lock;
0205     u32 hpd_pending;
0206     struct work_struct fbcon_work;
0207     int fbcon_new_state;
0208 #ifdef CONFIG_ACPI
0209     struct notifier_block acpi_nb;
0210 #endif
0211 
0212     /* power management */
0213     struct nouveau_hwmon *hwmon;
0214     struct nouveau_debugfs *debugfs;
0215 
0216     /* led management */
0217     struct nouveau_led *led;
0218 
0219     struct dev_pm_domain vga_pm_domain;
0220 
0221     struct nouveau_svm *svm;
0222 
0223     struct nouveau_dmem *dmem;
0224 
0225     struct {
0226         struct drm_audio_component *component;
0227         struct mutex lock;
0228         bool component_registered;
0229     } audio;
0230 };
0231 
0232 static inline struct nouveau_drm *
0233 nouveau_drm(struct drm_device *dev)
0234 {
0235     return dev->dev_private;
0236 }
0237 
0238 static inline bool
0239 nouveau_drm_use_coherent_gpu_mapping(struct nouveau_drm *drm)
0240 {
0241     struct nvif_mmu *mmu = &drm->client.mmu;
0242     return !(mmu->type[drm->ttm.type_host[0]].type & NVIF_MEM_UNCACHED);
0243 }
0244 
0245 int nouveau_pmops_suspend(struct device *);
0246 int nouveau_pmops_resume(struct device *);
0247 bool nouveau_pmops_runtime(void);
0248 
0249 #include <nvkm/core/tegra.h>
0250 
0251 struct drm_device *
0252 nouveau_platform_device_create(const struct nvkm_device_tegra_func *,
0253                    struct platform_device *, struct nvkm_device **);
0254 void nouveau_drm_device_remove(struct drm_device *dev);
0255 
0256 #define NV_PRINTK(l,c,f,a...) do {                                             \
0257     struct nouveau_cli *_cli = (c);                                        \
0258     dev_##l(_cli->drm->dev->dev, "%s: "f, _cli->name, ##a);                \
0259 } while(0)
0260 
0261 #define NV_FATAL(drm,f,a...) NV_PRINTK(crit, &(drm)->client, f, ##a)
0262 #define NV_ERROR(drm,f,a...) NV_PRINTK(err, &(drm)->client, f, ##a)
0263 #define NV_WARN(drm,f,a...) NV_PRINTK(warn, &(drm)->client, f, ##a)
0264 #define NV_INFO(drm,f,a...) NV_PRINTK(info, &(drm)->client, f, ##a)
0265 
0266 #define NV_DEBUG(drm,f,a...) do {                                              \
0267     if (drm_debug_enabled(DRM_UT_DRIVER))                                  \
0268         NV_PRINTK(info, &(drm)->client, f, ##a);                       \
0269 } while(0)
0270 #define NV_ATOMIC(drm,f,a...) do {                                             \
0271     if (drm_debug_enabled(DRM_UT_ATOMIC))                                  \
0272         NV_PRINTK(info, &(drm)->client, f, ##a);                       \
0273 } while(0)
0274 
0275 #define NV_PRINTK_ONCE(l,c,f,a...) NV_PRINTK(l##_once,c,f, ##a)
0276 
0277 #define NV_ERROR_ONCE(drm,f,a...) NV_PRINTK_ONCE(err, &(drm)->client, f, ##a)
0278 #define NV_WARN_ONCE(drm,f,a...) NV_PRINTK_ONCE(warn, &(drm)->client, f, ##a)
0279 #define NV_INFO_ONCE(drm,f,a...) NV_PRINTK_ONCE(info, &(drm)->client, f, ##a)
0280 
0281 extern int nouveau_modeset;
0282 
0283 #endif