/** * \file drm_proc.c * /proc support for DRM * * \author Rickard E. (Rik) Faith * \author Gareth Hughes * * \par Acknowledgements: * Matthew J Sottek sent in a patch to fix * the problem with the proc files not outputting all their information. */ /* * Created: Mon Jan 11 09:48:47 1999 by faith@valinux.com * * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. * All Rights Reserved. * * 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 (including the next * paragraph) 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 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS 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. */ #include "drmP.h" static int drm_name_info(char *buf, char **start, off_t offset, int request, int *eof, void *data); static int drm_vm_info(char *buf, char **start, off_t offset, int request, int *eof, void *data); static int drm_clients_info(char *buf, char **start, off_t offset, int request, int *eof, void *data); static int drm_queues_info(char *buf, char **start, off_t offset, int request, int *eof, void *data); static int drm_bufs_info(char *buf, char **start, off_t offset, int request, int *eof, void *data); static int drm_objects_info(char *buf, char **start, off_t offset, int request, int *eof, void *data); static int drm_gem_name_info(char *buf, char **start, off_t offset, int request, int *eof, void *data); static int drm_gem_object_info(char *buf, char **start, off_t offset, int request, int *eof, void *data); #if DRM_DEBUG_CODE static int drm_vma_info(char *buf, char **start, off_t offset, int request, int *eof, void *data); #endif /** * Proc file list. */ static struct drm_proc_list { const char *name; /**< file name */ int (*f) (char *, char **, off_t, int, int *, void *); /**< proc callback*/ } drm_proc_list[] = { {"name", drm_name_info}, {"mem", drm_mem_info}, {"vm", drm_vm_info}, {"clients", drm_clients_info}, {"queues", drm_queues_info}, {"bufs", drm_bufs_info}, {"objects", drm_objects_info}, {"gem_names", drm_gem_name_info}, {"gem_objects", drm_gem_object_info}, #if DRM_DEBUG_CODE {"vma", drm_vma_info}, #endif }; #define DRM_PROC_ENTRIES ARRAY_SIZE(drm_proc_list) /** * Initialize the DRI proc filesystem for a device. * * \param dev DRM device. * \param minor device minor number. * \param root DRI proc dir entry. * \param dev_root resulting DRI device proc dir entry. * \return root entry pointer on success, or NULL on failure. * * Create the DRI proc root entry "/proc/dri", the device proc root entry * "/proc/dri/%minor%/", and each entry in proc_list as * "/proc/dri/%minor%/%name%". */ int drm_proc_init(struct drm_minor *minor, int minor_id, struct proc_dir_entry *root) { struct proc_dir_entry *ent; int i, j; char name[64]; sprintf(name, "%d", minor_id); minor->dev_root = proc_mkdir(name, root); if (!minor->dev_root) { DRM_ERROR("Cannot create /proc/dri/%s\n", name); return -1; } for (i = 0; i < DRM_PROC_ENTRIES; i++) { ent = create_proc_entry(drm_proc_list[i].name, S_IFREG | S_IRUGO, minor->dev_root); if (!ent) { DRM_ERROR("Cannot create /proc/dri/%s/%s\n", name, drm_proc_list[i].name); for (j = 0; j < i; j++) remove_proc_entry(drm_proc_list[i].name, minor->dev_root); remove_proc_entry(name, root); minor->dev_root = NULL; return -1; } ent->read_proc = drm_proc_list[i].f; ent->data = minor; } return 0; } /** * Cleanup the proc filesystem resources. * * \param minor device minor number. * \param root DRI proc dir entry. * \param dev_root DRI device proc dir entry. * \return always zero. * * Remove all proc entries created by proc_init(). */ int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root) { int i; char name[64]; if (!root || !minor->dev_root) return 0; for (i = 0; i < DRM_PROC_ENTRIES; i++) remove_proc_entry(drm_proc_list[i].name, minor->dev_root); sprintf(name, "%d", minor->index); remove_proc_entry(name, root); return 0; } /** * Called when "/proc/dri/.../name" is read. * * \param buf output buffer. * \param start start of output data. * \param offset requested start offset. * \param request requested number of bytes. * \param eof whether there is no more data to return. * \param data private data. * \return number of written bytes. * * Prints the device name together with the bus id if available. */ static int drm_name_info(char *buf, char **start, off_t offset, int request, int *eof, void *data) { struct drm_minor *minor = (struct drm_minor *) data; struct drm_device *dev = minor->dev; int len = 0; if (offset > DRM_PROC_LIMIT) { *eof = 1; return 0; } *start = &buf[offset]; *eof = 0; if (dev->unique) { DRM_PROC_PRINT("%s %s %s\n", dev->driver->pci_driver.name, pci_name(dev->pdev), dev->unique); } else { DRM_PROC_PRINT("%s %s\n", dev->driver->pci_driver.name, pci_name(dev->pdev)); } if (len > request + offset) return request; *eof = 1; return len - offset; } /** * Called when "/proc/dri/.../vm" is read. * * \param buf output buffer. * \param start start of output data. * \param offset requested start offset. * \param request requested number of bytes. * \param eof whether there is no more data to return. * \param data private data. * \return number of written bytes. * * Prints information about all mappings in drm_device::maplist. */ static int drm__vm_info(char *buf, char **start, off_t offset, int request, int *eof, void *data) { struct drm_minor *minor = (struct drm_minor *) data; struct drm_device *dev = minor->dev; int len = 0; struct drm_map *map; struct drm_map_list *r_list; /* Hardcoded from _DRM_FRAME_BUFFER, _DRM_REGISTERS, _DRM/* * Copyright (C) 2007 Ben Skeggs. * All Rights Reserved. * * 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 (including the * next paragraph) 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 COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS 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. * */ #include "drmP.h" #include "drm.h" #include "nouveau_drv.h" #include "nouveau_dma.h" static int nouveau_fence_has_irq(struct drm_device *dev, uint32_t class, uint32_t flags) { struct drm_nouveau_private *dev_priv = dev->dev_private; DRM_DEBUG("class=%d, flags=0x%08x\n", class, flags); /* DRM's channel always uses IRQs to signal fences */ if (class == dev_priv->channel.chan->id) return 1; /* Other channels don't use IRQs at all yet */ return 0; } static int nouveau_fence_emit(struct drm_device *dev, uint32_t class, uint32_t flags, uint32_t *breadcrumb, uint32_t *native_type) { struct drm_nouveau_private *dev_priv = dev->dev_private; struct nouveau_channel *chan = dev_priv->fifos[class]; struct nouveau_drm_channel *dchan = &dev_priv->channel; DRM_DEBUG("class=%d, flags=0x%08x\n", class, flags); /* We can't emit fences on client channels, update sequence number * and userspace will emit the fence */ *breadcrumb = ++chan->next_sequence; *native_type = DRM_FENCE_TYPE_EXE; if (chan != dchan->chan) { DRM_DEBUG("user fence 0x%08x\n", *breadcrumb); return 0; } DRM_DEBUG("emit 0x%08x\n", *breadcrumb); BEGIN_RING(NvSubM2MF, NV_MEMORY_TO_MEMORY_FORMAT_SET_REF, 1); OUT_RING (*breadcrumb); BEGIN_RING(NvSubM2MF, 0x0150, 1); OUT_RING (0); FIRE_RING (); return 0; } static void nouveau_fence_poll(struct drm_device *dev, uint32_t class, uint32_t waiting_types) { struct drm_nouveau_private *dev_priv = dev->dev_private; struct drm_fence_class_manager *fc = &dev->fm.fence_class[class]; struct nouveau_channel *chan = dev_priv->fifos[class]; DRM_DEBUG("class=%d\n", class); DRM_DEBUG("pending: 0x%08x 0x%08x\n", waiting_types, fc->waiting_types); if (waiting_types & DRM_FENCE_TYPE_EXE) { uint32_t sequence = NV_READ(chan->ref_cnt); DRM_DEBUG("got 0x%08x\n", sequence); drm_fence_handler(dev, class, sequence, waiting_types, 0); } } void nouveau_fence_handler(struct drm_device *dev, int channel) { struct drm_fence_manager *fm = &dev->fm; struct drm_fence_class_manager *fc = &fm->fence_class[channel]; DRM_DEBUG("class=%d\n", channel); write_lock(&fm->lock); nouveau_fence_poll(dev, channel, fc->waiting_types); write_unlock(&fm->lock); } struct drm_fence_driver nouveau_fence_driver = { .num_classes = 8, .wrap_diff = (1 << 30), .flush_diff = (1 << 29), .sequence_mask = 0xffffffffU, .has_irq = nouveau_fence_has_irq, .emit = nouveau_fence_emit, .flush = NULL, .poll = nouveau_fence_poll, .needed_flush = NULL, .wait = NULL };