From 5bffbd6e275efffbb649c20c528a11412ccf99cd Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 5 Apr 2007 13:34:50 +1000 Subject: initial userspace interface to get modes --- libdrm/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdrm') diff --git a/libdrm/Makefile.am b/libdrm/Makefile.am index e7e07e47..24c32038 100644 --- a/libdrm/Makefile.am +++ b/libdrm/Makefile.am @@ -23,9 +23,9 @@ libdrm_ladir = $(libdir) libdrm_la_LDFLAGS = -version-number 2:3:0 -no-undefined AM_CFLAGS = -I$(top_srcdir)/shared-core -libdrm_la_SOURCES = xf86drm.c xf86drmHash.c xf86drmRandom.c xf86drmSL.c +libdrm_la_SOURCES = xf86drm.c xf86drmHash.c xf86drmRandom.c xf86drmSL.c xf86drmMode.c libdrmincludedir = ${includedir} -libdrminclude_HEADERS = xf86drm.h xf86mm.h +libdrminclude_HEADERS = xf86drm.h xf86mm.h xf86drmMode.h EXTRA_DIST = ChangeLog TODO -- cgit v1.2.3 From 7bb112fecadc6fe42e5828b861600691071ccd91 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 5 Apr 2007 17:06:42 +1000 Subject: checkpoint commit: added getresources, crtc and output This adds the user interfaces from Jakob and hooks them up for 3 ioctls GetResources, GetCrtc and GetOutput. I've made the ids for everything fbs, crtcs, outputs and modes go via idr as per krh's suggestion on irc as it make the code nice and consistent. --- libdrm/xf86drmMode.c | 407 +++++++++++++++++++++++++++++++++++++++++++++++++++ libdrm/xf86drmMode.h | 290 ++++++++++++++++++++++++++++++++++++ 2 files changed, 697 insertions(+) create mode 100644 libdrm/xf86drmMode.c create mode 100644 libdrm/xf86drmMode.h (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c new file mode 100644 index 00000000..b48ca838 --- /dev/null +++ b/libdrm/xf86drmMode.c @@ -0,0 +1,407 @@ +/* + * \file xf86drmMode.c + * Header for DRM modesetting interface. + * + * \author Jakob Bornecrantz + * + * \par Acknowledgements: + * Feb 2007, Dave Airlie + */ + +/* + * Copyright (c) + * + * 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. + * + */ + +/* + * TODO the types we are after are defined in diffrent headers on diffrent + * platforms find which headers to include to get uint32_t + */ +#include + +#include "xf86drmMode.h" +#include "xf86drm.h" +#include + +/* + * Util functions + */ + +void* drmAllocCpy(void *array, int count, int entry_size) +{ + char *r; + int i; + + if (!count || !array || !entry_size) + return 0; + + if (!(r = drmMalloc(count*entry_size))) + return 0; + + for (i = 0; i < count; i++) + memcpy(r+(entry_size*i), array+(entry_size*i), entry_size); + + return r; +} + +/** + * Generate crtc and output ids. + * + * Will generate ids starting from 1 up to count if count is greater then 0. + */ +static uint32_t* drmAllocGenerate(int count) +{ + uint32_t *r; + int i; + + if(0 <= count) + return 0; + + if (!(r = drmMalloc(count*sizeof(*r)))) + return 0; + + for (i = 0; i < count; r[i] = ++i); + + return 0; +} + +/* + * A couple of free functions. + */ + +void drmModeFreeModeInfo(struct drm_mode_modeinfo *ptr) +{ + if (!ptr) + return; + + drmFree(ptr); +} + +void drmModeFreeResources(drmModeResPtr ptr) +{ + if (!ptr) + return; + + drmFree(ptr->modes); + drmFree(ptr); + +} + +void drmModeFreeFrameBuffer(drmModeFrameBufferPtr ptr) +{ + if (!ptr) + return; + + /* we might add more frees later. */ + drmFree(ptr); +} + +void drmModeFreeCrtc(drmModeCrtcPtr ptr) +{ + if (!ptr) + return; + + drmFree(ptr); + +} + +void drmModeFreeOutput(drmModeOutputPtr ptr) +{ + if (!ptr) + return; + + drmFree(ptr->modes); + drmFree(ptr); + +} + +/* + * ModeSetting functions. + */ + +drmModeResPtr drmModeGetResources(int fd) +{ + struct drm_mode_card_res res; + int i; + drmModeResPtr r = 0; + + res.count_crtcs = 0; + res.count_outputs = 0; + res.count_modes = 0; + res.modes = 0; + + if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res)) + return 0; + + if (res.count_crtcs) + res.crtc_id = drmMalloc(res.count_crtcs*sizeof(uint32_t)); + if (res.count_outputs) + res.output_id = drmMalloc(res.count_outputs*sizeof(uint32_t)); + if (res.count_modes) + res.modes = drmMalloc(res.count_modes*sizeof(*res.modes)); + + if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res)) + goto err_allocs; + + /* + * return + */ + + + if (!(r = drmMalloc(sizeof(*r)))) + return 0; + + r->frameBufferId = res.fb_id; + r->count_crtcs = res.count_crtcs; + r->count_outputs = res.count_outputs; + r->count_modes = res.count_modes; + /* TODO we realy should test if these allocs fails. */ + r->crtcs = drmAllocCpy(res.crtc_id, res.count_crtcs, sizeof(uint32_t)); + r->outputs = drmAllocCpy(res.output_id, res.count_outputs, sizeof(uint32_t)); + r->modes = drmAllocCpy(res.modes, res.count_modes, sizeof(struct drm_mode_modeinfo)); + + drmFree(res.crtc_id); + drmFree(res.output_id); + drmFree(res.modes); + + return r; + +err_allocs: + drmFree(res.crtc_id); + drmFree(res.output_id); + drmFree(res.modes); + + return 0; +} + +#if 0 +int drmModeForceProbe(int fd, uint32_t outputId) +{ + /* TODO impl/keep? */ +} + +drmModeFrameBufferPtr drmModeGetFrameBuffer(int fd, uint32_t buf) +{ +// struct drm_mode_fb_cmd info; + drmModeFrameBufferPtr r; + + // if (ioctl(fd, DRM_IOCTL_MODE_GETFRAMEBUFFER, &info)) + return 0; + + if (!(r = drmMalloc(sizeof(*r)))) + return 0; + + /* TODO change to new code + r->minWidth = info.minWidth; + r->maxWidth = info.maxWidth; + r->minHeight = info.minHeight; + r->maxHeight = info.maxHeight;*/ + + return r; +} + +uint32_t drmModeNewFrameBuffer(int fd, uint32_t width, uint32_t height, + uint8_t bpp, uint32_t pitch, drmBO *bo) +{ + drm_mode_fb_cmd_t f; + + f.handle = bo->handle; + f.width = width; + f.height = height; + f.pitch = pitch; + + // if (ioctl(fd, DRM_IOCTL_MODE_NEWFRAMEBUFFER, &f)) + return 0; + + return f.bufferId; +} + +int drmModeDesFrameBuffer(int fd, uint32_t bufferId) +{ + // return ioctl(fd, DRM_IOCTL_MODE_DESFRAMEBUFFER, bufferId); +} + +#endif +/* + * Crtc function. + */ + +drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId) +{ + struct drm_mode_crtc crtc; + drmModeCrtcPtr r; + int i = 0; + + crtc.count_outputs = 0; + crtc.outputs = 0; + crtc.count_possibles = 0; + crtc.possibles = 0; + crtc.crtc_id = crtcId; + + if (ioctl(fd, DRM_IOCTL_MODE_GETCRTC, &crtc)) + return 0; + + /* + * return + */ + + if (!(r = drmMalloc(sizeof(*r)))) + return 0; + + r->x = crtc.x; + r->y = crtc.y; + r->mode = crtc.mode; +// r->width = crtc.width; +// r->height = crtc.height; + r->bufferId = crtc.fb_id; + r->gamma_size = crtc.gamma_size; + r->count_outputs = crtc.count_outputs; + r->count_possibles = crtc.count_possibles; + /* TODO we realy should test if these alloc & cpy fails. */ + r->outputs = crtc.outputs; + r->possibles = crtc.possibles; + + return r; + +err_allocs: + + return 0; +} + +#if 0 +int drmModeSetCrtc( + int fd, uint32_t crtcId, uint32_t bufferId, + uint32_t x, uint32_t y, uint32_t modeId, + uint32_t *outputs, int count + ) +{ + struct drm_mode_crtc crtc; + + crtc.count_outputs = 0; + crtc.outputs = 0; + crtc.count_possibles = 0; + crtc.possibles = 0; + + crtc.x = x; + crtc.y = y; + crtc.crtcId = crtcId; + crtc.bufferId = bufferId; + crtc.set_outputs = outputs; + crtc.count_outputs = count; + crtc.mode = modeId; + + // return ioctl(fd, DRM_IOCTL_MODE_SETCRTC, &crtc); +} + +drmModeGammaTriplePtr drmModeGetCrtcGamma(int fd, uint32_t crtc, int *count) +{ + /* TODO impl */ +} + +int drmModeSetCrtcGamma(int fd, uint32_t crtcId, + drmModeGammaTriplePtr ptr, int count) +{ + /* TODO impl */ +} + +#endif +/* + * Output manipulation + */ +drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) +{ + struct drm_mode_get_output out; + drmModeOutputPtr r = 0; + + out.output = output_id; + out.count_crtcs = 0; + out.crtcs = 0; + out.count_clones = 0; + out.clones = 0; + out.count_modes = 0; + out.modes = 0; + + if (ioctl(fd, DRM_IOCTL_MODE_GETOUTPUT, &out)) + return 0; + + if (out.count_modes) + out.modes = drmMalloc(out.count_modes*sizeof(uint32_t)); + + if (ioctl(fd, DRM_IOCTL_MODE_GETOUTPUT, &out)) + goto err_allocs; + + if(!(r = drmMalloc(sizeof(*r)))) + return 0; + + r->connection = out.connection; + r->mmWidth = out.mm_width; + r->mmHeight = out.mm_height; + r->subpixel = out.subpixel; + r->count_crtcs = out.count_crtcs; + r->count_clones = out.count_clones; + r->count_modes = out.count_modes; + /* TODO we should test if these alloc & cpy fails. */ + r->crtcs = out.crtcs; + r->clones = out.clones; + r->modes = drmAllocCpy(out.modes, out.count_modes, sizeof(uint32_t)); + + return r; + +err_allocs: + drmFree(out.modes); + + return 0; +} + +#if 0 +uint32_t drmModeNewMode(int fd, struct drm_mode_modeinfo *modeInfo) +{ + /* TODO impl */ +} + +int drmModeDesMode(int fd, uint32_t modeId) +{ + // return ioctl(fd, DRM_IOCTL_MODE_DESMODE, modeId); +} + +int drmModeAddMode(int fd, uint32_t outputId, uint32_t modeId) +{ + + drm_mode_outputmode_t res; + + res.outputId = outputId; + res.modeId = modeId; + + // return ioctl(fd, DRM_IOCTL_MODE_ADDMODE, &res); +} + +int drmModeDelMode(int fd, uint32_t outputId, uint32_t modeId) +{ + drm_mode_outputmode_t res; + + res.outputId = outputId; + res.modeId = modeId; + + // return ioctl(fd, DRM_IOCTL_MODE_DELMODE, &res); +} + +#endif + diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h new file mode 100644 index 00000000..c027a16d --- /dev/null +++ b/libdrm/xf86drmMode.h @@ -0,0 +1,290 @@ +/* + * \file xf86drmMode.h + * Header for DRM modesetting interface. + * + * \author Jakob Bornecrantz + * + * \par Acknowledgements: + * Feb 2007, Dave Airlie + */ + +/* + * Copyright (c) + * + * 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. + * + */ + +#include +#include "xf86mm.h" + +/* + * This is the interface for modesetting for drm. + * + * In order to use this interface you must include either or another + * header defining uint32_t, int32_t and uint16_t. + * + * It aims to provide a randr compatible interface for modesettings in the + * kernel, the interface is also ment to be used by libraries like EGL. + * + * More information can be found in randrproto.txt which can be found here: + * http://gitweb.freedesktop.org/?p=xorg/proto/randrproto.git + * + * All framebuffer, crtc and output ids start at 1 while 0 is either an invalid + * parameter or used to indicate that the command should disconnect from the + * currently bound target, as with drmModeMapOutput. + * + * Currently only one framebuffer exist and has a id of 1, which is also the + * default framebuffer and should allways be avaible to the client, unless + * it is locked/used or any other limiting state is applied on it. + * + */ + +typedef struct _drmModeGammaTriple { + uint16_t r, g, b; +} drmModeGammaTriple, *drmModeGammaTriplePtr; + +typedef struct _drmModeRes { + + uint32_t frameBufferId; + + int count_crtcs; + uint32_t *crtcs; + + int count_outputs; + uint32_t *outputs; + + int count_modes; + struct drm_mode_modeinfo *modes; + +} drmModeRes, *drmModeResPtr; + +typedef struct _drmModeFrameBuffer { + + uint32_t minWidth, maxWidth; + uint32_t minHeight, maxHeight; + +} drmModeFrameBuffer, *drmModeFrameBufferPtr; + +typedef struct _drmModeCrtc { + + unsigned int bufferId; /**< Buffer currently connected to */ + + uint32_t x, y; /**< Position on the frameuffer */ + uint32_t width, height; + uint32_t mode; /**< Current mode used */ + + int count_outputs; + uint32_t outputs; /**< Outputs that are connected */ + + int count_possibles; + uint32_t possibles; /**< Outputs that can be connected */ + + int gamma_size; /**< Number of gamma stops */ + +} drmModeCrtc, *drmModeCrtcPtr; + +typedef enum { + DRM_MODE_CONNECTED = 1, + DRM_MODE_DISCONNECTED = 2, + DRM_MODE_UNKNOWNCONNECTION = 3 +} drmModeConnection; + +typedef enum { + DRM_MODE_SUBPIXEL_UNKNOWN = 1, + DRM_MODE_SUBPIXEL_HORIZONTAL_RGB = 2, + DRM_MODE_SUBPIXEL_HORIZONTAL_BGR = 3, + DRM_MODE_SUBPIXEL_VERTICAL_RGB = 4, + DRM_MODE_SUBPIXEL_VERTICAL_BGR = 5, + DRM_MODE_SUBPIXEL_NONE = 6 +} drmModeSubPixel; + +typedef struct _drmModeOutput { + + unsigned int crtc; /**< Crtc currently connected to */ + + drmModeConnection connection; + uint32_t mmWidth, mmHeight; /**< HxW in millimeters */ + drmModeSubPixel subpixel; + + int count_crtcs; + uint32_t crtcs; /**< Possible crtc to connect to */ + + int count_clones; + uint32_t clones; /**< Mask of clones */ + + int count_modes; + uint32_t *modes; /**< List of modes ids */ + +} drmModeOutput, *drmModeOutputPtr; + +/* + * RRSetScreenConfig o + * RRGetScreenInfo o + * + * RRGetScreenSizeRange - see frameBuffer info + * RRSetScreenSize + * RRGetScreenResources + * + * RRGetOutputInfo + * + * RRListOutputProperties * + * RRQueryOutputProperty * + * RRConfigureOutputProperty * + * RRChangeOutputProperty * + * RRDeleteOutputProperty * + * RRGetOutputProperty * + * + * RRCreateMode + * RRDestroyMode + * RRAddOutputMode + * RRDeleteOutputMode + * + * RRGetCrtcInfo + * RRSetCrtcConfig + * + * RRGetCrtcGammaSize - see crtc info + * RRGetCrtcGamma + * RRSetCrtcGamma + * + * drmModeGetResources + * drmModeForceProbe + * + * drmModeGetFrameBufferInfo + * drmModeSetFrameBufferSize + * + * drmModeGetCrtcInfo + * drmModeSetCrtcConfig + * drmModeGetCrtcGamma + * drmModeSetCrtcGamma + * + * drmModeGetOutputInfo + * + * drmModeAddMode + * drmModeDestroyMode + * drmModeAddOutputMode + * drmModeDeleteOutputMode + */ + +extern void drmModeFreeModeInfo( struct drm_mode_modeinfo *ptr ); +extern void drmModeFreeResources( drmModeResPtr ptr ); +extern void drmModeFreeFrameBuffer( drmModeFrameBufferPtr ptr ); +extern void drmModeFreeCrtc( drmModeCrtcPtr ptr ); +extern void drmModeFreeOutput( drmModeOutputPtr ptr ); + +/** + * Retrives all of the resources associated with a card. + */ +extern drmModeResPtr drmModeGetResources(int fd); + +/** + * Forces a probe of the give output outputId, on 0 all will be probed. + */ +extern int drmModeForceProbe(int fd, uint32_t outputId); + + +/* + * FrameBuffer manipulation. + */ + +/** + * Retrive information about framebuffer bufferId + */ +extern drmModeFrameBufferPtr drmModeGetFramebuffer(int fd, + uint32_t bufferId); + +/** + * Creates a new framebuffer with an buffer object as its scanout buffer. + */ +extern uint32_t drmModeNewFrameBuffer(int fd, + uint32_t width, uint32_t height, + uint8_t bbp, uint32_t pitch, drmBO *bo); + +/** + * Destroies the given framebuffer. + */ +extern int drmModeDesFrameBuffer(int fd, uint32_t bufferId); + +/** + * Changes the scanout buffer to the given buffer object. + */ +extern int drmModeFlipFrameBuffer(int fd, uint32_t bufferId, drmBO *bo); + +/* + * Crtc function. + */ + +/** + * Retrive information about the ctrt crtcId + */ +extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId); + +/** + * Set the mode on a crtc crtcId with the given mode modeId. + */ +extern int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, + uint32_t x, uint32_t y, uint32_t modeId, + uint32_t *outputs, int count); + +/** + * Gets the gamma from a crtc + */ +extern drmModeGammaTriplePtr drmModeGetCrtcGamma(int fd, uint32_t crtcId, + int *count); + +/** + * Sets the gamma on a crtc + */ +extern int drmModeSetCrtcGamma(int fd, uint32_t crtcId, + drmModeGammaTriplePtr ptr, int count); + + + +/* + * Output manipulation + */ + +/** + * Retrive information about the output outputId. + */ +extern drmModeOutputPtr drmModeGetOutput(int fd, + uint32_t outputId); + +/** + * Creates a new mode from the given mode info. + * Name must be unique. + */ +extern uint32_t drmModeNewMode(int fd, struct drm_mode_modeinfo *modeInfo); + +/** + * Destroys a mode created with CreateMode, must be unused. + */ +extern int drmModeDesMode(int fd, uint32_t modeId); + +/** + * Adds the given mode to an output. + */ +extern int drmModeAddMode(int fd, uint32_t outputId, uint32_t modeId); + +/** + * Deletes a mode Added with AddOutputMode from the output, + * must be unused, by the given mode. + */ +extern int drmModeDelMode(int fd, uint32_t outputId, uint32_t modeId); + -- cgit v1.2.3 From b4094864f188a1346cc3b51bcb457beeacefbf82 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 5 Apr 2007 18:01:02 +1000 Subject: checkpoint commit: implement SetCrtc so modes can in theory be set from user This hooks up the userspace mode set it "seems" to work. --- libdrm/xf86drmMode.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index b48ca838..c4403b1c 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -286,7 +286,7 @@ err_allocs: return 0; } -#if 0 + int drmModeSetCrtc( int fd, uint32_t crtcId, uint32_t bufferId, uint32_t x, uint32_t y, uint32_t modeId, @@ -302,15 +302,16 @@ int drmModeSetCrtc( crtc.x = x; crtc.y = y; - crtc.crtcId = crtcId; - crtc.bufferId = bufferId; + crtc.crtc_id = crtcId; + crtc.fb_id = bufferId; crtc.set_outputs = outputs; crtc.count_outputs = count; crtc.mode = modeId; - // return ioctl(fd, DRM_IOCTL_MODE_SETCRTC, &crtc); + return ioctl(fd, DRM_IOCTL_MODE_SETCRTC, &crtc); } +#if 0 drmModeGammaTriplePtr drmModeGetCrtcGamma(int fd, uint32_t crtc, int *count) { /* TODO impl */ -- cgit v1.2.3 From b50bda002b824efb24e18e8d514ff0ca763c15b9 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 10 Apr 2007 18:44:47 +1000 Subject: add addfb/rmfb ioctls Originally from Jakob, cleaned up by airlied. --- libdrm/xf86drmMode.c | 22 ++++++++++++++++++++++ libdrm/xf86drmMode.h | 6 ++++-- 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index c4403b1c..55a9d91c 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -192,6 +192,28 @@ err_allocs: return 0; } +uint32_t drmModeAddFB(int fd, uint32_t width, uint32_t height, + uint8_t bpp, uint32_t pitch, drmBO *bo) +{ + struct drm_mode_fb_cmd f; + + f.width = width; + f.height = height; + f.pitch = pitch; + f.bpp = bpp; + f.handle = bo->handle; + + if (ioctl(fd, DRM_IOCTL_MODE_ADDFB, &f)) + return 0; + + return f.buffer_id; +} + +int drmModeRmFB(int fd, uint32_t bufferId) +{ + return ioctl(fd, DRM_IOCTL_MODE_RMFB, bufferId); +} + #if 0 int drmModeForceProbe(int fd, uint32_t outputId) { diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index c027a16d..45b157a8 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -77,8 +77,10 @@ typedef struct _drmModeRes { typedef struct _drmModeFrameBuffer { - uint32_t minWidth, maxWidth; - uint32_t minHeight, maxHeight; + uint32_t width; + uint32_t height; + uint32_t pitch; + uint8_t bpp; } drmModeFrameBuffer, *drmModeFrameBufferPtr; -- cgit v1.2.3 From eb9bdc27879d1aa307b234bbdb0f81494dcf7095 Mon Sep 17 00:00:00 2001 From: David Airlie Date: Tue, 10 Apr 2007 11:51:31 +1000 Subject: mode: fixup problems with framebuffer add function --- libdrm/xf86drmMode.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 55a9d91c..5f480890 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -192,10 +192,11 @@ err_allocs: return 0; } -uint32_t drmModeAddFB(int fd, uint32_t width, uint32_t height, - uint8_t bpp, uint32_t pitch, drmBO *bo) +int drmModeAddFB(int fd, uint32_t width, uint32_t height, + uint8_t bpp, uint32_t pitch, drmBO *bo, uint32_t *buf_id) { struct drm_mode_fb_cmd f; + int ret; f.width = width; f.height = height; @@ -203,10 +204,11 @@ uint32_t drmModeAddFB(int fd, uint32_t width, uint32_t height, f.bpp = bpp; f.handle = bo->handle; - if (ioctl(fd, DRM_IOCTL_MODE_ADDFB, &f)) - return 0; + if (ret = ioctl(fd, DRM_IOCTL_MODE_ADDFB, &f)) + return ret; - return f.buffer_id; + *buf_id = f.buffer_id; + return 0; } int drmModeRmFB(int fd, uint32_t bufferId) -- cgit v1.2.3 From 65f465ed5ad3caf773658bb2832785c963b987f6 Mon Sep 17 00:00:00 2001 From: David Airlie Date: Tue, 10 Apr 2007 14:49:49 +1000 Subject: fixup numerous issues with adding framebuffer support This still isn't perfect but it fixes a few oopses and cleans up some of the tabs and bugs in the original fb limit code --- libdrm/xf86drmMode.c | 8 +++----- libdrm/xf86drmMode.h | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 5f480890..df8ea8ee 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -311,11 +311,9 @@ err_allocs: } -int drmModeSetCrtc( - int fd, uint32_t crtcId, uint32_t bufferId, - uint32_t x, uint32_t y, uint32_t modeId, - uint32_t *outputs, int count - ) +int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, + uint32_t x, uint32_t y, uint32_t modeId, + uint32_t *outputs, int count) { struct drm_mode_crtc crtc; diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 45b157a8..fadfdc5d 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -214,14 +214,12 @@ extern drmModeFrameBufferPtr drmModeGetFramebuffer(int fd, /** * Creates a new framebuffer with an buffer object as its scanout buffer. */ -extern uint32_t drmModeNewFrameBuffer(int fd, - uint32_t width, uint32_t height, - uint8_t bbp, uint32_t pitch, drmBO *bo); - +extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, + uint8_t bpp, uint32_t pitch, drmBO *bo, uint32_t *buf_id); /** * Destroies the given framebuffer. */ -extern int drmModeDesFrameBuffer(int fd, uint32_t bufferId); +extern int drmModeRmFB(int fd, uint32_t bufferId); /** * Changes the scanout buffer to the given buffer object. -- cgit v1.2.3 From 1e39dc43230ba1827eedc29ab422464281ec3e1b Mon Sep 17 00:00:00 2001 From: David Airlie Date: Tue, 10 Apr 2007 16:25:31 +1000 Subject: export output name to userspace --- libdrm/xf86drmMode.c | 4 +++- libdrm/xf86drmMode.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index df8ea8ee..c0444e65 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -40,6 +40,7 @@ #include "xf86drmMode.h" #include "xf86drm.h" #include +#include /* * Util functions @@ -385,7 +386,8 @@ drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) r->crtcs = out.crtcs; r->clones = out.clones; r->modes = drmAllocCpy(out.modes, out.count_modes, sizeof(uint32_t)); - + strncpy(r->name, out.name, DRM_OUTPUT_NAME_LEN); + r->name[DRM_OUTPUT_NAME_LEN-1] = 0; return r; err_allocs: diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index fadfdc5d..594eb487 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -120,7 +120,7 @@ typedef enum { typedef struct _drmModeOutput { unsigned int crtc; /**< Crtc currently connected to */ - + unsigned char name[DRM_OUTPUT_NAME_LEN]; drmModeConnection connection; uint32_t mmWidth, mmHeight; /**< HxW in millimeters */ drmModeSubPixel subpixel; -- cgit v1.2.3 From 44be9c9d5950d3b2ba4d5527189abec8dac0686f Mon Sep 17 00:00:00 2001 From: David Airlie Date: Wed, 11 Apr 2007 13:19:30 +1000 Subject: add an fb count + id get to the get resources code path --- libdrm/xf86drmMode.c | 25 +++++++++++-------------- libdrm/xf86drmMode.h | 15 ++++++++------- 2 files changed, 19 insertions(+), 21 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index c0444e65..7f0252ce 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -144,14 +144,13 @@ drmModeResPtr drmModeGetResources(int fd) int i; drmModeResPtr r = 0; - res.count_crtcs = 0; - res.count_outputs = 0; - res.count_modes = 0; - res.modes = 0; + memset(&res, 0, sizeof(struct drm_mode_card_res)); if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res)) return 0; + if (res.count_fbs) + res.fb_id = drmMalloc(res.count_fbs*sizeof(uint32_t)); if (res.count_crtcs) res.crtc_id = drmMalloc(res.count_crtcs*sizeof(uint32_t)); if (res.count_outputs) @@ -159,8 +158,10 @@ drmModeResPtr drmModeGetResources(int fd) if (res.count_modes) res.modes = drmMalloc(res.count_modes*sizeof(*res.modes)); - if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res)) + if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res)) { + r = NULL; goto err_allocs; + } /* * return @@ -170,27 +171,23 @@ drmModeResPtr drmModeGetResources(int fd) if (!(r = drmMalloc(sizeof(*r)))) return 0; - r->frameBufferId = res.fb_id; + r->count_fbs = res.count_fbs; r->count_crtcs = res.count_crtcs; r->count_outputs = res.count_outputs; r->count_modes = res.count_modes; /* TODO we realy should test if these allocs fails. */ + r->fbs = drmAllocCpy(res.fb_id, res.count_fbs, sizeof(uint32_t)); r->crtcs = drmAllocCpy(res.crtc_id, res.count_crtcs, sizeof(uint32_t)); r->outputs = drmAllocCpy(res.output_id, res.count_outputs, sizeof(uint32_t)); r->modes = drmAllocCpy(res.modes, res.count_modes, sizeof(struct drm_mode_modeinfo)); - drmFree(res.crtc_id); - drmFree(res.output_id); - drmFree(res.modes); - - return r; - err_allocs: + drmFree(res.fb_id); drmFree(res.crtc_id); drmFree(res.output_id); drmFree(res.modes); - return 0; + return r; } int drmModeAddFB(int fd, uint32_t width, uint32_t height, @@ -214,7 +211,7 @@ int drmModeAddFB(int fd, uint32_t width, uint32_t height, int drmModeRmFB(int fd, uint32_t bufferId) { - return ioctl(fd, DRM_IOCTL_MODE_RMFB, bufferId); + return ioctl(fd, DRM_IOCTL_MODE_RMFB, bufferId); } #if 0 diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 594eb487..4ca9e407 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -62,7 +62,8 @@ typedef struct _drmModeGammaTriple { typedef struct _drmModeRes { - uint32_t frameBufferId; + int count_fbs; + uint32_t *fbs; int count_crtcs; uint32_t *crtcs; @@ -77,10 +78,10 @@ typedef struct _drmModeRes { typedef struct _drmModeFrameBuffer { - uint32_t width; - uint32_t height; - uint32_t pitch; - uint8_t bpp; + uint32_t width; + uint32_t height; + uint32_t pitch; + uint8_t bpp; } drmModeFrameBuffer, *drmModeFrameBufferPtr; @@ -208,14 +209,14 @@ extern int drmModeForceProbe(int fd, uint32_t outputId); /** * Retrive information about framebuffer bufferId */ -extern drmModeFrameBufferPtr drmModeGetFramebuffer(int fd, +extern drmModeFrameBufferPtr drmModeGetFB(int fd, uint32_t bufferId); /** * Creates a new framebuffer with an buffer object as its scanout buffer. */ extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, - uint8_t bpp, uint32_t pitch, drmBO *bo, uint32_t *buf_id); + uint8_t bpp, uint32_t pitch, drmBO *bo, uint32_t *buf_id); /** * Destroies the given framebuffer. */ -- cgit v1.2.3 From a6cc6a778f8b2f86300a8ce87441d044fd67f930 Mon Sep 17 00:00:00 2001 From: David Airlie Date: Wed, 11 Apr 2007 17:13:45 +1000 Subject: add support for setting a framebuffer depth --- libdrm/xf86drmMode.c | 3 ++- libdrm/xf86drmMode.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 7f0252ce..04fb07dc 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -190,7 +190,7 @@ err_allocs: return r; } -int drmModeAddFB(int fd, uint32_t width, uint32_t height, +int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, uint8_t bpp, uint32_t pitch, drmBO *bo, uint32_t *buf_id) { struct drm_mode_fb_cmd f; @@ -200,6 +200,7 @@ int drmModeAddFB(int fd, uint32_t width, uint32_t height, f.height = height; f.pitch = pitch; f.bpp = bpp; + f.depth = depth; f.handle = bo->handle; if (ret = ioctl(fd, DRM_IOCTL_MODE_ADDFB, &f)) diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 4ca9e407..cdc82f7d 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -215,7 +215,7 @@ extern drmModeFrameBufferPtr drmModeGetFB(int fd, /** * Creates a new framebuffer with an buffer object as its scanout buffer. */ -extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, +extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, uint8_t bpp, uint32_t pitch, drmBO *bo, uint32_t *buf_id); /** * Destroies the given framebuffer. -- cgit v1.2.3 From a81558d8b3ee17fbf46e32b10732e22fcd997858 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 12 Apr 2007 08:45:40 +1000 Subject: add getfb ioctl --- libdrm/xf86drmMode.c | 52 +++++++++++++++++----------------------------------- libdrm/xf86drmMode.h | 15 ++++----------- 2 files changed, 21 insertions(+), 46 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 04fb07dc..6070ec6f 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -215,51 +215,33 @@ int drmModeRmFB(int fd, uint32_t bufferId) return ioctl(fd, DRM_IOCTL_MODE_RMFB, bufferId); } -#if 0 -int drmModeForceProbe(int fd, uint32_t outputId) -{ - /* TODO impl/keep? */ -} - -drmModeFrameBufferPtr drmModeGetFrameBuffer(int fd, uint32_t buf) +drmModeFrameBufferPtr drmModeGetFB(int fd, uint32_t buf) { -// struct drm_mode_fb_cmd info; + struct drm_mode_fb_cmd info; drmModeFrameBufferPtr r; - // if (ioctl(fd, DRM_IOCTL_MODE_GETFRAMEBUFFER, &info)) - return 0; + info.buffer_id = buf; + + if (ioctl(fd, DRM_IOCTL_MODE_GETFB, &info)) + return NULL; if (!(r = drmMalloc(sizeof(*r)))) - return 0; + return NULL; - /* TODO change to new code - r->minWidth = info.minWidth; - r->maxWidth = info.maxWidth; - r->minHeight = info.minHeight; - r->maxHeight = info.maxHeight;*/ + r->buffer_id = info.buffer_id; + r->width = info.width; + r->height = info.height; + r->pitch = info.pitch; + r->bpp = info.bpp; + r->handle = info.handle; + r->depth = info.depth; return r; } - -uint32_t drmModeNewFrameBuffer(int fd, uint32_t width, uint32_t height, - uint8_t bpp, uint32_t pitch, drmBO *bo) -{ - drm_mode_fb_cmd_t f; - - f.handle = bo->handle; - f.width = width; - f.height = height; - f.pitch = pitch; - - // if (ioctl(fd, DRM_IOCTL_MODE_NEWFRAMEBUFFER, &f)) - return 0; - - return f.bufferId; -} - -int drmModeDesFrameBuffer(int fd, uint32_t bufferId) +#if 0 +int drmModeForceProbe(int fd, uint32_t outputId) { - // return ioctl(fd, DRM_IOCTL_MODE_DESFRAMEBUFFER, bufferId); + /* TODO impl/keep? */ } #endif diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index cdc82f7d..6a566c4d 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -76,14 +76,7 @@ typedef struct _drmModeRes { } drmModeRes, *drmModeResPtr; -typedef struct _drmModeFrameBuffer { - - uint32_t width; - uint32_t height; - uint32_t pitch; - uint8_t bpp; - -} drmModeFrameBuffer, *drmModeFrameBufferPtr; +typedef struct drm_mode_fb_cmd drmModeFrameBuffer, *drmModeFrameBufferPtr; typedef struct _drmModeCrtc { @@ -209,14 +202,14 @@ extern int drmModeForceProbe(int fd, uint32_t outputId); /** * Retrive information about framebuffer bufferId */ -extern drmModeFrameBufferPtr drmModeGetFB(int fd, - uint32_t bufferId); +extern drmModeFrameBufferPtr drmModeGetFB(int fd, uint32_t bufferId); /** * Creates a new framebuffer with an buffer object as its scanout buffer. */ extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, - uint8_t bpp, uint32_t pitch, drmBO *bo, uint32_t *buf_id); + uint8_t bpp, uint32_t pitch, drmBO *bo, + uint32_t *buf_id); /** * Destroies the given framebuffer. */ -- cgit v1.2.3 From 981f8156de0c5ec6387f659fbcac031d663d943c Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 12 Apr 2007 08:54:31 +1000 Subject: allow framebuffer changes on the crtc setup --- libdrm/xf86drmMode.c | 2 +- libdrm/xf86drmMode.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 6070ec6f..cb534678 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -276,7 +276,7 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId) r->mode = crtc.mode; // r->width = crtc.width; // r->height = crtc.height; - r->bufferId = crtc.fb_id; + r->buffer_id = crtc.fb_id; r->gamma_size = crtc.gamma_size; r->count_outputs = crtc.count_outputs; r->count_possibles = crtc.count_possibles; diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 6a566c4d..c87a95da 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -80,7 +80,7 @@ typedef struct drm_mode_fb_cmd drmModeFrameBuffer, *drmModeFrameBufferPtr; typedef struct _drmModeCrtc { - unsigned int bufferId; /**< Buffer currently connected to */ + unsigned int buffer_id; /**< FB id to connect to 0 = disconnect*/ uint32_t x, y; /**< Position on the frameuffer */ uint32_t width, height; -- cgit v1.2.3 From b1f0fd6dfbd1495aa08c6358e936582eeca042c8 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 12 Apr 2007 12:11:58 +1000 Subject: use FB everywhere --- libdrm/xf86drmMode.c | 6 +++--- libdrm/xf86drmMode.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index cb534678..b695467b 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -106,7 +106,7 @@ void drmModeFreeResources(drmModeResPtr ptr) } -void drmModeFreeFrameBuffer(drmModeFrameBufferPtr ptr) +void drmModeFreeFB(drmModeFBPtr ptr) { if (!ptr) return; @@ -215,10 +215,10 @@ int drmModeRmFB(int fd, uint32_t bufferId) return ioctl(fd, DRM_IOCTL_MODE_RMFB, bufferId); } -drmModeFrameBufferPtr drmModeGetFB(int fd, uint32_t buf) +drmModeFBPtr drmModeGetFB(int fd, uint32_t buf) { struct drm_mode_fb_cmd info; - drmModeFrameBufferPtr r; + drmModeFBPtr r; info.buffer_id = buf; diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index c87a95da..6aa104a9 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -76,7 +76,7 @@ typedef struct _drmModeRes { } drmModeRes, *drmModeResPtr; -typedef struct drm_mode_fb_cmd drmModeFrameBuffer, *drmModeFrameBufferPtr; +typedef struct drm_mode_fb_cmd drmModeFB, *drmModeFBPtr; typedef struct _drmModeCrtc { @@ -180,7 +180,7 @@ typedef struct _drmModeOutput { extern void drmModeFreeModeInfo( struct drm_mode_modeinfo *ptr ); extern void drmModeFreeResources( drmModeResPtr ptr ); -extern void drmModeFreeFrameBuffer( drmModeFrameBufferPtr ptr ); +extern void drmModeFreeFB( drmModeFBPtr ptr ); extern void drmModeFreeCrtc( drmModeCrtcPtr ptr ); extern void drmModeFreeOutput( drmModeOutputPtr ptr ); @@ -202,7 +202,7 @@ extern int drmModeForceProbe(int fd, uint32_t outputId); /** * Retrive information about framebuffer bufferId */ -extern drmModeFrameBufferPtr drmModeGetFB(int fd, uint32_t bufferId); +extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId); /** * Creates a new framebuffer with an buffer object as its scanout buffer. -- cgit v1.2.3 From 89231953d108e74ee7b0eb99494ead1dd795d640 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 1 May 2007 13:16:29 +1000 Subject: Add support for user defined modes This allows userspace to specify modes and add them to the modesetting system and attach modes to outputs --- libdrm/xf86drmMode.c | 33 +++++++++++++++++---------------- libdrm/xf86drmMode.h | 16 ++++++++-------- 2 files changed, 25 insertions(+), 24 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index b695467b..93b0af76 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -376,37 +376,38 @@ err_allocs: return 0; } -#if 0 -uint32_t drmModeNewMode(int fd, struct drm_mode_modeinfo *modeInfo) +uint32_t drmModeAddMode(int fd, struct drm_mode_modeinfo *mode_info) { - /* TODO impl */ + if (ioctl(fd, DRM_IOCTL_MODE_ADDMODE, mode_info)) + return 0; + + return mode_info->id; } -int drmModeDesMode(int fd, uint32_t modeId) +int drmModeRmMode(int fd, uint32_t mode_id) { - // return ioctl(fd, DRM_IOCTL_MODE_DESMODE, modeId); + return ioctl(fd, DRM_IOCTL_MODE_RMMODE, mode_id); } -int drmModeAddMode(int fd, uint32_t outputId, uint32_t modeId) +int drmModeAttachMode(int fd, uint32_t output_id, uint32_t mode_id) { - drm_mode_outputmode_t res; + struct drm_mode_mode_cmd res; - res.outputId = outputId; - res.modeId = modeId; + res.output_id = output_id; + res.mode_id = mode_id; - // return ioctl(fd, DRM_IOCTL_MODE_ADDMODE, &res); + return ioctl(fd, DRM_IOCTL_MODE_ATTACHMODE, &res); } -int drmModeDelMode(int fd, uint32_t outputId, uint32_t modeId) +int drmModeDetachMode(int fd, uint32_t output_id, uint32_t mode_id) { - drm_mode_outputmode_t res; + struct drm_mode_mode_cmd res; - res.outputId = outputId; - res.modeId = modeId; + res.output_id = output_id; + res.mode_id = mode_id; - // return ioctl(fd, DRM_IOCTL_MODE_DELMODE, &res); + return ioctl(fd, DRM_IOCTL_MODE_DETACHMODE, &res); } -#endif diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 6aa104a9..60e919ae 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -261,24 +261,24 @@ extern drmModeOutputPtr drmModeGetOutput(int fd, uint32_t outputId); /** - * Creates a new mode from the given mode info. + * Adds a new mode from the given mode info. * Name must be unique. */ -extern uint32_t drmModeNewMode(int fd, struct drm_mode_modeinfo *modeInfo); +extern uint32_t drmModeAddMode(int fd, struct drm_mode_modeinfo *modeInfo); /** - * Destroys a mode created with CreateMode, must be unused. + * Removes a mode created with AddMode, must be unused. */ -extern int drmModeDesMode(int fd, uint32_t modeId); +extern int drmModeRmMode(int fd, uint32_t modeId); /** - * Adds the given mode to an output. + * Attaches the given mode to an output. */ -extern int drmModeAddMode(int fd, uint32_t outputId, uint32_t modeId); +extern int drmModeAttachMode(int fd, uint32_t outputId, uint32_t modeId); /** - * Deletes a mode Added with AddOutputMode from the output, + * Detaches a mode from the output * must be unused, by the given mode. */ -extern int drmModeDelMode(int fd, uint32_t outputId, uint32_t modeId); +extern int drmModeDetachMode(int fd, uint32_t outputId, uint32_t modeId); -- cgit v1.2.3 From 45e09ea3cf85b76c18fb92a593ca7c40681052a7 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sat, 5 May 2007 16:08:27 +0200 Subject: Cleaned up userspace interface for modesetting. --- libdrm/xf86drmMode.c | 30 ++++-------------- libdrm/xf86drmMode.h | 88 ++++------------------------------------------------ 2 files changed, 12 insertions(+), 106 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 93b0af76..a7241ffd 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -238,15 +238,10 @@ drmModeFBPtr drmModeGetFB(int fd, uint32_t buf) return r; } -#if 0 -int drmModeForceProbe(int fd, uint32_t outputId) -{ - /* TODO impl/keep? */ -} -#endif + /* - * Crtc function. + * Crtc functions */ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId) @@ -274,9 +269,7 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId) r->x = crtc.x; r->y = crtc.y; r->mode = crtc.mode; -// r->width = crtc.width; -// r->height = crtc.height; - r->buffer_id = crtc.fb_id; + r->buffer_id = crtc.fb_id; r->gamma_size = crtc.gamma_size; r->count_outputs = crtc.count_outputs; r->count_possibles = crtc.count_possibles; @@ -305,8 +298,8 @@ int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, crtc.x = x; crtc.y = y; - crtc.crtc_id = crtcId; - crtc.fb_id = bufferId; + crtc.crtc_id = crtcId; + crtc.fb_id = bufferId; crtc.set_outputs = outputs; crtc.count_outputs = count; crtc.mode = modeId; @@ -314,22 +307,11 @@ int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, return ioctl(fd, DRM_IOCTL_MODE_SETCRTC, &crtc); } -#if 0 -drmModeGammaTriplePtr drmModeGetCrtcGamma(int fd, uint32_t crtc, int *count) -{ - /* TODO impl */ -} -int drmModeSetCrtcGamma(int fd, uint32_t crtcId, - drmModeGammaTriplePtr ptr, int count) -{ - /* TODO impl */ -} - -#endif /* * Output manipulation */ + drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) { struct drm_mode_get_output out; diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 60e919ae..b25a6610 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -40,25 +40,17 @@ * In order to use this interface you must include either or another * header defining uint32_t, int32_t and uint16_t. * - * It aims to provide a randr compatible interface for modesettings in the + * It aims to provide a randr1.2 compatible interface for modesettings in the * kernel, the interface is also ment to be used by libraries like EGL. * * More information can be found in randrproto.txt which can be found here: * http://gitweb.freedesktop.org/?p=xorg/proto/randrproto.git * - * All framebuffer, crtc and output ids start at 1 while 0 is either an invalid - * parameter or used to indicate that the command should disconnect from the - * currently bound target, as with drmModeMapOutput. - * - * Currently only one framebuffer exist and has a id of 1, which is also the - * default framebuffer and should allways be avaible to the client, unless - * it is locked/used or any other limiting state is applied on it. - * + * There are some major diffrences to be noted. Unlike the randr1.2 proto you + * need to create the memory object of the framebuffer yourself with the ttm + * buffer object interface. This object needs to be pinned. */ -typedef struct _drmModeGammaTriple { - uint16_t r, g, b; -} drmModeGammaTriple, *drmModeGammaTriplePtr; typedef struct _drmModeRes { @@ -130,53 +122,7 @@ typedef struct _drmModeOutput { } drmModeOutput, *drmModeOutputPtr; -/* - * RRSetScreenConfig o - * RRGetScreenInfo o - * - * RRGetScreenSizeRange - see frameBuffer info - * RRSetScreenSize - * RRGetScreenResources - * - * RRGetOutputInfo - * - * RRListOutputProperties * - * RRQueryOutputProperty * - * RRConfigureOutputProperty * - * RRChangeOutputProperty * - * RRDeleteOutputProperty * - * RRGetOutputProperty * - * - * RRCreateMode - * RRDestroyMode - * RRAddOutputMode - * RRDeleteOutputMode - * - * RRGetCrtcInfo - * RRSetCrtcConfig - * - * RRGetCrtcGammaSize - see crtc info - * RRGetCrtcGamma - * RRSetCrtcGamma - * - * drmModeGetResources - * drmModeForceProbe - * - * drmModeGetFrameBufferInfo - * drmModeSetFrameBufferSize - * - * drmModeGetCrtcInfo - * drmModeSetCrtcConfig - * drmModeGetCrtcGamma - * drmModeSetCrtcGamma - * - * drmModeGetOutputInfo - * - * drmModeAddMode - * drmModeDestroyMode - * drmModeAddOutputMode - * drmModeDeleteOutputMode - */ + extern void drmModeFreeModeInfo( struct drm_mode_modeinfo *ptr ); extern void drmModeFreeResources( drmModeResPtr ptr ); @@ -189,11 +135,6 @@ extern void drmModeFreeOutput( drmModeOutputPtr ptr ); */ extern drmModeResPtr drmModeGetResources(int fd); -/** - * Forces a probe of the give output outputId, on 0 all will be probed. - */ -extern int drmModeForceProbe(int fd, uint32_t outputId); - /* * FrameBuffer manipulation. @@ -215,13 +156,9 @@ extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, */ extern int drmModeRmFB(int fd, uint32_t bufferId); -/** - * Changes the scanout buffer to the given buffer object. - */ -extern int drmModeFlipFrameBuffer(int fd, uint32_t bufferId, drmBO *bo); /* - * Crtc function. + * Crtc functions */ /** @@ -236,19 +173,6 @@ extern int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, uint32_t x, uint32_t y, uint32_t modeId, uint32_t *outputs, int count); -/** - * Gets the gamma from a crtc - */ -extern drmModeGammaTriplePtr drmModeGetCrtcGamma(int fd, uint32_t crtcId, - int *count); - -/** - * Sets the gamma on a crtc - */ -extern int drmModeSetCrtcGamma(int fd, uint32_t crtcId, - drmModeGammaTriplePtr ptr, int count); - - /* * Output manipulation -- cgit v1.2.3 From 5e86f67a34c50ec49e1d7b3b834d1695ebf5d4c8 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Mon, 5 Nov 2007 10:00:11 +0000 Subject: pass pointer for drmModeRmFB --- libdrm/xf86drmMode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index a7241ffd..cfe133fe 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -212,7 +212,7 @@ int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, int drmModeRmFB(int fd, uint32_t bufferId) { - return ioctl(fd, DRM_IOCTL_MODE_RMFB, bufferId); + return ioctl(fd, DRM_IOCTL_MODE_RMFB, &bufferId); } drmModeFBPtr drmModeGetFB(int fd, uint32_t buf) -- cgit v1.2.3 From 0bee83a8c8bca817459a0ee9caa6e13f3f1aa281 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Mon, 5 Nov 2007 10:00:43 +0000 Subject: Pass pointer to drmModeRmMode. --- libdrm/xf86drmMode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index cfe133fe..e7ac58ba 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -368,7 +368,7 @@ uint32_t drmModeAddMode(int fd, struct drm_mode_modeinfo *mode_info) int drmModeRmMode(int fd, uint32_t mode_id) { - return ioctl(fd, DRM_IOCTL_MODE_RMMODE, mode_id); + return ioctl(fd, DRM_IOCTL_MODE_RMMODE, &mode_id); } int drmModeAttachMode(int fd, uint32_t output_id, uint32_t mode_id) -- cgit v1.2.3 From f32688d3d011d631c18d584603d684edd9b9b512 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 15 Nov 2007 18:31:50 +1100 Subject: libdrm: add crtc/output ids to userspace interface --- libdrm/xf86drmMode.c | 4 +++- libdrm/xf86drmMode.h | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index e7ac58ba..c3abb2df 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -265,7 +265,8 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId) if (!(r = drmMalloc(sizeof(*r)))) return 0; - + + r->crtc_id = crtc.crtc_id; r->x = crtc.x; r->y = crtc.y; r->mode = crtc.mode; @@ -337,6 +338,7 @@ drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) if(!(r = drmMalloc(sizeof(*r)))) return 0; + r->output_id = out.output; r->connection = out.connection; r->mmWidth = out.mm_width; r->mmHeight = out.mm_height; diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index b25a6610..be9d84af 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -71,7 +71,7 @@ typedef struct _drmModeRes { typedef struct drm_mode_fb_cmd drmModeFB, *drmModeFBPtr; typedef struct _drmModeCrtc { - + unsigned int crtc_id; unsigned int buffer_id; /**< FB id to connect to 0 = disconnect*/ uint32_t x, y; /**< Position on the frameuffer */ @@ -104,6 +104,7 @@ typedef enum { } drmModeSubPixel; typedef struct _drmModeOutput { + unsigned int output_id; unsigned int crtc; /**< Crtc currently connected to */ unsigned char name[DRM_OUTPUT_NAME_LEN]; -- cgit v1.2.3 From ca499f4d14ae29159f13957f2adc0536c71bf6d4 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 15 Nov 2007 19:22:01 +1100 Subject: libdrm: return crtc id to userspace --- libdrm/xf86drmMode.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index c3abb2df..e400f219 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -339,6 +339,7 @@ drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) return 0; r->output_id = out.output; + r->crtc = out.crtc; r->connection = out.connection; r->mmWidth = out.mm_width; r->mmHeight = out.mm_height; -- cgit v1.2.3 From b3af2b59a77a6916ea7151236d3da9bde6a537fc Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 27 Nov 2007 14:31:02 +1000 Subject: drm/modesetting: add initial gettable properites code. This allow the user to retrieve a list of properties for an output. Properties can either be 32-bit values or an enum with an associated name. Range properties are to be supported. This API is probably not all correct, I may make properties part of the general resource get when I think about it some more. So basically you can create properties and attached them to whatever outputs you want, so it should be possible to create some generics and just attach them to every output. --- libdrm/xf86drmMode.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++---- libdrm/xf86drmMode.h | 17 ++++++++++++ 2 files changed, 89 insertions(+), 5 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index e400f219..f697232d 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -316,7 +316,7 @@ int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) { struct drm_mode_get_output out; - drmModeOutputPtr r = 0; + drmModeOutputPtr r = NULL; out.output = output_id; out.count_crtcs = 0; @@ -325,18 +325,27 @@ drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) out.clones = 0; out.count_modes = 0; out.modes = 0; + out.count_props = 0; + out.props = NULL; + out.prop_values = NULL; if (ioctl(fd, DRM_IOCTL_MODE_GETOUTPUT, &out)) return 0; + if (out.count_props) { + out.props = drmMalloc(out.count_props*sizeof(uint32_t)); + out.prop_values = drmMalloc(out.count_props*sizeof(uint32_t)); + } + if (out.count_modes) out.modes = drmMalloc(out.count_modes*sizeof(uint32_t)); if (ioctl(fd, DRM_IOCTL_MODE_GETOUTPUT, &out)) goto err_allocs; - if(!(r = drmMalloc(sizeof(*r)))) - return 0; + if(!(r = drmMalloc(sizeof(*r)))) { + goto err_allocs; + } r->output_id = out.output; r->crtc = out.crtc; @@ -350,15 +359,19 @@ drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) /* TODO we should test if these alloc & cpy fails. */ r->crtcs = out.crtcs; r->clones = out.clones; + r->count_props = out.count_props; + r->props = drmAllocCpy(out.props, out.count_props, sizeof(uint32_t)); + r->prop_values = drmAllocCpy(out.prop_values, out.count_props, sizeof(uint32_t)); r->modes = drmAllocCpy(out.modes, out.count_modes, sizeof(uint32_t)); strncpy(r->name, out.name, DRM_OUTPUT_NAME_LEN); r->name[DRM_OUTPUT_NAME_LEN-1] = 0; - return r; err_allocs: + drmFree(out.prop_values); + drmFree(out.props); drmFree(out.modes); - return 0; + return r; } uint32_t drmModeAddMode(int fd, struct drm_mode_modeinfo *mode_info) @@ -396,3 +409,57 @@ int drmModeDetachMode(int fd, uint32_t output_id, uint32_t mode_id) } +drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id) +{ + struct drm_mode_get_property prop; + drmModePropertyPtr r; + + prop.prop_id = property_id; + prop.count_enums = 0; + prop.count_values = 0; + prop.flags = 0; + prop.enums = NULL; + prop.values = NULL; + + if (ioctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop)) + return 0; + + if (prop.count_values) + prop.values = drmMalloc(prop.count_values * sizeof(uint32_t)); + + if (prop.count_enums) + prop.enums = drmMalloc(prop.count_enums * sizeof(struct drm_mode_property_enum)); + + if (ioctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop)) { + r = NULL; + goto err_allocs; + } + + if (!(r = drmMalloc(sizeof(*r)))) + return NULL; + + r->prop_id = prop.prop_id; + r->count_values = prop.count_values; + r->count_enums = prop.count_enums; + + r->values = drmAllocCpy(prop.values, prop.count_values, sizeof(uint32_t)); + r->enums = drmAllocCpy(prop.enums, prop.count_enums, sizeof(struct drm_mode_property_enum)); + strncpy(r->name, prop.name, DRM_PROP_NAME_LEN); + r->name[DRM_PROP_NAME_LEN-1] = 0; + +err_allocs: + drmFree(prop.values); + drmFree(prop.enums); + + return r; +} + +void drmModeFreeProperty(drmModePropertyPtr ptr) +{ + if (!ptr) + return; + + drmFree(ptr->values); + drmFree(ptr->enums); + drmFree(ptr); +} diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index be9d84af..5e966e95 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -70,6 +70,17 @@ typedef struct _drmModeRes { typedef struct drm_mode_fb_cmd drmModeFB, *drmModeFBPtr; +typedef struct _drmModeProperty { + unsigned int prop_id; + unsigned int flags; + unsigned char name[DRM_PROP_NAME_LEN]; + int count_values; + uint32_t *values; + int count_enums; + struct drm_mode_property_enum *enums; + +} drmModePropertyRes, *drmModePropertyPtr; + typedef struct _drmModeCrtc { unsigned int crtc_id; unsigned int buffer_id; /**< FB id to connect to 0 = disconnect*/ @@ -121,6 +132,10 @@ typedef struct _drmModeOutput { int count_modes; uint32_t *modes; /**< List of modes ids */ + int count_props; + uint32_t *props; /**< List of property ids */ + uint32_t *prop_values; /**< List of property values */ + } drmModeOutput, *drmModeOutputPtr; @@ -207,3 +222,5 @@ extern int drmModeAttachMode(int fd, uint32_t outputId, uint32_t modeId); */ extern int drmModeDetachMode(int fd, uint32_t outputId, uint32_t modeId); +extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId); +extern void drmModeFreeProperty(drmModePropertyPtr ptr); -- cgit v1.2.3 From 91cd3e3c097d581ea75ec4bcbc1ba8d23b471a2e Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 28 Nov 2007 15:18:25 +1000 Subject: modesetting API change for removing mode ids and making modes per output. so really want to get a list of modes per output not the global hammer list. also we remove the mode ids and let the user pass back the full mode description need to fix up add/remove mode for user modes now --- libdrm/xf86drmMode.c | 22 +++++++++++----------- libdrm/xf86drmMode.h | 14 ++++++-------- 2 files changed, 17 insertions(+), 19 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index f697232d..8b701381 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -101,7 +101,6 @@ void drmModeFreeResources(drmModeResPtr ptr) if (!ptr) return; - drmFree(ptr->modes); drmFree(ptr); } @@ -155,8 +154,6 @@ drmModeResPtr drmModeGetResources(int fd) res.crtc_id = drmMalloc(res.count_crtcs*sizeof(uint32_t)); if (res.count_outputs) res.output_id = drmMalloc(res.count_outputs*sizeof(uint32_t)); - if (res.count_modes) - res.modes = drmMalloc(res.count_modes*sizeof(*res.modes)); if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res)) { r = NULL; @@ -174,18 +171,15 @@ drmModeResPtr drmModeGetResources(int fd) r->count_fbs = res.count_fbs; r->count_crtcs = res.count_crtcs; r->count_outputs = res.count_outputs; - r->count_modes = res.count_modes; /* TODO we realy should test if these allocs fails. */ r->fbs = drmAllocCpy(res.fb_id, res.count_fbs, sizeof(uint32_t)); r->crtcs = drmAllocCpy(res.crtc_id, res.count_crtcs, sizeof(uint32_t)); r->outputs = drmAllocCpy(res.output_id, res.count_outputs, sizeof(uint32_t)); - r->modes = drmAllocCpy(res.modes, res.count_modes, sizeof(struct drm_mode_modeinfo)); err_allocs: drmFree(res.fb_id); drmFree(res.crtc_id); drmFree(res.output_id); - drmFree(res.modes); return r; } @@ -287,8 +281,8 @@ err_allocs: int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, - uint32_t x, uint32_t y, uint32_t modeId, - uint32_t *outputs, int count) + uint32_t x, uint32_t y, uint32_t *outputs, int count, + struct drm_mode_modeinfo *mode) { struct drm_mode_crtc crtc; @@ -303,7 +297,11 @@ int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, crtc.fb_id = bufferId; crtc.set_outputs = outputs; crtc.count_outputs = count; - crtc.mode = modeId; + if (mode) { + memcpy(&crtc.mode, mode, sizeof(struct drm_mode_modeinfo)); + crtc.mode_valid = 1; + } else + crtc.mode_valid = 0; return ioctl(fd, DRM_IOCTL_MODE_SETCRTC, &crtc); } @@ -338,7 +336,7 @@ drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) } if (out.count_modes) - out.modes = drmMalloc(out.count_modes*sizeof(uint32_t)); + out.modes = drmMalloc(out.count_modes*sizeof(struct drm_mode_modeinfo)); if (ioctl(fd, DRM_IOCTL_MODE_GETOUTPUT, &out)) goto err_allocs; @@ -362,7 +360,7 @@ drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) r->count_props = out.count_props; r->props = drmAllocCpy(out.props, out.count_props, sizeof(uint32_t)); r->prop_values = drmAllocCpy(out.prop_values, out.count_props, sizeof(uint32_t)); - r->modes = drmAllocCpy(out.modes, out.count_modes, sizeof(uint32_t)); + r->modes = drmAllocCpy(out.modes, out.count_modes, sizeof(struct drm_mode_modeinfo)); strncpy(r->name, out.name, DRM_OUTPUT_NAME_LEN); r->name[DRM_OUTPUT_NAME_LEN-1] = 0; @@ -374,6 +372,7 @@ err_allocs: return r; } +#if 0 uint32_t drmModeAddMode(int fd, struct drm_mode_modeinfo *mode_info) { if (ioctl(fd, DRM_IOCTL_MODE_ADDMODE, mode_info)) @@ -386,6 +385,7 @@ int drmModeRmMode(int fd, uint32_t mode_id) { return ioctl(fd, DRM_IOCTL_MODE_RMMODE, &mode_id); } +#endif int drmModeAttachMode(int fd, uint32_t output_id, uint32_t mode_id) { diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 5e966e95..0777c596 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -63,9 +63,6 @@ typedef struct _drmModeRes { int count_outputs; uint32_t *outputs; - int count_modes; - struct drm_mode_modeinfo *modes; - } drmModeRes, *drmModeResPtr; typedef struct drm_mode_fb_cmd drmModeFB, *drmModeFBPtr; @@ -87,7 +84,8 @@ typedef struct _drmModeCrtc { uint32_t x, y; /**< Position on the frameuffer */ uint32_t width, height; - uint32_t mode; /**< Current mode used */ + int mode_valid; + struct drm_mode_modeinfo mode; int count_outputs; uint32_t outputs; /**< Outputs that are connected */ @@ -130,7 +128,7 @@ typedef struct _drmModeOutput { uint32_t clones; /**< Mask of clones */ int count_modes; - uint32_t *modes; /**< List of modes ids */ + struct drm_mode_modeinfo *modes; int count_props; uint32_t *props; /**< List of property ids */ @@ -185,9 +183,9 @@ extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId); /** * Set the mode on a crtc crtcId with the given mode modeId. */ -extern int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, - uint32_t x, uint32_t y, uint32_t modeId, - uint32_t *outputs, int count); +int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, + uint32_t x, uint32_t y, uint32_t *outputs, int count, + struct drm_mode_modeinfo *mode); /* -- cgit v1.2.3 From 96df9b11ad8974d7a2a0a589114cbbb04a584f18 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 3 Dec 2007 13:42:32 +1000 Subject: finish of mode add/remove, just have attach/detach modes --- libdrm/xf86drmMode.c | 24 ++++-------------------- libdrm/xf86drmMode.h | 15 ++------------- 2 files changed, 6 insertions(+), 33 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 8b701381..cf596730 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -372,38 +372,22 @@ err_allocs: return r; } -#if 0 -uint32_t drmModeAddMode(int fd, struct drm_mode_modeinfo *mode_info) +int drmModeAttachMode(int fd, uint32_t output_id, struct drm_mode_modeinfo *mode_info) { - if (ioctl(fd, DRM_IOCTL_MODE_ADDMODE, mode_info)) - return 0; - - return mode_info->id; -} - -int drmModeRmMode(int fd, uint32_t mode_id) -{ - return ioctl(fd, DRM_IOCTL_MODE_RMMODE, &mode_id); -} -#endif - -int drmModeAttachMode(int fd, uint32_t output_id, uint32_t mode_id) -{ - struct drm_mode_mode_cmd res; + memcpy(&res.mode, mode_info, sizeof(struct drm_mode_modeinfo)); res.output_id = output_id; - res.mode_id = mode_id; return ioctl(fd, DRM_IOCTL_MODE_ATTACHMODE, &res); } -int drmModeDetachMode(int fd, uint32_t output_id, uint32_t mode_id) +int drmModeDetachMode(int fd, uint32_t output_id, struct drm_mode_modeinfo *mode_info) { struct drm_mode_mode_cmd res; + memcpy(&res.mode, mode_info, sizeof(struct drm_mode_modeinfo)); res.output_id = output_id; - res.mode_id = mode_id; return ioctl(fd, DRM_IOCTL_MODE_DETACHMODE, &res); } diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 0777c596..a1d717f9 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -198,27 +198,16 @@ int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, extern drmModeOutputPtr drmModeGetOutput(int fd, uint32_t outputId); -/** - * Adds a new mode from the given mode info. - * Name must be unique. - */ -extern uint32_t drmModeAddMode(int fd, struct drm_mode_modeinfo *modeInfo); - -/** - * Removes a mode created with AddMode, must be unused. - */ -extern int drmModeRmMode(int fd, uint32_t modeId); - /** * Attaches the given mode to an output. */ -extern int drmModeAttachMode(int fd, uint32_t outputId, uint32_t modeId); +extern int drmModeAttachMode(int fd, uint32_t outputId, struct drm_mode_modeinfo *mode_info); /** * Detaches a mode from the output * must be unused, by the given mode. */ -extern int drmModeDetachMode(int fd, uint32_t outputId, uint32_t modeId); +extern int drmModeDetachMode(int fd, uint32_t outputId, struct drm_mode_modeinfo *mode_info); extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId); extern void drmModeFreeProperty(drmModePropertyPtr ptr); -- cgit v1.2.3 From 34bb2e733a612de49a390babddd8477825deb895 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 3 Dec 2007 15:27:49 +1000 Subject: mode: copy back the mode if is valid correctly --- libdrm/xf86drmMode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index cf596730..bb7be13c 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -263,7 +263,9 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId) r->crtc_id = crtc.crtc_id; r->x = crtc.x; r->y = crtc.y; - r->mode = crtc.mode; + r->mode_valid = crtc.mode_valid; + if (r->mode_valid) + memcpy(&r->mode, &crtc.mode, sizeof(struct drm_mode_modeinfo)); r->buffer_id = crtc.fb_id; r->gamma_size = crtc.gamma_size; r->count_outputs = crtc.count_outputs; -- cgit v1.2.3 From 1a6c95ef711fce807659ab5e4fe480d65ac233b6 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 5 Dec 2007 16:03:05 +1000 Subject: arrgggh.. make all ioctl structs 32/64-bit compatible hopefully. This also starts to add blob property support. someone needs to check this work for other things like ppc/x86 alignment diffs --- libdrm/xf86drmMode.c | 75 ++++++++++++++++++++++++++++------------------------ libdrm/xf86drmMode.h | 6 +++-- 2 files changed, 45 insertions(+), 36 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index bb7be13c..e5191d8c 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -42,6 +42,9 @@ #include #include +#define U642VOID(x) ((void *)(unsigned long)(x)) +#define VOID2U64(x) ((uint64_t)(unsigned long)(x)) + /* * Util functions */ @@ -149,11 +152,11 @@ drmModeResPtr drmModeGetResources(int fd) return 0; if (res.count_fbs) - res.fb_id = drmMalloc(res.count_fbs*sizeof(uint32_t)); + res.fb_id_ptr = VOID2U64(drmMalloc(res.count_fbs*sizeof(uint32_t))); if (res.count_crtcs) - res.crtc_id = drmMalloc(res.count_crtcs*sizeof(uint32_t)); + res.crtc_id_ptr = VOID2U64(drmMalloc(res.count_crtcs*sizeof(uint32_t))); if (res.count_outputs) - res.output_id = drmMalloc(res.count_outputs*sizeof(uint32_t)); + res.output_id_ptr = VOID2U64(drmMalloc(res.count_outputs*sizeof(uint32_t))); if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res)) { r = NULL; @@ -168,18 +171,22 @@ drmModeResPtr drmModeGetResources(int fd) if (!(r = drmMalloc(sizeof(*r)))) return 0; + r->min_width = res.min_width; + r->max_width = res.max_width; + r->min_height = res.min_height; + r->max_height = res.max_height; r->count_fbs = res.count_fbs; r->count_crtcs = res.count_crtcs; r->count_outputs = res.count_outputs; /* TODO we realy should test if these allocs fails. */ - r->fbs = drmAllocCpy(res.fb_id, res.count_fbs, sizeof(uint32_t)); - r->crtcs = drmAllocCpy(res.crtc_id, res.count_crtcs, sizeof(uint32_t)); - r->outputs = drmAllocCpy(res.output_id, res.count_outputs, sizeof(uint32_t)); + r->fbs = drmAllocCpy(U642VOID(res.fb_id_ptr), res.count_fbs, sizeof(uint32_t)); + r->crtcs = drmAllocCpy(U642VOID(res.crtc_id_ptr), res.count_crtcs, sizeof(uint32_t)); + r->outputs = drmAllocCpy(U642VOID(res.output_id_ptr), res.count_outputs, sizeof(uint32_t)); err_allocs: - drmFree(res.fb_id); - drmFree(res.crtc_id); - drmFree(res.output_id); + drmFree(U642VOID(res.fb_id_ptr)); + drmFree(U642VOID(res.crtc_id_ptr)); + drmFree(U642VOID(res.output_id_ptr)); return r; } @@ -297,7 +304,7 @@ int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, crtc.y = y; crtc.crtc_id = crtcId; crtc.fb_id = bufferId; - crtc.set_outputs = outputs; + crtc.set_outputs_ptr = VOID2U64(outputs); crtc.count_outputs = count; if (mode) { memcpy(&crtc.mode, mode, sizeof(struct drm_mode_modeinfo)); @@ -324,21 +331,21 @@ drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) out.count_clones = 0; out.clones = 0; out.count_modes = 0; - out.modes = 0; + out.modes_ptr = 0; out.count_props = 0; - out.props = NULL; - out.prop_values = NULL; + out.props_ptr = 0; + out.prop_values_ptr = 0; if (ioctl(fd, DRM_IOCTL_MODE_GETOUTPUT, &out)) return 0; if (out.count_props) { - out.props = drmMalloc(out.count_props*sizeof(uint32_t)); - out.prop_values = drmMalloc(out.count_props*sizeof(uint32_t)); + out.props_ptr = VOID2U64(drmMalloc(out.count_props*sizeof(uint32_t))); + out.prop_values_ptr = VOID2U64(drmMalloc(out.count_props*sizeof(uint64_t))); } if (out.count_modes) - out.modes = drmMalloc(out.count_modes*sizeof(struct drm_mode_modeinfo)); + out.modes_ptr = VOID2U64(drmMalloc(out.count_modes*sizeof(struct drm_mode_modeinfo))); if (ioctl(fd, DRM_IOCTL_MODE_GETOUTPUT, &out)) goto err_allocs; @@ -360,16 +367,16 @@ drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) r->crtcs = out.crtcs; r->clones = out.clones; r->count_props = out.count_props; - r->props = drmAllocCpy(out.props, out.count_props, sizeof(uint32_t)); - r->prop_values = drmAllocCpy(out.prop_values, out.count_props, sizeof(uint32_t)); - r->modes = drmAllocCpy(out.modes, out.count_modes, sizeof(struct drm_mode_modeinfo)); + r->props = drmAllocCpy(U642VOID(out.props_ptr), out.count_props, sizeof(uint32_t)); + r->prop_values = drmAllocCpy(U642VOID(out.prop_values_ptr), out.count_props, sizeof(uint64_t)); + r->modes = drmAllocCpy(U642VOID(out.modes_ptr), out.count_modes, sizeof(struct drm_mode_modeinfo)); strncpy(r->name, out.name, DRM_OUTPUT_NAME_LEN); r->name[DRM_OUTPUT_NAME_LEN-1] = 0; err_allocs: - drmFree(out.prop_values); - drmFree(out.props); - drmFree(out.modes); + drmFree(U642VOID(out.prop_values_ptr)); + drmFree(U642VOID(out.props_ptr)); + drmFree(U642VOID(out.modes_ptr)); return r; } @@ -401,20 +408,20 @@ drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id) drmModePropertyPtr r; prop.prop_id = property_id; - prop.count_enums = 0; + prop.count_enum_blobs = 0; prop.count_values = 0; prop.flags = 0; - prop.enums = NULL; - prop.values = NULL; + prop.enum_blob_ptr = 0; + prop.values_ptr = 0; if (ioctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop)) return 0; if (prop.count_values) - prop.values = drmMalloc(prop.count_values * sizeof(uint32_t)); + prop.values_ptr = VOID2U64(drmMalloc(prop.count_values * sizeof(uint64_t))); - if (prop.count_enums) - prop.enums = drmMalloc(prop.count_enums * sizeof(struct drm_mode_property_enum)); + if (prop.count_enum_blobs) + prop.enum_blob_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(struct drm_mode_property_enum))); if (ioctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop)) { r = NULL; @@ -426,16 +433,16 @@ drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id) r->prop_id = prop.prop_id; r->count_values = prop.count_values; - r->count_enums = prop.count_enums; - - r->values = drmAllocCpy(prop.values, prop.count_values, sizeof(uint32_t)); - r->enums = drmAllocCpy(prop.enums, prop.count_enums, sizeof(struct drm_mode_property_enum)); + r->count_enums = prop.count_enum_blobs; + r->flags = prop.flags; + r->values = drmAllocCpy(U642VOID(prop.values_ptr), prop.count_values, sizeof(uint64_t)); + r->enums = drmAllocCpy(U642VOID(prop.enum_blob_ptr), prop.count_enum_blobs, sizeof(struct drm_mode_property_enum)); strncpy(r->name, prop.name, DRM_PROP_NAME_LEN); r->name[DRM_PROP_NAME_LEN-1] = 0; err_allocs: - drmFree(prop.values); - drmFree(prop.enums); + drmFree(U642VOID(prop.values_ptr)); + drmFree(U642VOID(prop.enum_blob_ptr)); return r; } diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index a1d717f9..ec77174b 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -63,6 +63,8 @@ typedef struct _drmModeRes { int count_outputs; uint32_t *outputs; + uint32_t min_width, max_width; + uint32_t min_height, max_height; } drmModeRes, *drmModeResPtr; typedef struct drm_mode_fb_cmd drmModeFB, *drmModeFBPtr; @@ -72,7 +74,7 @@ typedef struct _drmModeProperty { unsigned int flags; unsigned char name[DRM_PROP_NAME_LEN]; int count_values; - uint32_t *values; + uint64_t *values; int count_enums; struct drm_mode_property_enum *enums; @@ -132,7 +134,7 @@ typedef struct _drmModeOutput { int count_props; uint32_t *props; /**< List of property ids */ - uint32_t *prop_values; /**< List of property values */ + uint64_t *prop_values; /**< List of property values */ } drmModeOutput, *drmModeOutputPtr; -- cgit v1.2.3 From c9cda51af5a8bea1d30ce575ae260de52950fe2f Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 5 Dec 2007 16:31:35 +1000 Subject: more WIP on blobs.. I'm going to pass back a list of blob ids and lengths in the getproperty. will need another ioctl to return the blob data as it is variable length. --- libdrm/xf86drmMode.c | 24 +++++++++++++++++++----- libdrm/xf86drmMode.h | 11 +++++++++-- 2 files changed, 28 insertions(+), 7 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index e5191d8c..f4ec004c 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -406,7 +406,8 @@ drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id) { struct drm_mode_get_property prop; drmModePropertyPtr r; - + struct drm_mode_property_blob *blob_tmp; + int i; prop.prop_id = property_id; prop.count_enum_blobs = 0; prop.count_values = 0; @@ -420,9 +421,14 @@ drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id) if (prop.count_values) prop.values_ptr = VOID2U64(drmMalloc(prop.count_values * sizeof(uint64_t))); - if (prop.count_enum_blobs) + if (prop.count_enum_blobs & (prop.flags & DRM_MODE_PROP_ENUM)) prop.enum_blob_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(struct drm_mode_property_enum))); + if (prop.count_enum_blobs & (prop.flags & DRM_MODE_PROP_BLOB)) { + prop.values_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(uint32_t))); + prop.enum_blob_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(uint32_t))); + } + if (ioctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop)) { r = NULL; goto err_allocs; @@ -433,10 +439,18 @@ drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id) r->prop_id = prop.prop_id; r->count_values = prop.count_values; - r->count_enums = prop.count_enum_blobs; + r->flags = prop.flags; - r->values = drmAllocCpy(U642VOID(prop.values_ptr), prop.count_values, sizeof(uint64_t)); - r->enums = drmAllocCpy(U642VOID(prop.enum_blob_ptr), prop.count_enum_blobs, sizeof(struct drm_mode_property_enum)); + if (prop.count_values) + r->values = drmAllocCpy(U642VOID(prop.values_ptr), prop.count_values, sizeof(uint64_t)); + if (prop.flags & DRM_MODE_PROP_ENUM) { + r->count_enums = prop.count_enum_blobs; + r->enums = drmAllocCpy(U642VOID(prop.enum_blob_ptr), prop.count_enum_blobs, sizeof(struct drm_mode_property_enum)); + } else if (prop.flags & DRM_MODE_PROP_ENUM) { + r->values = drmAllocCpy(U642VOID(prop.values_ptr), prop.count_enum_blobs, sizeof(uint32_t)); + r->blob_ids = drmAllocCpy(U642VOID(prop.enum_blob_ptr), prop.count_enum_blobs, sizeof(uint32_t)); + r->count_blobs = prop.count_enum_blobs; + } strncpy(r->name, prop.name, DRM_PROP_NAME_LEN); r->name[DRM_PROP_NAME_LEN-1] = 0; diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index ec77174b..e936044b 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -69,15 +69,22 @@ typedef struct _drmModeRes { typedef struct drm_mode_fb_cmd drmModeFB, *drmModeFBPtr; +typedef struct _drmModePropertyBlob { + uint32_t id; + uint32_t length; + void *data; +} drmModePropertyBlobRes, *drmModePropertyBlobPtr; + typedef struct _drmModeProperty { unsigned int prop_id; unsigned int flags; unsigned char name[DRM_PROP_NAME_LEN]; int count_values; - uint64_t *values; + uint64_t *values; // store the blob lengths int count_enums; struct drm_mode_property_enum *enums; - + int count_blobs; + uint32_t *blob_ids; // store the blob IDs } drmModePropertyRes, *drmModePropertyPtr; typedef struct _drmModeCrtc { -- cgit v1.2.3 From 67f6eb1eb8d3dc5bb5fdb097655d3da326f637c1 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 6 Dec 2007 10:44:51 +1000 Subject: add property blobs and edid reporting support --- libdrm/xf86drmMode.c | 41 +++++++++++++++++++++++++++++++++++++++++ libdrm/xf86drmMode.h | 3 +++ 2 files changed, 44 insertions(+) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index f4ec004c..03bd15f1 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -470,3 +470,44 @@ void drmModeFreeProperty(drmModePropertyPtr ptr) drmFree(ptr->enums); drmFree(ptr); } + +drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id) +{ + struct drm_mode_get_blob blob; + drmModePropertyBlobPtr r; + + blob.length = 0; + blob.data = 0; + blob.blob_id = blob_id; + + if (ioctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &blob)) + return NULL; + + if (blob.length) + blob.data = VOID2U64(drmMalloc(blob.length)); + + if (ioctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &blob)) { + r = NULL; + goto err_allocs; + } + + if (!(r = drmMalloc(sizeof(*r)))) + return NULL; + + r->id = blob.blob_id; + r->length = blob.length; + r->data = drmAllocCpy(U642VOID(blob.data), 1, blob.length); + +err_allocs: + drmFree(U642VOID(blob.data)); + return r; +} + +void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr) +{ + if (!ptr) + return; + + drmFree(ptr->data); + drmFree(ptr); +} diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index e936044b..6fcf6a19 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -220,3 +220,6 @@ extern int drmModeDetachMode(int fd, uint32_t outputId, struct drm_mode_modeinfo extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId); extern void drmModeFreeProperty(drmModePropertyPtr ptr); + +extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id); +extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr); -- cgit v1.2.3 From 3b6786e3e6523b1ceca3645ea4c6081f170d2134 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 11 Dec 2007 14:46:51 +1000 Subject: modesetting: add dpms property and initial settable property ioctl --- libdrm/xf86drmMode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 03bd15f1..7e2683ea 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -421,10 +421,10 @@ drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id) if (prop.count_values) prop.values_ptr = VOID2U64(drmMalloc(prop.count_values * sizeof(uint64_t))); - if (prop.count_enum_blobs & (prop.flags & DRM_MODE_PROP_ENUM)) + if (prop.count_enum_blobs && (prop.flags & DRM_MODE_PROP_ENUM)) prop.enum_blob_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(struct drm_mode_property_enum))); - if (prop.count_enum_blobs & (prop.flags & DRM_MODE_PROP_BLOB)) { + if (prop.count_enum_blobs && (prop.flags & DRM_MODE_PROP_BLOB)) { prop.values_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(uint32_t))); prop.enum_blob_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(uint32_t))); } -- cgit v1.2.3 From f99dea7db00dd46aa96eaed3a61dff9c956fd86f Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 11 Dec 2007 15:56:48 +1000 Subject: modesetting: fixup property setting and add connector property --- libdrm/xf86drmMode.c | 18 ++++++++++++++++++ libdrm/xf86drmMode.h | 2 ++ 2 files changed, 20 insertions(+) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 7e2683ea..726c55ab 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -214,6 +214,8 @@ int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, int drmModeRmFB(int fd, uint32_t bufferId) { return ioctl(fd, DRM_IOCTL_MODE_RMFB, &bufferId); + + } drmModeFBPtr drmModeGetFB(int fd, uint32_t buf) @@ -511,3 +513,19 @@ void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr) drmFree(ptr->data); drmFree(ptr); } + +int drmModeOutputSetProperty(int fd, uint32_t output_id, uint32_t property_id, + uint64_t value) +{ + struct drm_mode_output_set_property osp; + int ret; + + osp.output_id = output_id; + osp.prop_id = property_id; + osp.value = value; + + if (ret = ioctl(fd, DRM_IOCTL_MODE_SETPROPERTY, &osp)) + return ret; + + return 0; +} diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 6fcf6a19..05b61bc8 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -223,3 +223,5 @@ extern void drmModeFreeProperty(drmModePropertyPtr ptr); extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id); extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr); +extern int drmModeOutputSetProperty(int fd, uint32_t output_id, uint32_t property_id, + uint64_t value); -- cgit v1.2.3 From b13dc383df85d75cb1ea422f4d13efc2a4a8a732 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 18 Dec 2007 17:41:20 +1100 Subject: remove output names --- libdrm/xf86drmMode.c | 6 ++++-- libdrm/xf86drmMode.h | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 726c55ab..0edb1d7d 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -328,6 +328,8 @@ drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) drmModeOutputPtr r = NULL; out.output = output_id; + out.output_type_id = 0; + out.output_type = 0; out.count_crtcs = 0; out.crtcs = 0; out.count_clones = 0; @@ -372,8 +374,8 @@ drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) r->props = drmAllocCpy(U642VOID(out.props_ptr), out.count_props, sizeof(uint32_t)); r->prop_values = drmAllocCpy(U642VOID(out.prop_values_ptr), out.count_props, sizeof(uint64_t)); r->modes = drmAllocCpy(U642VOID(out.modes_ptr), out.count_modes, sizeof(struct drm_mode_modeinfo)); - strncpy(r->name, out.name, DRM_OUTPUT_NAME_LEN); - r->name[DRM_OUTPUT_NAME_LEN-1] = 0; + r->output_type = out.output_type; + r->output_type_id = out.output_type_id; err_allocs: drmFree(U642VOID(out.prop_values_ptr)); diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 05b61bc8..e2dda8ac 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -125,7 +125,8 @@ typedef struct _drmModeOutput { unsigned int output_id; unsigned int crtc; /**< Crtc currently connected to */ - unsigned char name[DRM_OUTPUT_NAME_LEN]; + unsigned int output_type; + unsigned int output_type_id; drmModeConnection connection; uint32_t mmWidth, mmHeight; /**< HxW in millimeters */ drmModeSubPixel subpixel; -- cgit v1.2.3 From 73bf5e867089b58b2c4baaa833d15a2b1fb268a4 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 9 Jan 2008 16:44:31 +1100 Subject: add internals for opening a control node --- libdrm/xf86drm.c | 21 ++++++++++++--------- libdrm/xf86drm.h | 1 + 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index 4265c320..2d7d85c1 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -87,6 +87,9 @@ #define DRM_MSG_VERBOSITY 3 +#define DRM_NODE_CONTROL 0 +#define DRM_NODE_RENDER 1 + static drmServerInfoPtr drm_server_info; void drmSetServerInfo(drmServerInfoPtr info) @@ -264,7 +267,7 @@ static int drmMatchBusID(const char *id1, const char *id2) * special file node with the major and minor numbers specified by \p dev and * parent directory if necessary and was called by root. */ -static int drmOpenDevice(long dev, int minor) +static int drmOpenDevice(long dev, int minor, int type) { stat_t st; char buf[64]; @@ -274,7 +277,7 @@ static int drmOpenDevice(long dev, int minor) uid_t user = DRM_DEV_UID; gid_t group = DRM_DEV_GID, serv_group; - sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, minor); + sprintf(buf, type ? DRM_DEV_NAME : DRM_CONTROL_DEV_NAME, DRM_DIR_NAME, minor); drmMsg("drmOpenDevice: node name is %s\n", buf); if (drm_server_info) { @@ -348,15 +351,15 @@ static int drmOpenDevice(long dev, int minor) * Calls drmOpenDevice() if \p create is set, otherwise assembles the device * name from \p minor and opens it. */ -static int drmOpenMinor(int minor, int create) +static int drmOpenMinor(int minor, int create, int type) { int fd; char buf[64]; if (create) - return drmOpenDevice(makedev(DRM_MAJOR, minor), minor); + return drmOpenDevice(makedev(DRM_MAJOR, minor), minor, type); - sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, minor); + sprintf(buf, type ? DRM_DEV_NAME : DRM_CONTROL_DEV_NAME, DRM_DIR_NAME, minor); if ((fd = open(buf, O_RDWR, 0)) >= 0) return fd; return -errno; @@ -379,7 +382,7 @@ int drmAvailable(void) int retval = 0; int fd; - if ((fd = drmOpenMinor(0, 1)) < 0) { + if ((fd = drmOpenMinor(0, 1, DRM_NODE_RENDER)) < 0) { #ifdef __linux__ /* Try proc for backward Linux compatibility */ if (!access("/proc/dri/0", R_OK)) @@ -420,7 +423,7 @@ static int drmOpenByBusid(const char *busid) drmMsg("drmOpenByBusid: Searching for BusID %s\n", busid); for (i = 0; i < DRM_MAX_MINOR; i++) { - fd = drmOpenMinor(i, 1); + fd = drmOpenMinor(i, 1, DRM_NODE_RENDER); drmMsg("drmOpenByBusid: drmOpenMinor returns %d\n", fd); if (fd >= 0) { sv.drm_di_major = 1; @@ -482,7 +485,7 @@ static int drmOpenByName(const char *name) * already in use. If it's in use it will have a busid assigned already. */ for (i = 0; i < DRM_MAX_MINOR; i++) { - if ((fd = drmOpenMinor(i, 1)) >= 0) { + if ((fd = drmOpenMinor(i, 1, DRM_NODE_RENDER)) >= 0) { if ((version = drmGetVersion(fd))) { if (!strcmp(version->name, name)) { drmFreeVersion(version); @@ -526,7 +529,7 @@ static int drmOpenByName(const char *name) if (*pt) { /* Found busid */ return drmOpenByBusid(++pt); } else { /* No busid */ - return drmOpenDevice(strtol(devstring, NULL, 0),i); + return drmOpenDevice(strtol(devstring, NULL, 0),i, DRM_NODE_RENDER); } } } diff --git a/libdrm/xf86drm.h b/libdrm/xf86drm.h index 230f54ce..d6e98825 100644 --- a/libdrm/xf86drm.h +++ b/libdrm/xf86drm.h @@ -49,6 +49,7 @@ #define DRM_DIR_NAME "/dev/dri" #define DRM_DEV_NAME "%s/card%d" +#define DRM_CONTROL_DEV_NAME "%s/controlD%d" #define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */ #define DRM_ERR_NO_DEVICE (-1001) -- cgit v1.2.3 From 87a32efcdde124df59656e00a402ba50a0ba1e45 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 9 Jan 2008 18:11:04 +1100 Subject: add control node open --- libdrm/xf86drm.c | 4 ++++ libdrm/xf86drm.h | 1 + 2 files changed, 5 insertions(+) (limited to 'libdrm') diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index 2d7d85c1..3cc54f12 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -579,6 +579,10 @@ int drmOpen(const char *name, const char *busid) return -1; } +int drmOpenControl(int minor) +{ + return drmOpenMinor(minor, 0, DRM_NODE_CONTROL); +} /** * Free the version information returned by drmGetVersion(). diff --git a/libdrm/xf86drm.h b/libdrm/xf86drm.h index d6e98825..7b418604 100644 --- a/libdrm/xf86drm.h +++ b/libdrm/xf86drm.h @@ -509,6 +509,7 @@ do { register unsigned int __old __asm("o0"); \ /* General user-level programmer's API: unprivileged */ extern int drmAvailable(void); extern int drmOpen(const char *name, const char *busid); +extern int drmOpenControl(int minor); extern int drmClose(int fd); extern drmVersionPtr drmGetVersion(int fd); extern drmVersionPtr drmGetLibVersion(int fd); -- cgit v1.2.3 From a2254c5a9670a3e865f0eb5acd46e905c9b146ce Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Mon, 28 Jan 2008 03:12:29 +0100 Subject: Added cursor support --- libdrm/xf86drmMode.c | 28 ++++++++++++++++++++++++++++ libdrm/xf86drmMode.h | 13 +++++++++++++ 2 files changed, 41 insertions(+) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 0edb1d7d..86572872 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -317,6 +317,34 @@ int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, return ioctl(fd, DRM_IOCTL_MODE_SETCRTC, &crtc); } +/* + * Cursor manipulation + */ + +int drmModeSetCursor(int fd, uint32_t crtcId, drmBO *bo, uint32_t width, uint32_t height) +{ + struct drm_mode_cursor arg; + + arg.flags = DRM_MODE_CURSOR_BO; + arg.crtc = crtcId; + arg.width = width; + arg.height = height; + arg.handle = bo->handle; + + return ioctl(fd, DRM_IOCTL_MODE_CURSOR, &arg); +} + +int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y) +{ + struct drm_mode_cursor arg; + + arg.flags = DRM_MODE_CURSOR_MOVE; + arg.crtc = crtcId; + arg.x = x; + arg.y = y; + + return ioctl(fd, DRM_IOCTL_MODE_CURSOR, &arg); +} /* * Output manipulation diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index e2dda8ac..f5b3337c 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -197,6 +197,19 @@ int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, uint32_t x, uint32_t y, uint32_t *outputs, int count, struct drm_mode_modeinfo *mode); +/* + * Cursor functions + */ + +/** + * Set the cursor on crtc + */ +int drmModeSetCursor(int fd, uint32_t crtcId, drmBO *bo, uint32_t width, uint32_t height); + +/** + * Move the cursor on crtc + */ +int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y); /* * Output manipulation -- cgit v1.2.3 From 841ef9eb8da8058d6495e9f8e1b14af2709dfaa1 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 30 Jan 2008 15:47:26 +0100 Subject: ModeFB demo now display cursor --- libdrm/xf86drmMode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 86572872..681ad417 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -329,7 +329,10 @@ int drmModeSetCursor(int fd, uint32_t crtcId, drmBO *bo, uint32_t width, uint32_ arg.crtc = crtcId; arg.width = width; arg.height = height; - arg.handle = bo->handle; + if (bo) + arg.handle = bo->handle; + else + arg.handle = 0; return ioctl(fd, DRM_IOCTL_MODE_CURSOR, &arg); } -- cgit v1.2.3 From 5997e10ca75ac87fd54b3bc0035938e1a9ad7929 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Tue, 5 Feb 2008 15:15:13 +0000 Subject: consistency --- libdrm/xf86drmMode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index f5b3337c..e878c40a 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -78,7 +78,7 @@ typedef struct _drmModePropertyBlob { typedef struct _drmModeProperty { unsigned int prop_id; unsigned int flags; - unsigned char name[DRM_PROP_NAME_LEN]; + char name[DRM_PROP_NAME_LEN]; int count_values; uint64_t *values; // store the blob lengths int count_enums; -- cgit v1.2.3 From c8b45e9362aa16fed08540996af6d0b1e2e730d0 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 7 Feb 2008 19:25:52 +0100 Subject: Added userspace part of hotplug ioctl and demo --- libdrm/xf86drmMode.c | 9 +++++++++ libdrm/xf86drmMode.h | 4 ++++ 2 files changed, 13 insertions(+) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 681ad417..52fef81b 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -191,6 +191,15 @@ err_allocs: return r; } +uint32_t drmModeGetHotplug(int fd) +{ + struct drm_mode_hotplug arg; + arg.counter = 0; + + ioctl(fd, DRM_IOCTL_MODE_HOTPLUG, &arg); + return arg.counter; +} + int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, uint8_t bpp, uint32_t pitch, drmBO *bo, uint32_t *buf_id) { diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index e878c40a..7cc3ceca 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -159,6 +159,10 @@ extern void drmModeFreeOutput( drmModeOutputPtr ptr ); */ extern drmModeResPtr drmModeGetResources(int fd); +/** + * Retrives the hotplug counter + */ +extern uint32_t drmModeGetHotplug(int fd); /* * FrameBuffer manipulation. -- cgit v1.2.3 From f51dc37d75b0b1b8e5636f8f2c201e29986517ea Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Thu, 7 Feb 2008 22:21:50 +0000 Subject: After the previous revert fix libdrm to start at minor 1 and fixup the demos --- libdrm/xf86drm.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index 39a849c6..8849f8bc 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -355,7 +355,7 @@ static int drmOpenMinor(int minor, int create, int type) { int fd; char buf[64]; - + if (create) return drmOpenDevice(makedev(DRM_MAJOR, minor), minor, type); @@ -421,8 +421,15 @@ static int drmOpenByBusid(const char *busid) const char *buf; drmSetVersion sv; + /* + * Open the first minor number that matches the driver name and isn't + * already in use. If it's in use it will have a busid assigned already. + * + * start at 1, as 0 is the control node, and we should use drmOpenControl + * for that. + */ drmMsg("drmOpenByBusid: Searching for BusID %s\n", busid); - for (i = 0; i < DRM_MAX_MINOR; i++) { + for (i = 1; i < DRM_MAX_MINOR; i++) { fd = drmOpenMinor(i, 1, DRM_NODE_RENDER); drmMsg("drmOpenByBusid: drmOpenMinor returns %d\n", fd); if (fd >= 0) { @@ -467,24 +474,14 @@ static int drmOpenByName(const char *name) drmVersionPtr version; char * id; - if (!drmAvailable()) { - if (!drm_server_info) { - return -1; - } - else { - /* try to load the kernel module now */ - if (!drm_server_info->load_module(name)) { - drmMsg("[drm] failed to load kernel module \"%s\"\n", name); - return -1; - } - } - } - /* * Open the first minor number that matches the driver name and isn't * already in use. If it's in use it will have a busid assigned already. + * + * start at 1, as 0 is the control node, and we should use drmOpenControl + * for that. */ - for (i = 0; i < DRM_MAX_MINOR; i++) { + for (i = 1; i < DRM_MAX_MINOR; i++) { if ((fd = drmOpenMinor(i, 1, DRM_NODE_RENDER)) >= 0) { if ((version = drmGetVersion(fd))) { if (!strcmp(version->name, name)) { -- cgit v1.2.3 From db85ed25afc616acfaadb21facf6066354f9d490 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 13 Feb 2008 12:20:02 +1000 Subject: Revert "After the previous revert fix libdrm to start at minor 1" This reverts commit f51dc37d75b0b1b8e5636f8f2c201e29986517ea. Conflicts: tests/modedemo/demo.c --- libdrm/xf86drm.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index 8849f8bc..39a849c6 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -355,7 +355,7 @@ static int drmOpenMinor(int minor, int create, int type) { int fd; char buf[64]; - + if (create) return drmOpenDevice(makedev(DRM_MAJOR, minor), minor, type); @@ -421,15 +421,8 @@ static int drmOpenByBusid(const char *busid) const char *buf; drmSetVersion sv; - /* - * Open the first minor number that matches the driver name and isn't - * already in use. If it's in use it will have a busid assigned already. - * - * start at 1, as 0 is the control node, and we should use drmOpenControl - * for that. - */ drmMsg("drmOpenByBusid: Searching for BusID %s\n", busid); - for (i = 1; i < DRM_MAX_MINOR; i++) { + for (i = 0; i < DRM_MAX_MINOR; i++) { fd = drmOpenMinor(i, 1, DRM_NODE_RENDER); drmMsg("drmOpenByBusid: drmOpenMinor returns %d\n", fd); if (fd >= 0) { @@ -474,14 +467,24 @@ static int drmOpenByName(const char *name) drmVersionPtr version; char * id; + if (!drmAvailable()) { + if (!drm_server_info) { + return -1; + } + else { + /* try to load the kernel module now */ + if (!drm_server_info->load_module(name)) { + drmMsg("[drm] failed to load kernel module \"%s\"\n", name); + return -1; + } + } + } + /* * Open the first minor number that matches the driver name and isn't * already in use. If it's in use it will have a busid assigned already. - * - * start at 1, as 0 is the control node, and we should use drmOpenControl - * for that. */ - for (i = 1; i < DRM_MAX_MINOR; i++) { + for (i = 0; i < DRM_MAX_MINOR; i++) { if ((fd = drmOpenMinor(i, 1, DRM_NODE_RENDER)) >= 0) { if ((version = drmGetVersion(fd))) { if (!strcmp(version->name, name)) { -- cgit v1.2.3 From cdad850ebc3570e5ff5a0996f36832c965aa8a1d Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 20 Feb 2008 13:27:10 +1000 Subject: add ioctl to get back memory managed area sized - used for kernel inited areas --- libdrm/xf86drm.c | 15 +++++++++++++++ libdrm/xf86mm.h | 1 + 2 files changed, 16 insertions(+) (limited to 'libdrm') diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index 39a849c6..13e99555 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -2883,6 +2883,21 @@ int drmMMUnlock(int fd, unsigned memType, int unlockBM) return drmIoctlTimeout(fd, DRM_IOCTL_MM_UNLOCK, &arg); } +int drmMMInfo(int fd, unsigned memType, uint64_t *size) +{ + struct drm_mm_info_arg arg; + + memset(&arg, 0, sizeof(arg)); + + arg.mem_type = memType; + + if (ioctl(fd, DRM_IOCTL_MM_INFO, &arg)) + return -errno; + + *size = arg.p_size; + return 0; +} + int drmBOVersion(int fd, unsigned int *major, unsigned int *minor, unsigned int *patchlevel) diff --git a/libdrm/xf86mm.h b/libdrm/xf86mm.h index c80288a7..bb573407 100644 --- a/libdrm/xf86mm.h +++ b/libdrm/xf86mm.h @@ -172,6 +172,7 @@ extern int drmMMInit(int fd, unsigned long pOffset, unsigned long pSize, extern int drmMMTakedown(int fd, unsigned memType); extern int drmMMLock(int fd, unsigned memType, int lockBM, int ignoreNoEvict); extern int drmMMUnlock(int fd, unsigned memType, int unlockBM); +extern int drmMMInfo(int fd, unsigned memType, uint64_t *size); extern int drmBOSetStatus(int fd, drmBO *buf, uint64_t flags, uint64_t mask, unsigned int hint, -- cgit v1.2.3 From 132ba667f4a88bb182e2d2abc7c4e60699398380 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 28 Feb 2008 12:59:39 +1000 Subject: drm: add a check for if modesetting is supported. This is Linux only code, it just uses sysfs to see if a control device has been registered on the requested PCI ID --- libdrm/xf86drmMode.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ libdrm/xf86drmMode.h | 1 + 2 files changed, 49 insertions(+) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 52fef81b..717e1fe2 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -41,6 +41,8 @@ #include "xf86drm.h" #include #include +#include +#include #define U642VOID(x) ((void *)(unsigned long)(x)) #define VOID2U64(x) ((uint64_t)(unsigned long)(x)) @@ -571,3 +573,49 @@ int drmModeOutputSetProperty(int fd, uint32_t output_id, uint32_t property_id, return 0; } + +/* + * checks if a modesetting capable driver has attached to the pci id + * returns 0 if modesetting supported. + * -EINVAL or invalid bus id + * -ENOSYS if no modesetting support +*/ +int drmCheckModesettingSupported(const char *busid) +{ +#ifdef __linux__ + char pci_dev_dir[1024]; + char *bus_id_path; + char *bus_type; + int domain, bus, dev, func; + DIR *sysdir; + struct dirent *dent; + int found = 0, ret; + + ret = sscanf(busid, "pci:%04x:%02x:%02x.%d", &domain, &bus, &dev, &func); + if (ret != 4) + return -EINVAL; + + sprintf(pci_dev_dir, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/", + domain, bus, dev, func); + + sysdir = opendir(pci_dev_dir); + if (!sysdir) + return -EINVAL; + + dent = readdir(sysdir); + while (dent) { + if (!strncmp(dent->d_name, "drm:controlD", 12)) { + found = 1; + break; + } + + dent = readdir(sysdir); + } + + closedir(sysdir); + if (found) + return 0; +#endif + return -ENOSYS; + +} diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 7cc3ceca..71e779d4 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -243,3 +243,4 @@ extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id); extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr); extern int drmModeOutputSetProperty(int fd, uint32_t output_id, uint32_t property_id, uint64_t value); +extern int drmCheckModesettingSupported(const char *busid); -- cgit v1.2.3 From 0e72819629741339af46d0e303f33482acdf0972 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 29 Feb 2008 14:07:29 +1000 Subject: drm: change fb api to take a bo handle not the bo pointer. --- libdrm/xf86drmMode.c | 5 +++-- libdrm/xf86drmMode.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 717e1fe2..dd1a6ca9 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -203,7 +203,8 @@ uint32_t drmModeGetHotplug(int fd) } int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, - uint8_t bpp, uint32_t pitch, drmBO *bo, uint32_t *buf_id) + uint8_t bpp, uint32_t pitch, uint32_t bo_handle, + uint32_t *buf_id) { struct drm_mode_fb_cmd f; int ret; @@ -213,7 +214,7 @@ int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, f.pitch = pitch; f.bpp = bpp; f.depth = depth; - f.handle = bo->handle; + f.handle = bo_handle; if (ret = ioctl(fd, DRM_IOCTL_MODE_ADDFB, &f)) return ret; diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 71e779d4..edf9efee 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -177,7 +177,7 @@ extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId); * Creates a new framebuffer with an buffer object as its scanout buffer. */ extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, - uint8_t bpp, uint32_t pitch, drmBO *bo, + uint8_t bpp, uint32_t pitch, uint32_t bo_handle, uint32_t *buf_id); /** * Destroies the given framebuffer. -- cgit v1.2.3 From 81db48536c9d7bb23c448af6a6f1de81df755585 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 5 Mar 2008 10:31:43 +1000 Subject: remove unused functions + include header file --- libdrm/xf86drmMode.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index dd1a6ca9..30b434de 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -36,6 +36,7 @@ * platforms find which headers to include to get uint32_t */ #include +#include #include "xf86drmMode.h" #include "xf86drm.h" @@ -68,27 +69,6 @@ void* drmAllocCpy(void *array, int count, int entry_size) return r; } -/** - * Generate crtc and output ids. - * - * Will generate ids starting from 1 up to count if count is greater then 0. - */ -static uint32_t* drmAllocGenerate(int count) -{ - uint32_t *r; - int i; - - if(0 <= count) - return 0; - - if (!(r = drmMalloc(count*sizeof(*r)))) - return 0; - - for (i = 0; i < count; r[i] = ++i); - - return 0; -} - /* * A couple of free functions. */ -- cgit v1.2.3 From 4aa7efe398911bd58fb348703444a92114e45114 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 5 Mar 2008 10:41:54 +1000 Subject: libdrm: fix warnings in mode code --- libdrm/xf86drmMode.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 30b434de..07b14dbf 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -37,6 +37,7 @@ */ #include #include +#include #include "xf86drmMode.h" #include "xf86drm.h" @@ -125,7 +126,6 @@ void drmModeFreeOutput(drmModeOutputPtr ptr) drmModeResPtr drmModeGetResources(int fd) { struct drm_mode_card_res res; - int i; drmModeResPtr r = 0; memset(&res, 0, sizeof(struct drm_mode_card_res)); @@ -196,7 +196,7 @@ int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, f.depth = depth; f.handle = bo_handle; - if (ret = ioctl(fd, DRM_IOCTL_MODE_ADDFB, &f)) + if ((ret = ioctl(fd, DRM_IOCTL_MODE_ADDFB, &f))) return ret; *buf_id = f.buffer_id; @@ -243,7 +243,6 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId) { struct drm_mode_crtc crtc; drmModeCrtcPtr r; - int i = 0; crtc.count_outputs = 0; crtc.outputs = 0; @@ -276,10 +275,6 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId) r->possibles = crtc.possibles; return r; - -err_allocs: - - return 0; } @@ -433,8 +428,7 @@ drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id) { struct drm_mode_get_property prop; drmModePropertyPtr r; - struct drm_mode_property_blob *blob_tmp; - int i; + prop.prop_id = property_id; prop.count_enum_blobs = 0; prop.count_values = 0; @@ -549,7 +543,7 @@ int drmModeOutputSetProperty(int fd, uint32_t output_id, uint32_t property_id, osp.prop_id = property_id; osp.value = value; - if (ret = ioctl(fd, DRM_IOCTL_MODE_SETPROPERTY, &osp)) + if ((ret = ioctl(fd, DRM_IOCTL_MODE_SETPROPERTY, &osp))) return ret; return 0; @@ -565,8 +559,6 @@ int drmCheckModesettingSupported(const char *busid) { #ifdef __linux__ char pci_dev_dir[1024]; - char *bus_id_path; - char *bus_type; int domain, bus, dev, func; DIR *sysdir; struct dirent *dent; -- cgit v1.2.3 From add7d21c79e2bd2012d92bb0043023230ec9aa74 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 7 Mar 2008 08:56:20 +1000 Subject: drm: fixup for new sysfs API --- libdrm/xf86drmMode.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 07b14dbf..f86cc48f 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -568,6 +568,25 @@ int drmCheckModesettingSupported(const char *busid) if (ret != 4) return -EINVAL; + sprintf(pci_dev_dir, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/drm", + domain, bus, dev, func); + + sysdir = opendir(pci_dev_dir); + if (sysdir) { + dent = readdir(sysdir); + while (dent) { + if (!strncmp(dent->d_name, "controlD", 8)) { + found = 1; + break; + } + + dent = readdir(sysdir); + } + closedir(sysdir); + if (found) + return 0; + } + sprintf(pci_dev_dir, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/", domain, bus, dev, func); -- cgit v1.2.3 From 607964ed9e5f6d86a0960bef2341e7f5de9c71da Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 17 Mar 2008 16:37:46 +1000 Subject: drm: add master set/drop protocol this may not survive long - just need something for testing --- libdrm/xf86drm.c | 17 +++++++++++++++++ libdrm/xf86drm.h | 3 +++ 2 files changed, 20 insertions(+) (limited to 'libdrm') diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index bcf562d5..53275f52 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -2977,3 +2977,20 @@ void drmCloseOnce(int fd) } } } + +int drmSetMaster(int fd) +{ + int ret; + + fprintf(stderr,"Setting master \n"); + ret = ioctl(fd, DRM_IOCTL_SET_MASTER, 0); + return ret; +} + +int drmDropMaster(int fd) +{ + int ret; + fprintf(stderr,"Dropping master \n"); + ret = ioctl(fd, DRM_IOCTL_DROP_MASTER, 0); + return ret; +} diff --git a/libdrm/xf86drm.h b/libdrm/xf86drm.h index 7b418604..35780aca 100644 --- a/libdrm/xf86drm.h +++ b/libdrm/xf86drm.h @@ -660,6 +660,9 @@ extern int drmSLLookupNeighbors(void *l, unsigned long key, extern int drmOpenOnce(void *unused, const char *BusID, int *newlyopened); extern void drmCloseOnce(int fd); +extern int drmSetMaster(int fd); +extern int drmDropMaster(int fd); + #include "xf86mm.h" #endif -- cgit v1.2.3 From 9d1db4ced1cd8e9e23f9ae945625a54d4f7f3721 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 8 May 2008 10:26:37 +1000 Subject: cursor: pass handle not BO. --- libdrm/xf86drmMode.c | 7 ++----- libdrm/xf86drmMode.h | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index f86cc48f..605377dd 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -308,7 +308,7 @@ int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, * Cursor manipulation */ -int drmModeSetCursor(int fd, uint32_t crtcId, drmBO *bo, uint32_t width, uint32_t height) +int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height) { struct drm_mode_cursor arg; @@ -316,10 +316,7 @@ int drmModeSetCursor(int fd, uint32_t crtcId, drmBO *bo, uint32_t width, uint32_ arg.crtc = crtcId; arg.width = width; arg.height = height; - if (bo) - arg.handle = bo->handle; - else - arg.handle = 0; + arg.handle = bo_handle; return ioctl(fd, DRM_IOCTL_MODE_CURSOR, &arg); } diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index edf9efee..e5a6ee92 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -208,7 +208,7 @@ int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, /** * Set the cursor on crtc */ -int drmModeSetCursor(int fd, uint32_t crtcId, drmBO *bo, uint32_t width, uint32_t height); +int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height); /** * Move the cursor on crtc -- cgit v1.2.3 From ed072ed075ec431b0746ac1aa8bad5f687d75d8c Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 8 May 2008 14:01:24 +1000 Subject: drm_mode: initial replacefb implemenation --- libdrm/xf86drmMode.c | 21 +++++++++++++++++++++ libdrm/xf86drmMode.h | 6 ++++++ 2 files changed, 27 insertions(+) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 605377dd..ae15fd65 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -608,3 +608,24 @@ int drmCheckModesettingSupported(const char *busid) return -ENOSYS; } + +int drmModeReplaceFB(int fd, uint32_t buffer_id, + uint32_t width, uint32_t height, uint8_t depth, + uint8_t bpp, uint32_t pitch, uint32_t bo_handle) +{ + struct drm_mode_fb_cmd f; + int ret; + + f.width = width; + f.height = height; + f.pitch = pitch; + f.bpp = bpp; + f.depth = depth; + f.handle = bo_handle; + f.buffer_id = buffer_id; + + if ((ret = ioctl(fd, DRM_IOCTL_MODE_REPLACEFB, &f))) + return ret; + + return 0; +} diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index e5a6ee92..5171b592 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -184,6 +184,12 @@ extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, */ extern int drmModeRmFB(int fd, uint32_t bufferId); +/** + * Replace a framebuffer object with a new one - for resizing the screen. + */ +extern int drmModeReplaceFB(int fd, uint32_t buffer_id, + uint32_t width, uint32_t height, uint8_t depth, + uint8_t bpp, uint32_t pitch, uint32_t bo_handle); /* * Crtc functions -- cgit v1.2.3 From 16a8f824face8067029ef6f3d10f1723d87b23f6 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 30 May 2008 12:10:01 +1000 Subject: libdrm: add encoder retrival --- libdrm/xf86drmMode.c | 27 +++++++++++++++++++++++++++ libdrm/xf86drmMode.h | 15 +++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index ae15fd65..e5798f96 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -139,6 +139,8 @@ drmModeResPtr drmModeGetResources(int fd) res.crtc_id_ptr = VOID2U64(drmMalloc(res.count_crtcs*sizeof(uint32_t))); if (res.count_outputs) res.output_id_ptr = VOID2U64(drmMalloc(res.count_outputs*sizeof(uint32_t))); + if (res.count_encoders) + res.encoder_id_ptr = VOID2U64(drmMalloc(res.count_encoders*sizeof(uint32_t))); if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res)) { r = NULL; @@ -164,11 +166,13 @@ drmModeResPtr drmModeGetResources(int fd) r->fbs = drmAllocCpy(U642VOID(res.fb_id_ptr), res.count_fbs, sizeof(uint32_t)); r->crtcs = drmAllocCpy(U642VOID(res.crtc_id_ptr), res.count_crtcs, sizeof(uint32_t)); r->outputs = drmAllocCpy(U642VOID(res.output_id_ptr), res.count_outputs, sizeof(uint32_t)); + r->encoders = drmAllocCpy(U642VOID(res.encoder_id_ptr), res.count_encoders, sizeof(uint32_t)); err_allocs: drmFree(U642VOID(res.fb_id_ptr)); drmFree(U642VOID(res.crtc_id_ptr)); drmFree(U642VOID(res.output_id_ptr)); + drmFree(U642VOID(res.encoder_id_ptr)); return r; } @@ -333,6 +337,29 @@ int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y) return ioctl(fd, DRM_IOCTL_MODE_CURSOR, &arg); } +/* + * Encoder get + */ +drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id) +{ + struct drm_mode_get_encoder enc; + drmModeEncoderPtr r = NULL; + + enc.encoder_id = encoder_id; + enc.encoder_type = 0; + enc.crtcs = 0; + enc.clones = 0; + + if (ioctl(fd, DRM_IOCTL_MODE_GETENCODER, &enc)) + return 0; + + r->encoder_type = enc.encoder_type; + r->crtcs = enc.crtcs; + r->clones = enc.clones; + + return r; +} + /* * Output manipulation */ diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 5171b592..a5ecd099 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -63,6 +63,9 @@ typedef struct _drmModeRes { int count_outputs; uint32_t *outputs; + int count_encoders; + uint32_t *encoders; + uint32_t min_width, max_width; uint32_t min_height, max_height; } drmModeRes, *drmModeResPtr; @@ -106,6 +109,13 @@ typedef struct _drmModeCrtc { } drmModeCrtc, *drmModeCrtcPtr; +typedef struct _drmModeEncoder { + unsigned int encoder_id; + unsigned int encoder_type; + uint32_t crtcs; + uint32_t clones; +} drmModeEncoder, *drmModeEncoderPtr; + typedef enum { DRM_MODE_CONNECTED = 1, DRM_MODE_DISCONNECTED = 2, @@ -221,6 +231,11 @@ int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width */ int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y); +/** + * Encoder functions + */ +drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id); + /* * Output manipulation */ -- cgit v1.2.3 From fae2c17b313e2838652c32ea4a576172b4063639 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 30 May 2008 12:14:44 +1000 Subject: drm: add more encoder interfaces --- libdrm/xf86drmMode.c | 8 ++++++++ libdrm/xf86drmMode.h | 2 ++ 2 files changed, 10 insertions(+) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index e5798f96..672a5e2a 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -381,6 +381,8 @@ drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) out.count_props = 0; out.props_ptr = 0; out.prop_values_ptr = 0; + out.count_encoders = 0; + out.encoders_ptr = 0; if (ioctl(fd, DRM_IOCTL_MODE_GETOUTPUT, &out)) return 0; @@ -393,6 +395,9 @@ drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) if (out.count_modes) out.modes_ptr = VOID2U64(drmMalloc(out.count_modes*sizeof(struct drm_mode_modeinfo))); + if (out.count_encoders) + out.encoders_ptr = VOID2U64(drmMalloc(out.count_encoders*sizeof(uint32_t))); + if (ioctl(fd, DRM_IOCTL_MODE_GETOUTPUT, &out)) goto err_allocs; @@ -416,6 +421,8 @@ drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) r->props = drmAllocCpy(U642VOID(out.props_ptr), out.count_props, sizeof(uint32_t)); r->prop_values = drmAllocCpy(U642VOID(out.prop_values_ptr), out.count_props, sizeof(uint64_t)); r->modes = drmAllocCpy(U642VOID(out.modes_ptr), out.count_modes, sizeof(struct drm_mode_modeinfo)); + r->count_encoders = out.count_encoders; + r->encoders = drmAllocCpy(U642VOID(out.encoders_ptr), out.count_encoders, sizeof(uint32_t)); r->output_type = out.output_type; r->output_type_id = out.output_type_id; @@ -423,6 +430,7 @@ err_allocs: drmFree(U642VOID(out.prop_values_ptr)); drmFree(U642VOID(out.props_ptr)); drmFree(U642VOID(out.modes_ptr)); + drmFree(U642VOID(out.encoders_ptr)); return r; } diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index a5ecd099..601a6460 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -154,6 +154,8 @@ typedef struct _drmModeOutput { uint32_t *props; /**< List of property ids */ uint64_t *prop_values; /**< List of property values */ + int count_encoders; + uint32_t *encoders; /**< List of encoder ids */ } drmModeOutput, *drmModeOutputPtr; -- cgit v1.2.3 From 514147e3f3180b46d3e9e6e906580fe232d4ad26 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 30 May 2008 12:29:45 +1000 Subject: drm: add encoder free function --- libdrm/xf86drmMode.c | 5 +++++ libdrm/xf86drmMode.h | 1 + 2 files changed, 6 insertions(+) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 672a5e2a..78efe827 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -119,6 +119,11 @@ void drmModeFreeOutput(drmModeOutputPtr ptr) } +void drmModeFreeEncoder(drmModeEncoderPtr ptr) +{ + drmFree(ptr); +} + /* * ModeSetting functions. */ diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 601a6460..85e3d912 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -165,6 +165,7 @@ extern void drmModeFreeResources( drmModeResPtr ptr ); extern void drmModeFreeFB( drmModeFBPtr ptr ); extern void drmModeFreeCrtc( drmModeCrtcPtr ptr ); extern void drmModeFreeOutput( drmModeOutputPtr ptr ); +extern void drmModeFreeEncoder( drmModeEncoderPtr ptr ); /** * Retrives all of the resources associated with a card. -- cgit v1.2.3 From 1c4b25a2b1c31df190eab173128702d1b5871906 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 30 May 2008 13:49:39 +1000 Subject: drm: fix a couple of bugs in the encoder return to userspace --- libdrm/xf86drmMode.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 78efe827..0824ec3f 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -167,6 +167,7 @@ drmModeResPtr drmModeGetResources(int fd) r->count_fbs = res.count_fbs; r->count_crtcs = res.count_crtcs; r->count_outputs = res.count_outputs; + r->count_encoders = res.count_encoders; /* TODO we realy should test if these allocs fails. */ r->fbs = drmAllocCpy(U642VOID(res.fb_id_ptr), res.count_fbs, sizeof(uint32_t)); r->crtcs = drmAllocCpy(U642VOID(res.crtc_id_ptr), res.count_crtcs, sizeof(uint32_t)); @@ -358,6 +359,9 @@ drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id) if (ioctl(fd, DRM_IOCTL_MODE_GETENCODER, &enc)) return 0; + if (!(r = drmMalloc(sizeof(*r)))) + return 0; + r->encoder_type = enc.encoder_type; r->crtcs = enc.crtcs; r->clones = enc.clones; -- cgit v1.2.3 From 9d38448ed33aaff324cc4bbe1e0878593e97d07d Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 30 May 2008 15:03:12 +1000 Subject: modesetting: the great renaming. Okay we have crtc, encoder and connectors. No more outputs exposed beyond driver internals I've broken intel tv connector stuff. Really for TV we should have one TV connector, with a sub property for the type of signal been driven over it --- libdrm/xf86drmMode.c | 148 +++++++++++++++++++++++++-------------------------- libdrm/xf86drmMode.h | 42 +++++++-------- 2 files changed, 95 insertions(+), 95 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 0824ec3f..a18c4290 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -109,7 +109,7 @@ void drmModeFreeCrtc(drmModeCrtcPtr ptr) } -void drmModeFreeOutput(drmModeOutputPtr ptr) +void drmModeFreeConnector(drmModeConnectorPtr ptr) { if (!ptr) return; @@ -142,8 +142,8 @@ drmModeResPtr drmModeGetResources(int fd) res.fb_id_ptr = VOID2U64(drmMalloc(res.count_fbs*sizeof(uint32_t))); if (res.count_crtcs) res.crtc_id_ptr = VOID2U64(drmMalloc(res.count_crtcs*sizeof(uint32_t))); - if (res.count_outputs) - res.output_id_ptr = VOID2U64(drmMalloc(res.count_outputs*sizeof(uint32_t))); + if (res.count_connectors) + res.connector_id_ptr = VOID2U64(drmMalloc(res.count_connectors*sizeof(uint32_t))); if (res.count_encoders) res.encoder_id_ptr = VOID2U64(drmMalloc(res.count_encoders*sizeof(uint32_t))); @@ -166,18 +166,18 @@ drmModeResPtr drmModeGetResources(int fd) r->max_height = res.max_height; r->count_fbs = res.count_fbs; r->count_crtcs = res.count_crtcs; - r->count_outputs = res.count_outputs; + r->count_connectors = res.count_connectors; r->count_encoders = res.count_encoders; /* TODO we realy should test if these allocs fails. */ r->fbs = drmAllocCpy(U642VOID(res.fb_id_ptr), res.count_fbs, sizeof(uint32_t)); r->crtcs = drmAllocCpy(U642VOID(res.crtc_id_ptr), res.count_crtcs, sizeof(uint32_t)); - r->outputs = drmAllocCpy(U642VOID(res.output_id_ptr), res.count_outputs, sizeof(uint32_t)); + r->connectors = drmAllocCpy(U642VOID(res.connector_id_ptr), res.count_connectors, sizeof(uint32_t)); r->encoders = drmAllocCpy(U642VOID(res.encoder_id_ptr), res.count_encoders, sizeof(uint32_t)); err_allocs: drmFree(U642VOID(res.fb_id_ptr)); drmFree(U642VOID(res.crtc_id_ptr)); - drmFree(U642VOID(res.output_id_ptr)); + drmFree(U642VOID(res.connector_id_ptr)); drmFree(U642VOID(res.encoder_id_ptr)); return r; @@ -254,8 +254,8 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId) struct drm_mode_crtc crtc; drmModeCrtcPtr r; - crtc.count_outputs = 0; - crtc.outputs = 0; + crtc.count_connectors = 0; + crtc.connectors = 0; crtc.count_possibles = 0; crtc.possibles = 0; crtc.crtc_id = crtcId; @@ -278,10 +278,10 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId) memcpy(&r->mode, &crtc.mode, sizeof(struct drm_mode_modeinfo)); r->buffer_id = crtc.fb_id; r->gamma_size = crtc.gamma_size; - r->count_outputs = crtc.count_outputs; + r->count_connectors = crtc.count_connectors; r->count_possibles = crtc.count_possibles; /* TODO we realy should test if these alloc & cpy fails. */ - r->outputs = crtc.outputs; + r->connectors = crtc.connectors; r->possibles = crtc.possibles; return r; @@ -289,13 +289,13 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId) int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, - uint32_t x, uint32_t y, uint32_t *outputs, int count, + uint32_t x, uint32_t y, uint32_t *connectors, int count, struct drm_mode_modeinfo *mode) { struct drm_mode_crtc crtc; - crtc.count_outputs = 0; - crtc.outputs = 0; + crtc.count_connectors = 0; + crtc.connectors = 0; crtc.count_possibles = 0; crtc.possibles = 0; @@ -303,8 +303,8 @@ int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, crtc.y = y; crtc.crtc_id = crtcId; crtc.fb_id = bufferId; - crtc.set_outputs_ptr = VOID2U64(outputs); - crtc.count_outputs = count; + crtc.set_connectors_ptr = VOID2U64(connectors); + crtc.count_connectors = count; if (mode) { memcpy(&crtc.mode, mode, sizeof(struct drm_mode_modeinfo)); crtc.mode_valid = 1; @@ -370,96 +370,96 @@ drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id) } /* - * Output manipulation + * Connector manipulation */ -drmModeOutputPtr drmModeGetOutput(int fd, uint32_t output_id) +drmModeConnectorPtr drmModeGetConnector(int fd, uint32_t connector_id) { - struct drm_mode_get_output out; - drmModeOutputPtr r = NULL; - - out.output = output_id; - out.output_type_id = 0; - out.output_type = 0; - out.count_crtcs = 0; - out.crtcs = 0; - out.count_clones = 0; - out.clones = 0; - out.count_modes = 0; - out.modes_ptr = 0; - out.count_props = 0; - out.props_ptr = 0; - out.prop_values_ptr = 0; - out.count_encoders = 0; - out.encoders_ptr = 0; - - if (ioctl(fd, DRM_IOCTL_MODE_GETOUTPUT, &out)) + struct drm_mode_get_connector conn; + drmModeConnectorPtr r = NULL; + + conn.connector = connector_id; + conn.connector_type_id = 0; + conn.connector_type = 0; + conn.count_crtcs = 0; + conn.crtcs = 0; + conn.count_clones = 0; + conn.clones = 0; + conn.count_modes = 0; + conn.modes_ptr = 0; + conn.count_props = 0; + conn.props_ptr = 0; + conn.prop_values_ptr = 0; + conn.count_encoders = 0; + conn.encoders_ptr = 0; + + if (ioctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn)) return 0; - if (out.count_props) { - out.props_ptr = VOID2U64(drmMalloc(out.count_props*sizeof(uint32_t))); - out.prop_values_ptr = VOID2U64(drmMalloc(out.count_props*sizeof(uint64_t))); + if (conn.count_props) { + conn.props_ptr = VOID2U64(drmMalloc(conn.count_props*sizeof(uint32_t))); + conn.prop_values_ptr = VOID2U64(drmMalloc(conn.count_props*sizeof(uint64_t))); } - if (out.count_modes) - out.modes_ptr = VOID2U64(drmMalloc(out.count_modes*sizeof(struct drm_mode_modeinfo))); + if (conn.count_modes) + conn.modes_ptr = VOID2U64(drmMalloc(conn.count_modes*sizeof(struct drm_mode_modeinfo))); - if (out.count_encoders) - out.encoders_ptr = VOID2U64(drmMalloc(out.count_encoders*sizeof(uint32_t))); + if (conn.count_encoders) + conn.encoders_ptr = VOID2U64(drmMalloc(conn.count_encoders*sizeof(uint32_t))); - if (ioctl(fd, DRM_IOCTL_MODE_GETOUTPUT, &out)) + if (ioctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn)) goto err_allocs; if(!(r = drmMalloc(sizeof(*r)))) { goto err_allocs; } - r->output_id = out.output; - r->crtc = out.crtc; - r->connection = out.connection; - r->mmWidth = out.mm_width; - r->mmHeight = out.mm_height; - r->subpixel = out.subpixel; - r->count_crtcs = out.count_crtcs; - r->count_clones = out.count_clones; - r->count_modes = out.count_modes; + r->connector_id = conn.connector; + r->crtc = conn.crtc; + r->connection = conn.connection; + r->mmWidth = conn.mm_width; + r->mmHeight = conn.mm_height; + r->subpixel = conn.subpixel; + r->count_crtcs = conn.count_crtcs; + r->count_clones = conn.count_clones; + r->count_modes = conn.count_modes; /* TODO we should test if these alloc & cpy fails. */ - r->crtcs = out.crtcs; - r->clones = out.clones; - r->count_props = out.count_props; - r->props = drmAllocCpy(U642VOID(out.props_ptr), out.count_props, sizeof(uint32_t)); - r->prop_values = drmAllocCpy(U642VOID(out.prop_values_ptr), out.count_props, sizeof(uint64_t)); - r->modes = drmAllocCpy(U642VOID(out.modes_ptr), out.count_modes, sizeof(struct drm_mode_modeinfo)); - r->count_encoders = out.count_encoders; - r->encoders = drmAllocCpy(U642VOID(out.encoders_ptr), out.count_encoders, sizeof(uint32_t)); - r->output_type = out.output_type; - r->output_type_id = out.output_type_id; + r->crtcs = conn.crtcs; + r->clones = conn.clones; + r->count_props = conn.count_props; + r->props = drmAllocCpy(U642VOID(conn.props_ptr), conn.count_props, sizeof(uint32_t)); + r->prop_values = drmAllocCpy(U642VOID(conn.prop_values_ptr), conn.count_props, sizeof(uint64_t)); + r->modes = drmAllocCpy(U642VOID(conn.modes_ptr), conn.count_modes, sizeof(struct drm_mode_modeinfo)); + r->count_encoders = conn.count_encoders; + r->encoders = drmAllocCpy(U642VOID(conn.encoders_ptr), conn.count_encoders, sizeof(uint32_t)); + r->connector_type = conn.connector_type; + r->connector_type_id = conn.connector_type_id; err_allocs: - drmFree(U642VOID(out.prop_values_ptr)); - drmFree(U642VOID(out.props_ptr)); - drmFree(U642VOID(out.modes_ptr)); - drmFree(U642VOID(out.encoders_ptr)); + drmFree(U642VOID(conn.prop_values_ptr)); + drmFree(U642VOID(conn.props_ptr)); + drmFree(U642VOID(conn.modes_ptr)); + drmFree(U642VOID(conn.encoders_ptr)); return r; } -int drmModeAttachMode(int fd, uint32_t output_id, struct drm_mode_modeinfo *mode_info) +int drmModeAttachMode(int fd, uint32_t connector_id, struct drm_mode_modeinfo *mode_info) { struct drm_mode_mode_cmd res; memcpy(&res.mode, mode_info, sizeof(struct drm_mode_modeinfo)); - res.output_id = output_id; + res.connector_id = connector_id; return ioctl(fd, DRM_IOCTL_MODE_ATTACHMODE, &res); } -int drmModeDetachMode(int fd, uint32_t output_id, struct drm_mode_modeinfo *mode_info) +int drmModeDetachMode(int fd, uint32_t connector_id, struct drm_mode_modeinfo *mode_info) { struct drm_mode_mode_cmd res; memcpy(&res.mode, mode_info, sizeof(struct drm_mode_modeinfo)); - res.output_id = output_id; + res.connector_id = connector_id; return ioctl(fd, DRM_IOCTL_MODE_DETACHMODE, &res); } @@ -574,13 +574,13 @@ void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr) drmFree(ptr); } -int drmModeOutputSetProperty(int fd, uint32_t output_id, uint32_t property_id, +int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id, uint64_t value) { - struct drm_mode_output_set_property osp; + struct drm_mode_connector_set_property osp; int ret; - osp.output_id = output_id; + osp.connector_id = connector_id; osp.prop_id = property_id; osp.value = value; diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 85e3d912..03268b10 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -60,8 +60,8 @@ typedef struct _drmModeRes { int count_crtcs; uint32_t *crtcs; - int count_outputs; - uint32_t *outputs; + int count_connectors; + uint32_t *connectors; int count_encoders; uint32_t *encoders; @@ -99,11 +99,11 @@ typedef struct _drmModeCrtc { int mode_valid; struct drm_mode_modeinfo mode; - int count_outputs; - uint32_t outputs; /**< Outputs that are connected */ + int count_connectors; + uint32_t connectors; /**< Connectors that are connected */ int count_possibles; - uint32_t possibles; /**< Outputs that can be connected */ + uint32_t possibles; /**< Connectors that can be connected */ int gamma_size; /**< Number of gamma stops */ @@ -131,12 +131,12 @@ typedef enum { DRM_MODE_SUBPIXEL_NONE = 6 } drmModeSubPixel; -typedef struct _drmModeOutput { - unsigned int output_id; +typedef struct _drmModeConnector { + unsigned int connector_id; unsigned int crtc; /**< Crtc currently connected to */ - unsigned int output_type; - unsigned int output_type_id; + unsigned int connector_type; + unsigned int connector_type_id; drmModeConnection connection; uint32_t mmWidth, mmHeight; /**< HxW in millimeters */ drmModeSubPixel subpixel; @@ -156,7 +156,7 @@ typedef struct _drmModeOutput { int count_encoders; uint32_t *encoders; /**< List of encoder ids */ -} drmModeOutput, *drmModeOutputPtr; +} drmModeConnector, *drmModeConnectorPtr; @@ -164,7 +164,7 @@ extern void drmModeFreeModeInfo( struct drm_mode_modeinfo *ptr ); extern void drmModeFreeResources( drmModeResPtr ptr ); extern void drmModeFreeFB( drmModeFBPtr ptr ); extern void drmModeFreeCrtc( drmModeCrtcPtr ptr ); -extern void drmModeFreeOutput( drmModeOutputPtr ptr ); +extern void drmModeFreeConnector( drmModeConnectorPtr ptr ); extern void drmModeFreeEncoder( drmModeEncoderPtr ptr ); /** @@ -217,7 +217,7 @@ extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId); * Set the mode on a crtc crtcId with the given mode modeId. */ int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, - uint32_t x, uint32_t y, uint32_t *outputs, int count, + uint32_t x, uint32_t y, uint32_t *connectors, int count, struct drm_mode_modeinfo *mode); /* @@ -240,31 +240,31 @@ int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y); drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id); /* - * Output manipulation + * Connector manipulation */ /** - * Retrive information about the output outputId. + * Retrive information about the connector connectorId. */ -extern drmModeOutputPtr drmModeGetOutput(int fd, - uint32_t outputId); +extern drmModeConnectorPtr drmModeGetConnector(int fd, + uint32_t connectorId); /** - * Attaches the given mode to an output. + * Attaches the given mode to an connector. */ -extern int drmModeAttachMode(int fd, uint32_t outputId, struct drm_mode_modeinfo *mode_info); +extern int drmModeAttachMode(int fd, uint32_t connectorId, struct drm_mode_modeinfo *mode_info); /** - * Detaches a mode from the output + * Detaches a mode from the connector * must be unused, by the given mode. */ -extern int drmModeDetachMode(int fd, uint32_t outputId, struct drm_mode_modeinfo *mode_info); +extern int drmModeDetachMode(int fd, uint32_t connectorId, struct drm_mode_modeinfo *mode_info); extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId); extern void drmModeFreeProperty(drmModePropertyPtr ptr); extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id); extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr); -extern int drmModeOutputSetProperty(int fd, uint32_t output_id, uint32_t property_id, +extern int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id, uint64_t value); extern int drmCheckModesettingSupported(const char *busid); -- cgit v1.2.3 From 5d47185eb69d73dd7e6ee3ddde4d0c7642c2d5b7 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 30 May 2008 15:32:58 +1000 Subject: drm: switch possible crtc/clones over to encoders --- libdrm/xf86drmMode.c | 8 -------- libdrm/xf86drmMode.h | 6 ------ 2 files changed, 14 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index a18c4290..8b7f2bcf 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -381,10 +381,6 @@ drmModeConnectorPtr drmModeGetConnector(int fd, uint32_t connector_id) conn.connector = connector_id; conn.connector_type_id = 0; conn.connector_type = 0; - conn.count_crtcs = 0; - conn.crtcs = 0; - conn.count_clones = 0; - conn.clones = 0; conn.count_modes = 0; conn.modes_ptr = 0; conn.count_props = 0; @@ -420,12 +416,8 @@ drmModeConnectorPtr drmModeGetConnector(int fd, uint32_t connector_id) r->mmWidth = conn.mm_width; r->mmHeight = conn.mm_height; r->subpixel = conn.subpixel; - r->count_crtcs = conn.count_crtcs; - r->count_clones = conn.count_clones; r->count_modes = conn.count_modes; /* TODO we should test if these alloc & cpy fails. */ - r->crtcs = conn.crtcs; - r->clones = conn.clones; r->count_props = conn.count_props; r->props = drmAllocCpy(U642VOID(conn.props_ptr), conn.count_props, sizeof(uint32_t)); r->prop_values = drmAllocCpy(U642VOID(conn.prop_values_ptr), conn.count_props, sizeof(uint64_t)); diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 03268b10..ceaa9abc 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -141,12 +141,6 @@ typedef struct _drmModeConnector { uint32_t mmWidth, mmHeight; /**< HxW in millimeters */ drmModeSubPixel subpixel; - int count_crtcs; - uint32_t crtcs; /**< Possible crtc to connect to */ - - int count_clones; - uint32_t clones; /**< Mask of clones */ - int count_modes; struct drm_mode_modeinfo *modes; -- cgit v1.2.3 From dba95ec34315d62934ff0e493e085aa6a03cde7c Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 2 Jun 2008 10:41:12 +1000 Subject: drm: fixup some interfaces so test code works again --- libdrm/xf86drmMode.c | 14 +++----------- libdrm/xf86drmMode.h | 3 ++- 2 files changed, 5 insertions(+), 12 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 8b7f2bcf..d11fc12e 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -254,10 +254,6 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId) struct drm_mode_crtc crtc; drmModeCrtcPtr r; - crtc.count_connectors = 0; - crtc.connectors = 0; - crtc.count_possibles = 0; - crtc.possibles = 0; crtc.crtc_id = crtcId; if (ioctl(fd, DRM_IOCTL_MODE_GETCRTC, &crtc)) @@ -278,12 +274,6 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId) memcpy(&r->mode, &crtc.mode, sizeof(struct drm_mode_modeinfo)); r->buffer_id = crtc.fb_id; r->gamma_size = crtc.gamma_size; - r->count_connectors = crtc.count_connectors; - r->count_possibles = crtc.count_possibles; - /* TODO we realy should test if these alloc & cpy fails. */ - r->connectors = crtc.connectors; - r->possibles = crtc.possibles; - return r; } @@ -362,6 +352,8 @@ drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id) if (!(r = drmMalloc(sizeof(*r)))) return 0; + r->encoder_id = enc.encoder_id; + r->crtc = enc.crtc; r->encoder_type = enc.encoder_type; r->crtcs = enc.crtcs; r->clones = enc.clones; @@ -411,7 +403,7 @@ drmModeConnectorPtr drmModeGetConnector(int fd, uint32_t connector_id) } r->connector_id = conn.connector; - r->crtc = conn.crtc; + r->encoder = conn.encoder; r->connection = conn.connection; r->mmWidth = conn.mm_width; r->mmHeight = conn.mm_height; diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index ceaa9abc..2f3a8f74 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -112,6 +112,7 @@ typedef struct _drmModeCrtc { typedef struct _drmModeEncoder { unsigned int encoder_id; unsigned int encoder_type; + uint32_t crtc; uint32_t crtcs; uint32_t clones; } drmModeEncoder, *drmModeEncoderPtr; @@ -134,7 +135,7 @@ typedef enum { typedef struct _drmModeConnector { unsigned int connector_id; - unsigned int crtc; /**< Crtc currently connected to */ + unsigned int encoder; /**< Crtc currently connected to */ unsigned int connector_type; unsigned int connector_type_id; drmModeConnection connection; -- cgit v1.2.3 From 4e7b24639808e5e1e2c05143028db1a3bc2812e9 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 2 Jun 2008 14:04:41 +1000 Subject: drm: add functions to get/set gamma ramps --- libdrm/xf86drmMode.c | 36 ++++++++++++++++++++++++++++++++++++ libdrm/xf86drmMode.h | 5 +++++ 2 files changed, 41 insertions(+) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index d11fc12e..a393f965 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -657,3 +657,39 @@ int drmModeReplaceFB(int fd, uint32_t buffer_id, return 0; } + +int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size, + uint16_t *red, uint16_t *green, uint16_t *blue) +{ + int ret; + struct drm_mode_crtc_lut l; + + l.crtc_id = crtc_id; + l.gamma_size = size; + l.red = VOID2U64(red); + l.green = VOID2U64(green); + l.blue = VOID2U64(blue); + + if ((ret = ioctl(fd, DRM_IOCTL_MODE_GETGAMMA, &l))) + return ret; + + return 0; +} + +int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size, + uint16_t *red, uint16_t *green, uint16_t *blue) +{ + int ret; + struct drm_mode_crtc_lut l; + + l.crtc_id = crtc_id; + l.gamma_size = size; + l.red = VOID2U64(red); + l.green = VOID2U64(green); + l.blue = VOID2U64(blue); + + if ((ret = ioctl(fd, DRM_IOCTL_MODE_SETGAMMA, &l))) + return ret; + + return 0; +} diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 2f3a8f74..56908d8f 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -263,3 +263,8 @@ extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr); extern int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id, uint64_t value); extern int drmCheckModesettingSupported(const char *busid); + +extern int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size, + uint16_t *red, uint16_t *green, uint16_t *blue); +extern int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size, + uint16_t *red, uint16_t *green, uint16_t *blue); -- cgit v1.2.3 From 382aa3ceeb79165a9bdddc8f944de131c8cbf2dd Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 4 Jun 2008 13:49:43 +1000 Subject: drm: introduce generation counter to interface. Idea being if you want to add new crtc/output/encoder dynamically later, you just increase the generation counter and userspace should re-read all the resources --- libdrm/xf86drmMode.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 56908d8f..3bd30a92 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -51,9 +51,16 @@ * buffer object interface. This object needs to be pinned. */ +/* + * generation - these are to be read by userspace, and if it notices + * while calling a get output or get crtc that the generation has changed + * it should re-call the mode resource functions resync its view of the + * outputs with current view. + */ typedef struct _drmModeRes { + uint32_t generation; int count_fbs; uint32_t *fbs; @@ -93,6 +100,7 @@ typedef struct _drmModeProperty { typedef struct _drmModeCrtc { unsigned int crtc_id; unsigned int buffer_id; /**< FB id to connect to 0 = disconnect*/ + uint32_t generation; uint32_t x, y; /**< Position on the frameuffer */ uint32_t width, height; @@ -110,6 +118,7 @@ typedef struct _drmModeCrtc { } drmModeCrtc, *drmModeCrtcPtr; typedef struct _drmModeEncoder { + uint32_t generation; unsigned int encoder_id; unsigned int encoder_type; uint32_t crtc; @@ -133,8 +142,8 @@ typedef enum { } drmModeSubPixel; typedef struct _drmModeConnector { + uint32_t generation; unsigned int connector_id; - unsigned int encoder; /**< Crtc currently connected to */ unsigned int connector_type; unsigned int connector_type_id; -- cgit v1.2.3 From 9390bdab7cce67ad0eb8103da8782aec7bfad017 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 4 Jun 2008 13:53:33 +1000 Subject: libdrm: shouldn't rely on this --- libdrm/xf86drmMode.h | 1 - 1 file changed, 1 deletion(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 3bd30a92..f1b7c86e 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -32,7 +32,6 @@ */ #include -#include "xf86mm.h" /* * This is the interface for modesetting for drm. -- cgit v1.2.3 From f9dad8cc22994e0e4671d14b3ee721e4b5777a68 Mon Sep 17 00:00:00 2001 From: Maarten Maathuis Date: Mon, 23 Jun 2008 21:15:54 +0200 Subject: libdrm: check for allocation failure --- libdrm/xf86drmMode.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index a393f965..df865415 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -419,6 +419,9 @@ drmModeConnectorPtr drmModeGetConnector(int fd, uint32_t connector_id) r->connector_type = conn.connector_type; r->connector_type_id = conn.connector_type_id; + if (!r->props || !r->prop_values || !r->modes || !r->encoders) + goto err_allocs; + err_allocs: drmFree(U642VOID(conn.prop_values_ptr)); drmFree(U642VOID(conn.props_ptr)); -- cgit v1.2.3 From 9f28da80f6cc8e45670b217a2483983f2838095d Mon Sep 17 00:00:00 2001 From: Maarten Maathuis Date: Fri, 27 Jun 2008 18:45:08 +0200 Subject: Change some obviously wrong things about property blobs, still broken though. - I do not fully understand these blobs, so i'm leaving it at this for the moment. --- libdrm/xf86drmMode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index df865415..ca21a961 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -495,7 +495,7 @@ drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id) if (prop.flags & DRM_MODE_PROP_ENUM) { r->count_enums = prop.count_enum_blobs; r->enums = drmAllocCpy(U642VOID(prop.enum_blob_ptr), prop.count_enum_blobs, sizeof(struct drm_mode_property_enum)); - } else if (prop.flags & DRM_MODE_PROP_ENUM) { + } else if (prop.flags & DRM_MODE_PROP_BLOB) { r->values = drmAllocCpy(U642VOID(prop.values_ptr), prop.count_enum_blobs, sizeof(uint32_t)); r->blob_ids = drmAllocCpy(U642VOID(prop.enum_blob_ptr), prop.count_enum_blobs, sizeof(uint32_t)); r->count_blobs = prop.count_enum_blobs; -- cgit v1.2.3 From 5de978905abd6d44ee2ecdc7393194a4950c595c Mon Sep 17 00:00:00 2001 From: Maarten Maathuis Date: Thu, 3 Jul 2008 00:25:06 +0200 Subject: [libdrm] count connectors and such has no place in a crtc object --- libdrm/xf86drmMode.h | 6 ------ 1 file changed, 6 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index f1b7c86e..9f1e7a26 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -106,12 +106,6 @@ typedef struct _drmModeCrtc { int mode_valid; struct drm_mode_modeinfo mode; - int count_connectors; - uint32_t connectors; /**< Connectors that are connected */ - - int count_possibles; - uint32_t possibles; /**< Connectors that can be connected */ - int gamma_size; /**< Number of gamma stops */ } drmModeCrtc, *drmModeCrtcPtr; -- cgit v1.2.3 From 11b7a81c8a776aa7761ee03fe55d741a44ba5df7 Mon Sep 17 00:00:00 2001 From: Maarten Maathuis Date: Thu, 3 Jul 2008 17:25:37 +0200 Subject: libdrm: fix typo in comment --- libdrm/xf86drmMode.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 9f1e7a26..7afc71d7 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -98,7 +98,7 @@ typedef struct _drmModeProperty { typedef struct _drmModeCrtc { unsigned int crtc_id; - unsigned int buffer_id; /**< FB id to connect to 0 = disconnect*/ + unsigned int buffer_id; /**< FB id to connect to 0 = disconnect */ uint32_t generation; uint32_t x, y; /**< Position on the frameuffer */ @@ -137,7 +137,7 @@ typedef enum { typedef struct _drmModeConnector { uint32_t generation; unsigned int connector_id; - unsigned int encoder; /**< Crtc currently connected to */ + unsigned int encoder; /**< Encoder currently connected to */ unsigned int connector_type; unsigned int connector_type_id; drmModeConnection connection; -- cgit v1.2.3 From 142a309604b65c26ca95594943ee91dde8688697 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 4 Jul 2008 09:34:24 +1000 Subject: modesetting: rip out all of the generation code. not needed, hotplug will work just as well hopefully. --- libdrm/xf86drmMode.h | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 7afc71d7..3e2f5c0e 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -50,16 +50,8 @@ * buffer object interface. This object needs to be pinned. */ -/* - * generation - these are to be read by userspace, and if it notices - * while calling a get output or get crtc that the generation has changed - * it should re-call the mode resource functions resync its view of the - * outputs with current view. - */ - typedef struct _drmModeRes { - uint32_t generation; int count_fbs; uint32_t *fbs; @@ -99,7 +91,6 @@ typedef struct _drmModeProperty { typedef struct _drmModeCrtc { unsigned int crtc_id; unsigned int buffer_id; /**< FB id to connect to 0 = disconnect */ - uint32_t generation; uint32_t x, y; /**< Position on the frameuffer */ uint32_t width, height; @@ -111,7 +102,6 @@ typedef struct _drmModeCrtc { } drmModeCrtc, *drmModeCrtcPtr; typedef struct _drmModeEncoder { - uint32_t generation; unsigned int encoder_id; unsigned int encoder_type; uint32_t crtc; @@ -135,7 +125,6 @@ typedef enum { } drmModeSubPixel; typedef struct _drmModeConnector { - uint32_t generation; unsigned int connector_id; unsigned int encoder; /**< Encoder currently connected to */ unsigned int connector_type; -- cgit v1.2.3 From 7cbc5f6145046f3775e3b3ca2862bfb71831ec44 Mon Sep 17 00:00:00 2001 From: Maarten Maathuis Date: Sat, 5 Jul 2008 12:04:07 +0200 Subject: modesetting-101: Make the interface variable names a little more consistent + modeprint changes. - All things are now called _id when they are id's. - modeprint now accepts driver name as first argument. --- libdrm/xf86drmMode.c | 21 ++++++++------------- libdrm/xf86drmMode.h | 10 +++++----- 2 files changed, 13 insertions(+), 18 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index ca21a961..c3921ee9 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -284,11 +284,6 @@ int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, { struct drm_mode_crtc crtc; - crtc.count_connectors = 0; - crtc.connectors = 0; - crtc.count_possibles = 0; - crtc.possibles = 0; - crtc.x = x; crtc.y = y; crtc.crtc_id = crtcId; @@ -343,8 +338,8 @@ drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id) enc.encoder_id = encoder_id; enc.encoder_type = 0; - enc.crtcs = 0; - enc.clones = 0; + enc.possible_crtcs = 0; + enc.possible_clones = 0; if (ioctl(fd, DRM_IOCTL_MODE_GETENCODER, &enc)) return 0; @@ -353,10 +348,10 @@ drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id) return 0; r->encoder_id = enc.encoder_id; - r->crtc = enc.crtc; + r->crtc_id = enc.crtc_id; r->encoder_type = enc.encoder_type; - r->crtcs = enc.crtcs; - r->clones = enc.clones; + r->possible_crtcs = enc.possible_crtcs; + r->possible_clones = enc.possible_clones; return r; } @@ -370,7 +365,7 @@ drmModeConnectorPtr drmModeGetConnector(int fd, uint32_t connector_id) struct drm_mode_get_connector conn; drmModeConnectorPtr r = NULL; - conn.connector = connector_id; + conn.connector_id = connector_id; conn.connector_type_id = 0; conn.connector_type = 0; conn.count_modes = 0; @@ -402,8 +397,8 @@ drmModeConnectorPtr drmModeGetConnector(int fd, uint32_t connector_id) goto err_allocs; } - r->connector_id = conn.connector; - r->encoder = conn.encoder; + r->connector_id = conn.connector_id; + r->encoder_id = conn.encoder_id; r->connection = conn.connection; r->mmWidth = conn.mm_width; r->mmHeight = conn.mm_height; diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 3e2f5c0e..59612a94 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -92,7 +92,7 @@ typedef struct _drmModeCrtc { unsigned int crtc_id; unsigned int buffer_id; /**< FB id to connect to 0 = disconnect */ - uint32_t x, y; /**< Position on the frameuffer */ + uint32_t x, y; /**< Position on the framebuffer */ uint32_t width, height; int mode_valid; struct drm_mode_modeinfo mode; @@ -104,9 +104,9 @@ typedef struct _drmModeCrtc { typedef struct _drmModeEncoder { unsigned int encoder_id; unsigned int encoder_type; - uint32_t crtc; - uint32_t crtcs; - uint32_t clones; + unsigned int crtc_id; + uint32_t possible_crtcs; + uint32_t possible_clones; } drmModeEncoder, *drmModeEncoderPtr; typedef enum { @@ -126,7 +126,7 @@ typedef enum { typedef struct _drmModeConnector { unsigned int connector_id; - unsigned int encoder; /**< Encoder currently connected to */ + unsigned int encoder_id; /**< Encoder currently connected to */ unsigned int connector_type; unsigned int connector_type_id; drmModeConnection connection; -- cgit v1.2.3 From d2d7f3069dac4bc5ddd3c8da4d3955f690274276 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 31 Jul 2008 13:13:21 +1000 Subject: drm: userspace rip out TTM API --- libdrm/intel/intel_bufmgr_fake.c | 2 +- libdrm/xf86drm.c | 530 --------------------------------------- 2 files changed, 1 insertion(+), 531 deletions(-) (limited to 'libdrm') diff --git a/libdrm/intel/intel_bufmgr_fake.c b/libdrm/intel/intel_bufmgr_fake.c index e988eb58..e7ed893f 100644 --- a/libdrm/intel/intel_bufmgr_fake.c +++ b/libdrm/intel/intel_bufmgr_fake.c @@ -649,7 +649,7 @@ intel_bo_fake_alloc_static(dri_bufmgr *bufmgr, const char *name, bo_fake->refcount = 1; bo_fake->id = ++bufmgr_fake->buf_nr; bo_fake->name = name; - bo_fake->flags = BM_PINNED | DRM_BO_FLAG_NO_MOVE; + bo_fake->flags = BM_PINNED; bo_fake->is_static = 1; DBG("drm_bo_alloc_static: (buf %d: %s, %d kb)\n", bo_fake->id, bo_fake->name, diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index 4b4d009b..1fd3a697 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -2357,165 +2357,6 @@ int drmCommandWriteRead(int fd, unsigned long drmCommandIndex, void *data, } -/* - * Valid flags are - * DRM_FENCE_FLAG_EMIT - * DRM_FENCE_FLAG_SHAREABLE - * DRM_FENCE_MASK_DRIVER - */ - -int drmFenceCreate(int fd, unsigned flags, int fence_class, unsigned type, - drmFence *fence) -{ - drm_fence_arg_t arg; - - memset(&arg, 0, sizeof(arg)); - arg.flags = flags; - arg.type = type; - arg.fence_class = fence_class; - - if (drmIoctl(fd, DRM_IOCTL_FENCE_CREATE, &arg)) - return -errno; - fence->handle = arg.handle; - fence->fence_class = arg.fence_class; - fence->type = arg.type; - fence->flags = arg.flags; - fence->signaled = 0; - return 0; -} - -/* - * Valid flags are - * DRM_FENCE_FLAG_SHAREABLE - * DRM_FENCE_MASK_DRIVER - */ - -int drmFenceBuffers(int fd, unsigned flags, uint32_t fence_class, drmFence *fence) -{ - drm_fence_arg_t arg; - - memset(&arg, 0, sizeof(arg)); - arg.flags = flags; - arg.fence_class = fence_class; - - if (drmIoctl(fd, DRM_IOCTL_FENCE_BUFFERS, &arg)) - return -errno; - fence->handle = arg.handle; - fence->fence_class = arg.fence_class; - fence->type = arg.type; - fence->flags = arg.flags; - fence->sequence = arg.sequence; - fence->signaled = 0; - return 0; -} - -int drmFenceReference(int fd, unsigned handle, drmFence *fence) -{ - drm_fence_arg_t arg; - - memset(&arg, 0, sizeof(arg)); - arg.handle = handle; - - if (drmIoctl(fd, DRM_IOCTL_FENCE_REFERENCE, &arg)) - return -errno; - fence->handle = arg.handle; - fence->fence_class = arg.fence_class; - fence->type = arg.type; - fence->flags = arg.flags; - fence->signaled = arg.signaled; - return 0; -} - -int drmFenceUnreference(int fd, const drmFence *fence) -{ - drm_fence_arg_t arg; - - memset(&arg, 0, sizeof(arg)); - arg.handle = fence->handle; - - if (drmIoctl(fd, DRM_IOCTL_FENCE_UNREFERENCE, &arg)) - return -errno; - return 0; -} - -int drmFenceFlush(int fd, drmFence *fence, unsigned flush_type) -{ - drm_fence_arg_t arg; - - memset(&arg, 0, sizeof(arg)); - arg.handle = fence->handle; - arg.type = flush_type; - - if (drmIoctl(fd, DRM_IOCTL_FENCE_FLUSH, &arg)) - return -errno; - fence->fence_class = arg.fence_class; - fence->type = arg.type; - fence->signaled = arg.signaled; - return arg.error; -} - -int drmFenceUpdate(int fd, drmFence *fence) -{ - drm_fence_arg_t arg; - - memset(&arg, 0, sizeof(arg)); - arg.handle = fence->handle; - - if (drmIoctl(fd, DRM_IOCTL_FENCE_SIGNALED, &arg)) - return -errno; - fence->fence_class = arg.fence_class; - fence->type = arg.type; - fence->signaled = arg.signaled; - return 0; -} - -int drmFenceSignaled(int fd, drmFence *fence, unsigned fenceType, - int *signaled) -{ - if ((fence->flags & DRM_FENCE_FLAG_SHAREABLE) || - ((fenceType & fence->signaled) != fenceType)) { - int ret = drmFenceFlush(fd, fence, fenceType); - if (ret) - return ret; - } - - *signaled = ((fenceType & fence->signaled) == fenceType); - - return 0; -} - -/* - * Valid flags are - * DRM_FENCE_FLAG_SHAREABLE - * DRM_FENCE_MASK_DRIVER - */ - - -int drmFenceEmit(int fd, unsigned flags, drmFence *fence, unsigned emit_type) -{ - drm_fence_arg_t arg; - - memset(&arg, 0, sizeof(arg)); - arg.fence_class = fence->fence_class; - arg.flags = flags; - arg.handle = fence->handle; - arg.type = emit_type; - - if (drmIoctl(fd, DRM_IOCTL_FENCE_EMIT, &arg)) - return -errno; - fence->fence_class = arg.fence_class; - fence->type = arg.type; - fence->signaled = arg.signaled; - fence->sequence = arg.sequence; - return 0; -} - -/* - * Valid flags are - * DRM_FENCE_FLAG_WAIT_LAZY - * DRM_FENCE_FLAG_WAIT_IGNORE_SIGNALS - */ - #define DRM_IOCTL_TIMEOUT_USEC 3000000UL static unsigned long @@ -2558,377 +2399,6 @@ drmIoctlTimeout(int fd, unsigned long request, void *argp) - -int drmFenceWait(int fd, unsigned flags, drmFence *fence, unsigned flush_type) -{ - drm_fence_arg_t arg; - int ret; - - if (flush_type == 0) { - flush_type = fence->type; - } - - if (!(fence->flags & DRM_FENCE_FLAG_SHAREABLE)) { - if ((flush_type & fence->signaled) == flush_type) { - return 0; - } - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = fence->handle; - arg.type = flush_type; - arg.flags = flags; - - - ret = drmIoctlTimeout(fd, DRM_IOCTL_FENCE_WAIT, &arg); - if (ret) - return ret; - - fence->fence_class = arg.fence_class; - fence->type = arg.type; - fence->signaled = arg.signaled; - return arg.error; -} - -static void drmBOCopyReply(const struct drm_bo_info_rep *rep, drmBO *buf) -{ - buf->handle = rep->handle; - buf->flags = rep->flags; - buf->size = rep->size; - buf->offset = rep->offset; - buf->mapHandle = rep->arg_handle; - buf->proposedFlags = rep->proposed_flags; - buf->start = rep->buffer_start; - buf->fenceFlags = rep->fence_flags; - buf->replyFlags = rep->rep_flags; - buf->pageAlignment = rep->page_alignment; - buf->tileInfo = rep->tile_info; - buf->hwTileStride = rep->hw_tile_stride; - buf->desiredTileStride = rep->desired_tile_stride; -} - - - -int drmBOCreate(int fd, unsigned long size, - unsigned pageAlignment, void *user_buffer, - uint64_t flags, - unsigned hint, drmBO *buf) -{ - struct drm_bo_create_arg arg; - struct drm_bo_create_req *req = &arg.d.req; - struct drm_bo_info_rep *rep = &arg.d.rep; - int ret; - - memset(buf, 0, sizeof(*buf)); - memset(&arg, 0, sizeof(arg)); - req->flags = flags; - req->hint = hint; - req->size = size; - req->page_alignment = pageAlignment; - req->buffer_start = (unsigned long) user_buffer; - - buf->virtual = NULL; - - ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_CREATE, &arg); - if (ret) - return ret; - - drmBOCopyReply(rep, buf); - buf->virtual = user_buffer; - buf->mapCount = 0; - - return 0; -} - -int drmBOReference(int fd, unsigned handle, drmBO *buf) -{ - struct drm_bo_reference_info_arg arg; - struct drm_bo_handle_arg *req = &arg.d.req; - struct drm_bo_info_rep *rep = &arg.d.rep; - - memset(&arg, 0, sizeof(arg)); - req->handle = handle; - - if (drmIoctl(fd, DRM_IOCTL_BO_REFERENCE, &arg)) - return -errno; - - drmBOCopyReply(rep, buf); - buf->mapVirtual = NULL; - buf->mapCount = 0; - buf->virtual = NULL; - - return 0; -} - -int drmBOUnreference(int fd, drmBO *buf) -{ - struct drm_bo_handle_arg arg; - - if (buf->mapVirtual && buf->mapHandle) { - (void) munmap(buf->mapVirtual, buf->start + buf->size); - buf->mapVirtual = NULL; - buf->virtual = NULL; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = buf->handle; - - if (drmIoctl(fd, DRM_IOCTL_BO_UNREFERENCE, &arg)) - return -errno; - - buf->handle = 0; - return 0; -} - - -/* - * Flags can be DRM_BO_FLAG_READ, DRM_BO_FLAG_WRITE or'ed together - * Hint currently be DRM_BO_HINT_DONT_BLOCK, which makes the - * call return an -EBUSY if it can' immediately honor the mapping request. - */ - -int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint, - void **address) -{ - struct drm_bo_map_wait_idle_arg arg; - struct drm_bo_info_req *req = &arg.d.req; - struct drm_bo_info_rep *rep = &arg.d.rep; - int ret = 0; - - /* - * Make sure we have a virtual address of the buffer. - */ - - if (!buf->virtual) { - drmAddress virtual; - virtual = mmap(0, buf->size + buf->start, - PROT_READ | PROT_WRITE, MAP_SHARED, - fd, buf->mapHandle); - if (virtual == MAP_FAILED) { - ret = -errno; - } - if (ret) - return ret; - buf->mapVirtual = virtual; - buf->virtual = ((char *) virtual) + buf->start; - } - - memset(&arg, 0, sizeof(arg)); - req->handle = buf->handle; - req->mask = mapFlags; - req->hint = mapHint; - - /* - * May hang if the buffer object is busy. - * This IOCTL synchronizes the buffer. - */ - - ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_MAP, &arg); - if (ret) - return ret; - - drmBOCopyReply(rep, buf); - buf->mapFlags = mapFlags; - ++buf->mapCount; - *address = buf->virtual; - - return 0; -} - - -int drmBOUnmap(int fd, drmBO *buf) -{ - struct drm_bo_handle_arg arg; - - memset(&arg, 0, sizeof(arg)); - arg.handle = buf->handle; - - if (drmIoctl(fd, DRM_IOCTL_BO_UNMAP, &arg)) { - return -errno; - } - buf->mapCount--; - return 0; -} - -int drmBOSetStatus(int fd, drmBO *buf, - uint64_t flags, uint64_t mask, - unsigned int hint, - unsigned int desired_tile_stride, - unsigned int tile_info) -{ - - struct drm_bo_map_wait_idle_arg arg; - struct drm_bo_info_req *req = &arg.d.req; - struct drm_bo_info_rep *rep = &arg.d.rep; - int ret = 0; - - memset(&arg, 0, sizeof(arg)); - req->mask = mask; - req->flags = flags; - req->handle = buf->handle; - req->hint = hint; - req->desired_tile_stride = desired_tile_stride; - req->tile_info = tile_info; - - ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_SETSTATUS, &arg); - if (ret) - return ret; - - drmBOCopyReply(rep, buf); - return 0; -} - - -int drmBOInfo(int fd, drmBO *buf) -{ - struct drm_bo_reference_info_arg arg; - struct drm_bo_handle_arg *req = &arg.d.req; - struct drm_bo_info_rep *rep = &arg.d.rep; - int ret = 0; - - memset(&arg, 0, sizeof(arg)); - req->handle = buf->handle; - - ret = drmIoctl(fd, DRM_IOCTL_BO_INFO, &arg); - if (ret) - return -errno; - - drmBOCopyReply(rep, buf); - return 0; -} - -int drmBOWaitIdle(int fd, drmBO *buf, unsigned hint) -{ - struct drm_bo_map_wait_idle_arg arg; - struct drm_bo_info_req *req = &arg.d.req; - struct drm_bo_info_rep *rep = &arg.d.rep; - int ret = 0; - - if ((buf->flags & DRM_BO_FLAG_SHAREABLE) || - (buf->replyFlags & DRM_BO_REP_BUSY)) { - memset(&arg, 0, sizeof(arg)); - req->handle = buf->handle; - req->hint = hint; - - ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_WAIT_IDLE, &arg); - if (ret) - return ret; - - drmBOCopyReply(rep, buf); - } - return 0; -} - -int drmBOBusy(int fd, drmBO *buf, int *busy) -{ - int ret = drmBOInfo(fd, buf); - - if (ret) - return ret; - - *busy = (buf->replyFlags & DRM_BO_REP_BUSY); - return 0; -} - -int drmMMInit(int fd, unsigned long pOffset, unsigned long pSize, - unsigned memType) -{ - struct drm_mm_init_arg arg; - - memset(&arg, 0, sizeof(arg)); - - arg.magic = DRM_BO_INIT_MAGIC; - arg.major = DRM_BO_INIT_MAJOR; - arg.minor = DRM_BO_INIT_MINOR; - arg.p_offset = pOffset; - arg.p_size = pSize; - arg.mem_type = memType; - - if (drmIoctl(fd, DRM_IOCTL_MM_INIT, &arg)) - return -errno; - return 0; -} - -int drmMMTakedown(int fd, unsigned memType) -{ - struct drm_mm_type_arg arg; - - memset(&arg, 0, sizeof(arg)); - arg.mem_type = memType; - - if (drmIoctl(fd, DRM_IOCTL_MM_TAKEDOWN, &arg)) - return -errno; - return 0; -} - -/* - * If this function returns an error, and lockBM was set to 1, - * the buffer manager is NOT locked. - */ - -int drmMMLock(int fd, unsigned memType, int lockBM, int ignoreNoEvict) -{ - struct drm_mm_type_arg arg; - - memset(&arg, 0, sizeof(arg)); - arg.mem_type = memType; - arg.lock_flags |= (lockBM) ? DRM_BO_LOCK_UNLOCK_BM : 0; - arg.lock_flags |= (ignoreNoEvict) ? DRM_BO_LOCK_IGNORE_NO_EVICT : 0; - - return drmIoctlTimeout(fd, DRM_IOCTL_MM_LOCK, &arg); -} - -int drmMMUnlock(int fd, unsigned memType, int unlockBM) -{ - struct drm_mm_type_arg arg; - - memset(&arg, 0, sizeof(arg)); - - arg.mem_type = memType; - arg.lock_flags |= (unlockBM) ? DRM_BO_LOCK_UNLOCK_BM : 0; - - return drmIoctlTimeout(fd, DRM_IOCTL_MM_UNLOCK, &arg); -} - -int drmMMInfo(int fd, unsigned memType, uint64_t *size) -{ - struct drm_mm_info_arg arg; - - memset(&arg, 0, sizeof(arg)); - - arg.mem_type = memType; - - if (drmIoctl(fd, DRM_IOCTL_MM_INFO, &arg)) - return -errno; - - *size = arg.p_size; - return 0; -} - -int drmBOVersion(int fd, unsigned int *major, - unsigned int *minor, - unsigned int *patchlevel) -{ - struct drm_bo_version_arg arg; - int ret; - - memset(&arg, 0, sizeof(arg)); - ret = drmIoctl(fd, DRM_IOCTL_BO_VERSION, &arg); - if (ret) - return -errno; - - if (major) - *major = arg.major; - if (minor) - *minor = arg.minor; - if (patchlevel) - *patchlevel = arg.patchlevel; - - return 0; -} - - - #define DRM_MAX_FDS 16 static struct { char *BusID; -- cgit v1.2.3 From e9648e9107e90c3ef38a9c9ebb95bac1297d0df5 Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Tue, 12 Aug 2008 18:22:34 -0700 Subject: Export a generic dri_bo handle for use by clients We'll need something like this (either a handle field or a dri_bo_get_handle function) for kernel mode setting to get at the handles. --- libdrm/dri_bufmgr.h | 4 ++++ libdrm/intel/intel_bufmgr_gem.c | 1 + 2 files changed, 5 insertions(+) (limited to 'libdrm') diff --git a/libdrm/dri_bufmgr.h b/libdrm/dri_bufmgr.h index a5ae6c0f..7a7dd6e9 100644 --- a/libdrm/dri_bufmgr.h +++ b/libdrm/dri_bufmgr.h @@ -58,6 +58,10 @@ struct _dri_bo { void *virtual; /** Buffer manager context associated with this buffer object */ dri_bufmgr *bufmgr; + /** + * MM-specific handle for accessing object + */ + int handle; }; /** diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c index 22f8695d..02b1b252 100644 --- a/libdrm/intel/intel_bufmgr_gem.c +++ b/libdrm/intel/intel_bufmgr_gem.c @@ -311,6 +311,7 @@ dri_gem_bo_alloc(dri_bufmgr *bufmgr, const char *name, ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_CREATE, &create); bo_gem->gem_handle = create.handle; + bo_gem->bo.handle = bo_gem->gem_handle; if (ret != 0) { free(bo_gem); return NULL; -- cgit v1.2.3 From af2323b4b3b76070fb453531147a8956161b3718 Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Tue, 30 Sep 2008 16:35:26 -0700 Subject: intel bufmgr: reinstate buffer handle tracking We need a way of getting at the underlying handle for use with mode setting. We can either export it in the dri_bo object or provide a new callback to get it. --- libdrm/intel/intel_bufmgr.h | 4 ++++ libdrm/intel/intel_bufmgr_gem.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'libdrm') diff --git a/libdrm/intel/intel_bufmgr.h b/libdrm/intel/intel_bufmgr.h index c44d596b..67dba6a1 100644 --- a/libdrm/intel/intel_bufmgr.h +++ b/libdrm/intel/intel_bufmgr.h @@ -59,6 +59,10 @@ struct _dri_bo { /** Buffer manager context associated with this buffer object */ dri_bufmgr *bufmgr; + /** + * MM-specific handle for accessing object + */ + int handle; }; dri_bo *dri_bo_alloc(dri_bufmgr *bufmgr, const char *name, unsigned long size, diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c index 4ca49d0a..70cdca74 100644 --- a/libdrm/intel/intel_bufmgr_gem.c +++ b/libdrm/intel/intel_bufmgr_gem.c @@ -316,7 +316,7 @@ dri_gem_bo_alloc(dri_bufmgr *bufmgr, const char *name, ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_CREATE, &create); bo_gem->gem_handle = create.handle; - //bo_gem->bo.handle = bo_gem->gem_handle; + bo_gem->bo.handle = bo_gem->gem_handle; if (ret != 0) { free(bo_gem); return NULL; -- cgit v1.2.3 From 6df7b0719fe92b718e486c2b87e2f883cfa41efa Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 12 Jun 2008 23:22:26 -0700 Subject: intel: Protect bufmgr objects with a pthread mutex. We want to be able to use the bufmgr from multiple threads for GL, and thus we need to protect the internal structures. The pthread-stubs package is used so that programs not linked against pthreads get weak symbols to stubs and don't eat most of the cost. --- libdrm/Makefile.am | 4 +- libdrm/intel/Makefile.am | 1 + libdrm/intel/intel_bufmgr_fake.c | 112 +++++++++++++++++++++++++++++++++------ libdrm/intel/intel_bufmgr_gem.c | 65 ++++++++++++++++++----- 4 files changed, 151 insertions(+), 31 deletions(-) (limited to 'libdrm') diff --git a/libdrm/Makefile.am b/libdrm/Makefile.am index 532ca138..8e1c0ee4 100644 --- a/libdrm/Makefile.am +++ b/libdrm/Makefile.am @@ -26,8 +26,8 @@ libdrm_la_LDFLAGS = -version-number 2:3:0 -no-undefined AM_CFLAGS = -I$(top_srcdir)/shared-core libdrm_la_SOURCES = xf86drm.c xf86drmHash.c xf86drmRandom.c xf86drmSL.c \ - xf86drmMode.c -libdrm_la_LIBADD = intel/libdrm_intel.la + xf86drmMode.c libdrm_lists.h +libdrm_la_LIBADD = intel/libdrm_intel.la @PTHREADSTUBS_LIBS@ libdrmincludedir = ${includedir} libdrminclude_HEADERS = xf86drm.h xf86drmMode.h diff --git a/libdrm/intel/Makefile.am b/libdrm/intel/Makefile.am index 607c4765..92388c24 100644 --- a/libdrm/intel/Makefile.am +++ b/libdrm/intel/Makefile.am @@ -26,6 +26,7 @@ AM_CFLAGS = \ $(WARN_CFLAGS) \ -I$(top_srcdir)/libdrm \ -I$(top_srcdir)/libdrm/intel \ + $(PTHREADSTUBS_CFLAGS) \ -I$(top_srcdir)/shared-core libdrm_intel_la_LTLIBRARIES = libdrm_intel.la diff --git a/libdrm/intel/intel_bufmgr_fake.c b/libdrm/intel/intel_bufmgr_fake.c index c88e1cb0..4c281467 100644 --- a/libdrm/intel/intel_bufmgr_fake.c +++ b/libdrm/intel/intel_bufmgr_fake.c @@ -43,6 +43,7 @@ #include #include #include +#include #include "intel_bufmgr.h" #include "intel_bufmgr_priv.h" #include "drm.h" @@ -112,6 +113,8 @@ struct block { typedef struct _bufmgr_fake { dri_bufmgr bufmgr; + pthread_mutex_t lock; + unsigned long low_offset; unsigned long size; void *virtual; @@ -716,10 +719,16 @@ dri_fake_bo_wait_rendering(dri_bo *bo) dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bo->bufmgr; dri_bo_fake *bo_fake = (dri_bo_fake *)bo; - if (bo_fake->block == NULL || !bo_fake->block->fenced) + pthread_mutex_lock(&bufmgr_fake->lock); + + if (bo_fake->block == NULL || !bo_fake->block->fenced) { + pthread_mutex_unlock(&bufmgr_fake->lock); return; + } _fence_wait_internal(bufmgr_fake, bo_fake->block->fence); + + pthread_mutex_unlock(&bufmgr_fake->lock); } /* Specifically ignore texture memory sharing. @@ -732,6 +741,8 @@ intel_bufmgr_fake_contended_lock_take(dri_bufmgr *bufmgr) dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bufmgr; struct block *block, *tmp; + pthread_mutex_lock(&bufmgr_fake->lock); + bufmgr_fake->need_fence = 1; bufmgr_fake->fail = 0; @@ -751,6 +762,8 @@ intel_bufmgr_fake_contended_lock_take(dri_bufmgr *bufmgr) assert(_fence_test(bufmgr_fake, block->fence)); set_dirty(block->bo); } + + pthread_mutex_unlock(&bufmgr_fake->lock); } static dri_bo * @@ -825,21 +838,29 @@ intel_bo_fake_alloc_static(dri_bufmgr *bufmgr, const char *name, static void dri_fake_bo_reference(dri_bo *bo) { + dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bo->bufmgr; dri_bo_fake *bo_fake = (dri_bo_fake *)bo; + pthread_mutex_lock(&bufmgr_fake->lock); bo_fake->refcount++; + pthread_mutex_unlock(&bufmgr_fake->lock); } static void -dri_fake_bo_unreference(dri_bo *bo) +dri_fake_bo_reference_locked(dri_bo *bo) +{ + dri_bo_fake *bo_fake = (dri_bo_fake *)bo; + + bo_fake->refcount++; +} + +static void +dri_fake_bo_unreference_locked(dri_bo *bo) { dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bo->bufmgr; dri_bo_fake *bo_fake = (dri_bo_fake *)bo; int i; - if (!bo) - return; - if (--bo_fake->refcount == 0) { assert(bo_fake->map_count == 0); /* No remaining references, so free it */ @@ -848,17 +869,25 @@ dri_fake_bo_unreference(dri_bo *bo) free_backing_store(bo); for (i = 0; i < bo_fake->nr_relocs; i++) - dri_bo_unreference(bo_fake->relocs[i].target_buf); + dri_fake_bo_unreference_locked(bo_fake->relocs[i].target_buf); DBG("drm_bo_unreference: free buf %d %s\n", bo_fake->id, bo_fake->name); free(bo_fake->relocs); free(bo); - - return; } } +static void +dri_fake_bo_unreference(dri_bo *bo) +{ + dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bo->bufmgr; + + pthread_mutex_lock(&bufmgr_fake->lock); + dri_fake_bo_unreference_locked(bo); + pthread_mutex_unlock(&bufmgr_fake->lock); +} + /** * Set the buffer as not requiring backing store, and instead get the callback * invoked whenever it would be set dirty. @@ -871,6 +900,8 @@ void intel_bo_fake_disable_backing_store(dri_bo *bo, dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bo->bufmgr; dri_bo_fake *bo_fake = (dri_bo_fake *)bo; + pthread_mutex_lock(&bufmgr_fake->lock); + if (bo_fake->backing_store) free_backing_store(bo); @@ -887,6 +918,8 @@ void intel_bo_fake_disable_backing_store(dri_bo *bo, */ if (invalidate_cb != NULL) invalidate_cb(bo, ptr); + + pthread_mutex_unlock(&bufmgr_fake->lock); } /** @@ -894,7 +927,7 @@ void intel_bo_fake_disable_backing_store(dri_bo *bo, * BM_NO_BACKING_STORE or BM_PINNED) or backing store, as necessary. */ static int -dri_fake_bo_map(dri_bo *bo, int write_enable) +dri_fake_bo_map_locked(dri_bo *bo, int write_enable) { dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bo->bufmgr; dri_bo_fake *bo_fake = (dri_bo_fake *)bo; @@ -952,7 +985,20 @@ dri_fake_bo_map(dri_bo *bo, int write_enable) } static int -dri_fake_bo_unmap(dri_bo *bo) +dri_fake_bo_map(dri_bo *bo, int write_enable) +{ + dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bo->bufmgr; + int ret; + + pthread_mutex_lock(&bufmgr_fake->lock); + ret = dri_fake_bo_map_locked(bo, write_enable); + pthread_mutex_unlock(&bufmgr_fake->lock); + + return ret; +} + +static int +dri_fake_bo_unmap_locked(dri_bo *bo) { dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bo->bufmgr; dri_bo_fake *bo_fake = (dri_bo_fake *)bo; @@ -973,11 +1019,26 @@ dri_fake_bo_unmap(dri_bo *bo) return 0; } +static int +dri_fake_bo_unmap(dri_bo *bo) +{ + dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bo->bufmgr; + int ret; + + pthread_mutex_lock(&bufmgr_fake->lock); + ret = dri_fake_bo_unmap_locked(bo); + pthread_mutex_unlock(&bufmgr_fake->lock); + + return ret; +} + static void dri_fake_kick_all(dri_bufmgr_fake *bufmgr_fake) { struct block *block, *tmp; + pthread_mutex_lock(&bufmgr_fake->lock); + bufmgr_fake->performed_rendering = 0; /* okay for ever BO that is on the HW kick it off. seriously not afraid of the POLICE right now */ @@ -991,6 +1052,8 @@ dri_fake_kick_all(dri_bufmgr_fake *bufmgr_fake) if (!(bo_fake->flags & BM_NO_BACKING_STORE)) bo_fake->dirty = 1; } + + pthread_mutex_unlock(&bufmgr_fake->lock); } static int @@ -999,9 +1062,6 @@ dri_fake_bo_validate(dri_bo *bo) dri_bufmgr_fake *bufmgr_fake; dri_bo_fake *bo_fake = (dri_bo_fake *)bo; - /* XXX: Sanity-check whether we've already validated this one under - * different flags. See drmAddValidateItem(). - */ bufmgr_fake = (dri_bufmgr_fake *)bo->bufmgr; DBG("drm_bo_validate: (buf %d: %s, %d kb)\n", bo_fake->id, bo_fake->name, @@ -1084,6 +1144,7 @@ dri_fake_destroy(dri_bufmgr *bufmgr) { dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bufmgr; + pthread_mutex_destroy(&bufmgr_fake->lock); mmDestroy(bufmgr_fake->heap); free(bufmgr); } @@ -1099,6 +1160,8 @@ dri_fake_emit_reloc(dri_bo *reloc_buf, dri_bo_fake *target_fake = (dri_bo_fake *)target_buf; int i; + pthread_mutex_lock(&bufmgr_fake->lock); + assert(reloc_buf); assert(target_buf); @@ -1111,7 +1174,7 @@ dri_fake_emit_reloc(dri_bo *reloc_buf, assert(reloc_fake->nr_relocs <= MAX_RELOCS); - dri_bo_reference(target_buf); + dri_fake_bo_reference_locked(target_buf); if (!target_fake->is_static) reloc_fake->child_size += ALIGN(target_buf->size, target_fake->alignment); @@ -1132,6 +1195,8 @@ dri_fake_emit_reloc(dri_bo *reloc_buf, } } + pthread_mutex_unlock(&bufmgr_fake->lock); + return 0; } @@ -1178,7 +1243,7 @@ dri_fake_reloc_and_validate_buffer(dri_bo *bo) ret = dri_fake_reloc_and_validate_buffer(r->target_buf); if (ret != 0) { if (bo->virtual != NULL) - dri_bo_unmap(bo); + dri_fake_bo_unmap_locked(bo); return ret; } } @@ -1188,7 +1253,7 @@ dri_fake_reloc_and_validate_buffer(dri_bo *bo) reloc_data = r->target_buf->offset + r->delta; if (bo->virtual == NULL) - dri_bo_map(bo, 1); + dri_fake_bo_map_locked(bo, 1); *(uint32_t *)((uint8_t *)bo->virtual + r->offset) = reloc_data; @@ -1197,7 +1262,7 @@ dri_fake_reloc_and_validate_buffer(dri_bo *bo) } if (bo->virtual != NULL) - dri_bo_unmap(bo); + dri_fake_bo_unmap_locked(bo); if (bo_fake->write_domain != 0) { if (!(bo_fake->flags & (BM_NO_BACKING_STORE|BM_PINNED))) { @@ -1261,6 +1326,8 @@ dri_fake_bo_exec(dri_bo *bo, int used, int ret; int retry_count = 0; + pthread_mutex_lock(&bufmgr_fake->lock); + bufmgr_fake->performed_rendering = 0; dri_fake_calculate_domains(bo); @@ -1305,6 +1372,8 @@ dri_fake_bo_exec(dri_bo *bo, int used, dri_bo_fake_post_submit(bo); + pthread_mutex_unlock(&bufmgr_fake->lock); + return 0; } @@ -1357,6 +1426,8 @@ intel_bufmgr_fake_evict_all(dri_bufmgr *bufmgr) dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bufmgr; struct block *block, *tmp; + pthread_mutex_lock(&bufmgr_fake->lock); + bufmgr_fake->need_fence = 1; bufmgr_fake->fail = 0; @@ -1376,6 +1447,8 @@ intel_bufmgr_fake_evict_all(dri_bufmgr *bufmgr) /* Releases the memory, and memcpys dirty contents out if necessary. */ free_block(bufmgr_fake, block); } + + pthread_mutex_unlock(&bufmgr_fake->lock); } void intel_bufmgr_fake_set_last_dispatch(dri_bufmgr *bufmgr, volatile unsigned int *last_dispatch) @@ -1395,6 +1468,11 @@ intel_bufmgr_fake_init(int fd, bufmgr_fake = calloc(1, sizeof(*bufmgr_fake)); + if (pthread_mutex_init(&bufmgr_fake->lock, NULL) != 0) { + free(bufmgr_fake); + return NULL; + } + /* Initialize allocator */ DRMINITLISTHEAD(&bufmgr_fake->fenced); DRMINITLISTHEAD(&bufmgr_fake->on_hardware); diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c index 70cdca74..af58ad8f 100644 --- a/libdrm/intel/intel_bufmgr_gem.c +++ b/libdrm/intel/intel_bufmgr_gem.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -84,6 +85,8 @@ typedef struct _dri_bufmgr_gem { int max_relocs; + pthread_mutex_t lock; + struct drm_i915_gem_exec_object *exec_objects; dri_bo **exec_bos; int exec_size; @@ -133,6 +136,8 @@ struct _dri_bo_gem { dri_bo_gem *next; }; +static void dri_gem_bo_reference_locked(dri_bo *bo); + static int logbase2(int n) { @@ -237,7 +242,7 @@ intel_add_validate_buffer(dri_bo *bo) bufmgr_gem->exec_objects[index].alignment = 0; bufmgr_gem->exec_objects[index].offset = 0; bufmgr_gem->exec_bos[index] = bo; - dri_bo_reference(bo); + dri_gem_bo_reference_locked(bo); bufmgr_gem->exec_count++; } @@ -285,6 +290,7 @@ dri_gem_bo_alloc(dri_bufmgr *bufmgr, const char *name, bo_size = page_size; } + pthread_mutex_lock(&bufmgr_gem->lock); /* Get a buffer out of the cache if available */ if (bucket != NULL && bucket->num_entries > 0) { struct drm_i915_gem_busy busy; @@ -302,6 +308,7 @@ dri_gem_bo_alloc(dri_bufmgr *bufmgr, const char *name, bucket->num_entries--; } } + pthread_mutex_unlock(&bufmgr_gem->lock); if (!alloc_from_cache) { struct drm_i915_gem_create create; @@ -379,6 +386,17 @@ intel_bo_gem_create_from_name(dri_bufmgr *bufmgr, const char *name, static void dri_gem_bo_reference(dri_bo *bo) +{ + dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr; + dri_bo_gem *bo_gem = (dri_bo_gem *)bo; + + pthread_mutex_lock(&bufmgr_gem->lock); + bo_gem->refcount++; + pthread_mutex_unlock(&bufmgr_gem->lock); +} + +static void +dri_gem_bo_reference_locked(dri_bo *bo) { dri_bo_gem *bo_gem = (dri_bo_gem *)bo; @@ -408,14 +426,11 @@ dri_gem_bo_free(dri_bo *bo) } static void -dri_gem_bo_unreference(dri_bo *bo) +dri_gem_bo_unreference_locked(dri_bo *bo) { dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr; dri_bo_gem *bo_gem = (dri_bo_gem *)bo; - if (!bo) - return; - if (--bo_gem->refcount == 0) { struct dri_gem_bo_bucket *bucket; @@ -424,7 +439,7 @@ dri_gem_bo_unreference(dri_bo *bo) /* Unreference all the target buffers */ for (i = 0; i < bo_gem->reloc_count; i++) - dri_bo_unreference(bo_gem->reloc_target_bo[i]); + dri_gem_bo_unreference_locked(bo_gem->reloc_target_bo[i]); free(bo_gem->reloc_target_bo); free(bo_gem->relocs); } @@ -452,20 +467,28 @@ dri_gem_bo_unreference(dri_bo *bo) } else { dri_gem_bo_free(bo); } - - return; } } +static void +dri_gem_bo_unreference(dri_bo *bo) +{ + dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr; + + pthread_mutex_lock(&bufmgr_gem->lock); + dri_gem_bo_unreference_locked(bo); + pthread_mutex_unlock(&bufmgr_gem->lock); +} + static int dri_gem_bo_map(dri_bo *bo, int write_enable) { - dri_bufmgr_gem *bufmgr_gem; + dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr; dri_bo_gem *bo_gem = (dri_bo_gem *)bo; struct drm_i915_gem_set_domain set_domain; int ret; - bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr; + pthread_mutex_lock(&bufmgr_gem->lock); /* Allow recursive mapping. Mesa may recursively map buffers with * nested display loops. @@ -515,6 +538,8 @@ dri_gem_bo_map(dri_bo *bo, int write_enable) bo_gem->swrast = 1; } + pthread_mutex_unlock(&bufmgr_gem->lock); + return 0; } @@ -531,6 +556,7 @@ dri_gem_bo_unmap(dri_bo *bo) assert(bo_gem->mapped); + pthread_mutex_lock(&bufmgr_gem->lock); if (bo_gem->swrast) { sw_finish.handle = bo_gem->gem_handle; do { @@ -539,6 +565,7 @@ dri_gem_bo_unmap(dri_bo *bo) } while (ret == -1 && errno == EINTR); bo_gem->swrast = 0; } + pthread_mutex_unlock(&bufmgr_gem->lock); return 0; } @@ -623,6 +650,8 @@ dri_bufmgr_gem_destroy(dri_bufmgr *bufmgr) free(bufmgr_gem->exec_objects); free(bufmgr_gem->exec_bos); + pthread_mutex_destroy(&bufmgr_gem->lock); + /* Free any cached buffer objects we were going to reuse */ for (i = 0; i < INTEL_GEM_BO_BUCKETS; i++) { struct dri_gem_bo_bucket *bucket = &bufmgr_gem->cache_bucket[i]; @@ -658,6 +687,8 @@ dri_gem_bo_emit_reloc(dri_bo *bo, uint32_t read_domains, uint32_t write_domain, dri_bo_gem *bo_gem = (dri_bo_gem *)bo; dri_bo_gem *target_bo_gem = (dri_bo_gem *)target_bo; + pthread_mutex_lock(&bufmgr_gem->lock); + /* Create a new relocation list if needed */ if (bo_gem->relocs == NULL) intel_setup_reloc_list(bo); @@ -678,9 +709,12 @@ dri_gem_bo_emit_reloc(dri_bo *bo, uint32_t read_domains, uint32_t write_domain, bo_gem->relocs[bo_gem->reloc_count].presumed_offset = target_bo->offset; bo_gem->reloc_target_bo[bo_gem->reloc_count] = target_bo; - dri_bo_reference(target_bo); + dri_gem_bo_reference_locked(target_bo); bo_gem->reloc_count++; + + pthread_mutex_unlock(&bufmgr_gem->lock); + return 0; } @@ -737,6 +771,7 @@ dri_gem_bo_exec(dri_bo *bo, int used, struct drm_i915_gem_execbuffer execbuf; int ret, i; + pthread_mutex_lock(&bufmgr_gem->lock); /* Update indices and set up the validate list. */ dri_gem_bo_process_reloc(bo); @@ -772,10 +807,11 @@ dri_gem_bo_exec(dri_bo *bo, int used, /* Disconnect the buffer from the validate list */ bo_gem->validate_index = -1; - dri_bo_unreference(bo); + dri_gem_bo_unreference_locked(bo); bufmgr_gem->exec_bos[i] = NULL; } bufmgr_gem->exec_count = 0; + pthread_mutex_unlock(&bufmgr_gem->lock); return 0; } @@ -900,6 +936,11 @@ intel_bufmgr_gem_init(int fd, int batch_size) bufmgr_gem = calloc(1, sizeof(*bufmgr_gem)); bufmgr_gem->fd = fd; + if (pthread_mutex_init(&bufmgr_gem->lock, NULL) != 0) { + free(bufmgr_gem); + return NULL; + } + /* Let's go with one relocation per every 2 dwords (but round down a bit * since a power of two will mean an extra page allocation for the reloc * buffer). -- cgit v1.2.3 From 9dda3a8f63331cb55f4669fd8edb600f2e07ec86 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 13 Oct 2008 07:16:33 +1000 Subject: libdrm: don't depend or link to libdrm_intel --- libdrm/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdrm') diff --git a/libdrm/Makefile.am b/libdrm/Makefile.am index 8e1c0ee4..8fd985bd 100644 --- a/libdrm/Makefile.am +++ b/libdrm/Makefile.am @@ -27,7 +27,7 @@ libdrm_la_LDFLAGS = -version-number 2:3:0 -no-undefined AM_CFLAGS = -I$(top_srcdir)/shared-core libdrm_la_SOURCES = xf86drm.c xf86drmHash.c xf86drmRandom.c xf86drmSL.c \ xf86drmMode.c libdrm_lists.h -libdrm_la_LIBADD = intel/libdrm_intel.la @PTHREADSTUBS_LIBS@ +libdrm_la_LIBADD = @PTHREADSTUBS_LIBS@ libdrmincludedir = ${includedir} libdrminclude_HEADERS = xf86drm.h xf86drmMode.h -- cgit v1.2.3 From 4c8aeb6fc7fa9f0aa9df4fd855696afe4bf6c0b4 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 17 Oct 2008 06:40:38 +1000 Subject: link libdrm_intel properly libdrm_intel needs symbols from libdrm, so link against it. (cherry picked from commit d9c2f65dd8e50736a33e97a55c257ef6843e1ce7) Conflicts: libdrm/Makefile.am --- libdrm/Makefile.am | 4 ++-- libdrm/intel/Makefile.am | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'libdrm') diff --git a/libdrm/Makefile.am b/libdrm/Makefile.am index 8fd985bd..c3619a6d 100644 --- a/libdrm/Makefile.am +++ b/libdrm/Makefile.am @@ -18,7 +18,7 @@ # 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. -SUBDIRS = intel +SUBDIRS = . intel libdrm_la_LTLIBRARIES = libdrm.la libdrm_ladir = $(libdir) @@ -27,7 +27,7 @@ libdrm_la_LDFLAGS = -version-number 2:3:0 -no-undefined AM_CFLAGS = -I$(top_srcdir)/shared-core libdrm_la_SOURCES = xf86drm.c xf86drmHash.c xf86drmRandom.c xf86drmSL.c \ xf86drmMode.c libdrm_lists.h -libdrm_la_LIBADD = @PTHREADSTUBS_LIBS@ + libdrm_lists.h libdrmincludedir = ${includedir} libdrminclude_HEADERS = xf86drm.h xf86drmMode.h diff --git a/libdrm/intel/Makefile.am b/libdrm/intel/Makefile.am index 92388c24..5e3dee06 100644 --- a/libdrm/intel/Makefile.am +++ b/libdrm/intel/Makefile.am @@ -32,6 +32,7 @@ AM_CFLAGS = \ libdrm_intel_la_LTLIBRARIES = libdrm_intel.la libdrm_intel_ladir = $(libdir) libdrm_intel_la_LDFLAGS = -version-number 1:0:0 -no-undefined +libdrm_intel_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@ libdrm_intel_la_SOURCES = \ intel_bufmgr.c \ -- cgit v1.2.3 From 34a3ebffc369575412a4ff2c05c50264e83c6d3e Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 24 Oct 2008 18:43:55 +0200 Subject: mode: Try to settle on a standard for struct fields --- libdrm/xf86drmMode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index c3921ee9..a25b11bb 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -308,7 +308,7 @@ int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width struct drm_mode_cursor arg; arg.flags = DRM_MODE_CURSOR_BO; - arg.crtc = crtcId; + arg.crtc_id = crtcId; arg.width = width; arg.height = height; arg.handle = bo_handle; @@ -321,7 +321,7 @@ int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y) struct drm_mode_cursor arg; arg.flags = DRM_MODE_CURSOR_MOVE; - arg.crtc = crtcId; + arg.crtc_id = crtcId; arg.x = x; arg.y = y; -- cgit v1.2.3 From 7617d1fef7b743349b470e4a62388174bbffb56b Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Mon, 27 Oct 2008 19:27:15 +0100 Subject: radeon: radeon util library --- libdrm/Makefile.am | 2 +- libdrm/radeon/Makefile.am | 43 ++++++++++ libdrm/radeon/radeon_bo.h | 102 +++++++++++++++++++++++ libdrm/radeon/radeon_bo_gem.c | 186 ++++++++++++++++++++++++++++++++++++++++++ libdrm/radeon/radeon_bo_gem.h | 38 +++++++++ libdrm/radeon/radeon_cs.h | 144 ++++++++++++++++++++++++++++++++ 6 files changed, 514 insertions(+), 1 deletion(-) create mode 100644 libdrm/radeon/Makefile.am create mode 100644 libdrm/radeon/radeon_bo.h create mode 100644 libdrm/radeon/radeon_bo_gem.c create mode 100644 libdrm/radeon/radeon_bo_gem.h create mode 100644 libdrm/radeon/radeon_cs.h (limited to 'libdrm') diff --git a/libdrm/Makefile.am b/libdrm/Makefile.am index c3619a6d..ded86308 100644 --- a/libdrm/Makefile.am +++ b/libdrm/Makefile.am @@ -18,7 +18,7 @@ # 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. -SUBDIRS = . intel +SUBDIRS = . intel radeon libdrm_la_LTLIBRARIES = libdrm.la libdrm_ladir = $(libdir) diff --git a/libdrm/radeon/Makefile.am b/libdrm/radeon/Makefile.am new file mode 100644 index 00000000..6af06a7f --- /dev/null +++ b/libdrm/radeon/Makefile.am @@ -0,0 +1,43 @@ +# Copyright © 2008 Jérôme Glisse +# +# 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 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. +# +# Authors: +# Jérôme Glisse + +AM_CFLAGS = \ + $(WARN_CFLAGS) \ + -I$(top_srcdir)/libdrm \ + -I$(top_srcdir)/libdrm/radeon \ + $(PTHREADSTUBS_CFLAGS) \ + -I$(top_srcdir)/shared-core + +libdrm_radeon_la_LTLIBRARIES = libdrm_radeon.la +libdrm_radeon_ladir = $(libdir) +libdrm_radeon_la_LDFLAGS = -version-number 1:0:0 -no-undefined +libdrm_radeon_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@ + +libdrm_radeon_la_SOURCES = \ + radeon_bo_gem.c + +libdrm_radeonincludedir = ${includedir} +libdrm_radeoninclude_HEADERS = \ + radeon_bo.h \ + radeon_cs.h diff --git a/libdrm/radeon/radeon_bo.h b/libdrm/radeon/radeon_bo.h new file mode 100644 index 00000000..67c75262 --- /dev/null +++ b/libdrm/radeon/radeon_bo.h @@ -0,0 +1,102 @@ +/* + * Copyright © 2008 Jérôme Glisse + * 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, sub license, 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 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Jérôme Glisse + */ +#ifndef RADEON_BO_H +#define RADEON_BO_H + +#include + +/* bo object */ +#define RADEON_BO_FLAGS_MACRO_TILE 1 +#define RADEON_BO_FLAGS_MICRO_TILE 2 + +struct radeon_bo_manager; + +struct radeon_bo { + uint32_t alignment; + uint32_t handle; + uint32_t size; + uint32_t flags; + void *ptr; + struct radeon_bo_manager *bom; +}; + +/* bo functions */ +struct radeon_bo_funcs { + struct radeon_bo *(*bo_open)(struct radeon_bo_manager *bom, + uint32_t handle, + uint32_t size, + uint32_t alignment, + uint32_t flags); + void (*bo_close)(struct radeon_bo *bo); + void (*bo_pin)(struct radeon_bo *bo); + void (*bo_unpin)(struct radeon_bo *bo); + int (*bo_map)(struct radeon_bo *bo, unsigned int flags); + int (*bo_unmap)(struct radeon_bo *bo); +}; + +struct radeon_bo_manager { + struct radeon_bo_funcs *funcs; + int fd; +}; + +static inline struct radeon_bo *radeon_bo_open(struct radeon_bo_manager *bom, + uint32_t handle, + uint32_t size, + uint32_t alignment, + uint32_t flags) +{ + return bom->funcs->bo_open(bom, handle, size, alignment, flags); +} + +static inline void radeon_bo_close(struct radeon_bo *bo) +{ + return bo->bom->funcs->bo_close(bo); +} + +static inline void radeon_bo_pin(struct radeon_bo *bo) +{ + return bo->bom->funcs->bo_pin(bo); +} + +static inline void radeon_bo_unpin(struct radeon_bo *bo) +{ + return bo->bom->funcs->bo_unpin(bo); +} + +static inline int radeon_bo_map(struct radeon_bo *bo, unsigned int flags) +{ + return bo->bom->funcs->bo_map(bo, flags); +} + +static inline int radeon_bo_unmap(struct radeon_bo *bo) +{ + return bo->bom->funcs->bo_unmap(bo); +} + +#endif diff --git a/libdrm/radeon/radeon_bo_gem.c b/libdrm/radeon/radeon_bo_gem.c new file mode 100644 index 00000000..21fe41f9 --- /dev/null +++ b/libdrm/radeon/radeon_bo_gem.c @@ -0,0 +1,186 @@ +/* + * Copyright © 2008 Dave Airlie + * Copyright © 2008 Jérôme Glisse + * 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, sub license, 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 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Dave Airlie + * Jérôme Glisse + */ +#include +#include +#include +#include +#include +#include +#include "xf86drm.h" +#include "drm.h" +#include "radeon_drm.h" +#include "radeon_bo.h" +#include "radeon_bo_gem.h" + +struct radeon_bo_gem { + struct radeon_bo base; + int ref_count; + int map_count; +}; + +static struct radeon_bo *bo_open(struct radeon_bo_manager *bom, + uint32_t handle, + uint32_t size, + uint32_t alignment, + uint32_t flags) +{ + struct radeon_bo_gem *bo; + int r; + + bo = (struct radeon_bo_gem*)calloc(1, sizeof(struct radeon_bo_gem)); + if (bo == NULL) { + return NULL; + } + + bo->base.bom = bom; + bo->base.handle = 0; + bo->base.size = size; + bo->base.alignment = alignment; + bo->base.flags = flags; + bo->base.ptr = NULL; + bo->ref_count = 0; + bo->map_count = 0; + + if (handle) { + struct drm_gem_open open_arg; + + memset(&open_arg, 0, sizeof(open_arg)); + open_arg.name = handle; + r = ioctl(bom->fd, DRM_IOCTL_GEM_OPEN, &open_arg); + if (r != 0) { + fprintf(stderr, "GEM open failed: %d (%s)\n",r,strerror(r)); + free(bo); + return NULL; + } + bo->base.handle = handle; + } else { + struct drm_radeon_gem_create args; + + args.size = size; + args.alignment = alignment; + args.initial_domain = RADEON_GEM_DOMAIN_CPU; + args.no_backing_store = 0; + r = drmCommandWriteRead(bom->fd, DRM_RADEON_GEM_CREATE, + &args, sizeof(args)); + bo->base.handle = args.handle; + if (r) { + free(bo); + return NULL; + } + } + return (struct radeon_bo*)bo; +} + +static void bo_close(struct radeon_bo *bo) +{ + struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo; + struct drm_gem_close args; + + if (bo == NULL) { + return; + } + if (bo_gem->ref_count) { + /* FIXME: what to do ? */ + } + + if (bo_gem->map_count) { + munmap(bo->ptr, bo->size); + } + + /* close object */ + args.handle = bo->handle; + ioctl(bo->bom->fd, DRM_IOCTL_GEM_CLOSE, &args); + free(bo_gem); +} + +static void bo_pin(struct radeon_bo *bo) +{ + struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo; + + bo_gem->ref_count++; +} + +static void bo_unpin(struct radeon_bo *bo) +{ + struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo; + + bo_gem->ref_count--; +} + +static int bo_map(struct radeon_bo *bo, unsigned int flags) +{ + struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo; + struct drm_radeon_gem_mmap args; + int r; + + if (bo_gem->map_count++ != 0) { + return 0; + } + args.handle = bo->handle; + args.offset = 0; + args.size = bo->size; + + r = drmCommandWriteRead(bo->bom->fd, + DRM_RADEON_GEM_MMAP, + &args, + sizeof(args)); + if (!r) { + bo->ptr = (void *)(unsigned long)args.addr_ptr; + } + return r; +} + +static int bo_unmap(struct radeon_bo *bo) +{ + struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo; + + if (--bo_gem->map_count > 0) { + return 0; + } + + munmap(bo->ptr, bo->size); + bo->ptr = NULL; + return 0; +} + +static struct radeon_bo_funcs bo_gem_funcs = { + bo_open, + bo_close, + bo_pin, + bo_unpin, + bo_map, + bo_unmap +}; + +struct radeon_bo_funcs *radeon_bo_gem_initialize(int fd) +{ + return &bo_gem_funcs; +} diff --git a/libdrm/radeon/radeon_bo_gem.h b/libdrm/radeon/radeon_bo_gem.h new file mode 100644 index 00000000..e0ed61fb --- /dev/null +++ b/libdrm/radeon/radeon_bo_gem.h @@ -0,0 +1,38 @@ +/* + * Copyright © 2008 Dave Airlie + * Copyright © 2008 Jérôme Glisse + * 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, sub license, 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 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Dave Airlie + * Jérôme Glisse + */ +#ifndef RADEON_BO_GEM_H +#define RADEON_BO_GEM_H + +#include "radeon_bo.h" + +struct radeon_bo_funcs *radeon_bo_gem_initialize(int fd); + +#endif diff --git a/libdrm/radeon/radeon_cs.h b/libdrm/radeon/radeon_cs.h new file mode 100644 index 00000000..71b2839f --- /dev/null +++ b/libdrm/radeon/radeon_cs.h @@ -0,0 +1,144 @@ +/* + * Copyright © 2008 Nicolai Haehnle + * Copyright © 2008 Jérôme Glisse + * 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, sub license, 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 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Aapo Tahkola + * Nicolai Haehnle + * Jérôme Glisse + */ +#ifndef RADEON_CS_H +#define RADEON_CS_H + +#include +#include "radeon_bo.h" + +struct radeon_cs_reloc { + struct radeon_bo *bo; + uint32_t soffset; + uint32_t eoffset; + uint32_t size; + uint32_t domains; +}; + +struct radeon_cs_manager; + +struct radeon_cs { + struct radeon_cs_manager *csm; + struct radeon_cs_reloc *relocs; + uint32_t *packets; + unsigned crelocs; + unsigned cdw; + unsigned ndw; + int section; + unsigned section_ndw; + unsigned section_cdw; + const char *section_file; + const char *section_func; + int section_line; +}; + +/* cs functions */ +struct radeon_cs_funcs { + struct radeon_cs *(*cs_create)(struct radeon_cs_manager *csm, + uint32_t ndw); + int (*cs_write_dword)(struct radeon_cs *cs, uint32_t dword); + int (*cs_write_reloc)(struct radeon_cs *cs, + struct radeon_bo *bo, + uint32_t soffset, + uint32_t eoffset, + uint32_t domains); + int (*cs_begin)(struct radeon_cs *cs, + uint32_t ndw, + const char *file, + const char *func, + int line); + int (*cs_end)(struct radeon_cs *cs, + const char *file, + const char *func, + int line); + int (*cs_emit)(struct radeon_cs *cs); + int (*cs_destroy)(struct radeon_cs *cs); + int (*cs_erase)(struct radeon_cs *cs); +}; + +struct radeon_cs_manager { + struct radeon_cs_funcs *funcs; + int fd; +}; + +static inline struct radeon_cs *radeon_cs_create(struct radeon_cs_manager *csm, + uint32_t ndw) +{ + return csm->funcs->cs_create(csm, ndw); +} + +static inline int radeon_cs_write_dword(struct radeon_cs *cs, uint32_t dword) +{ + return cs->csm->funcs->cs_write_dword(cs, dword); +} + +static inline int radeon_cs_write_reloc(struct radeon_cs *cs, + struct radeon_bo *bo, + uint32_t soffset, + uint32_t eoffset, + uint32_t domains) +{ + return cs->csm->funcs->cs_write_reloc(cs, bo, soffset, eoffset, domains); +} + +static inline int radeon_cs_begin(struct radeon_cs *cs, + uint32_t ndw, + const char *file, + const char *func, + int line) +{ + return cs->csm->funcs->cs_begin(cs, ndw, file, func, line); +} + +static inline int radeon_cs_end(struct radeon_cs *cs, + const char *file, + const char *func, + int line) +{ + return cs->csm->funcs->cs_end(cs, file, func, line); +} + +static inline int radeon_cs_emit(struct radeon_cs *cs) +{ + return cs->csm->funcs->cs_emit(cs); +} + +static inline int radeon_cs_destroy(struct radeon_cs *cs) +{ + return cs->csm->funcs->cs_destroy(cs); +} + +static inline int radeon_cs_erase(struct radeon_cs *cs) +{ + return cs->csm->funcs->cs_erase(cs); +} + +#endif -- cgit v1.2.3 From af118cd186407cd8e72ccd63f6deca56f1ffd905 Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Mon, 27 Oct 2008 23:26:15 +0100 Subject: radeon: reloc are backend dependant --- libdrm/radeon/radeon_cs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdrm') diff --git a/libdrm/radeon/radeon_cs.h b/libdrm/radeon/radeon_cs.h index 71b2839f..6d560748 100644 --- a/libdrm/radeon/radeon_cs.h +++ b/libdrm/radeon/radeon_cs.h @@ -47,7 +47,7 @@ struct radeon_cs_manager; struct radeon_cs { struct radeon_cs_manager *csm; - struct radeon_cs_reloc *relocs; + void *relocs; uint32_t *packets; unsigned crelocs; unsigned cdw; -- cgit v1.2.3 From 5d861951b3714d13292d18f3731294c83e209b3a Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Wed, 29 Oct 2008 23:40:20 +0100 Subject: radeon: libdrm_radeon updates bo & cs interfaces --- libdrm/radeon/radeon_bo.h | 93 ++++++++++++++++++++++++++++++++++++----------- libdrm/radeon/radeon_cs.h | 7 ++++ 2 files changed, 78 insertions(+), 22 deletions(-) (limited to 'libdrm') diff --git a/libdrm/radeon/radeon_bo.h b/libdrm/radeon/radeon_bo.h index 67c75262..00dd521b 100644 --- a/libdrm/radeon/radeon_bo.h +++ b/libdrm/radeon/radeon_bo.h @@ -29,6 +29,7 @@ #ifndef RADEON_BO_H #define RADEON_BO_H +#include #include /* bo object */ @@ -42,6 +43,7 @@ struct radeon_bo { uint32_t handle; uint32_t size; uint32_t flags; + unsigned cref; void *ptr; struct radeon_bo_manager *bom; }; @@ -53,10 +55,9 @@ struct radeon_bo_funcs { uint32_t size, uint32_t alignment, uint32_t flags); - void (*bo_close)(struct radeon_bo *bo); - void (*bo_pin)(struct radeon_bo *bo); - void (*bo_unpin)(struct radeon_bo *bo); - int (*bo_map)(struct radeon_bo *bo, unsigned int flags); + void (*bo_ref)(struct radeon_bo *bo); + void (*bo_unref)(struct radeon_bo *bo); + int (*bo_map)(struct radeon_bo *bo, int write); int (*bo_unmap)(struct radeon_bo *bo); }; @@ -65,38 +66,86 @@ struct radeon_bo_manager { int fd; }; -static inline struct radeon_bo *radeon_bo_open(struct radeon_bo_manager *bom, - uint32_t handle, - uint32_t size, - uint32_t alignment, - uint32_t flags) +static inline struct radeon_bo *_radeon_bo_open(struct radeon_bo_manager *bom, + uint32_t handle, + uint32_t size, + uint32_t alignment, + uint32_t flags, + const char *file, + const char *func, + int line) { - return bom->funcs->bo_open(bom, handle, size, alignment, flags); -} - -static inline void radeon_bo_close(struct radeon_bo *bo) -{ - return bo->bom->funcs->bo_close(bo); + struct radeon_bo *bo; + bo = bom->funcs->bo_open(bom, handle, size, alignment, flags); +#ifdef RADEON_BO_TRACK_OPEN + if (bo) { + fprintf(stderr, "+open (%p, %d, %d) at (%s, %s, %d)\n", + bo, bo->size, bo->cref, file, func, line); + } +#endif + return bo; } -static inline void radeon_bo_pin(struct radeon_bo *bo) +static inline void _radeon_bo_ref(struct radeon_bo *bo, + const char *file, + const char *func, + int line) { - return bo->bom->funcs->bo_pin(bo); + bo->cref++; +#ifdef RADEON_BO_TRACK_REF + fprintf(stderr, "+ref (%p, %d, %d) at (%s, %s, %d)\n", + bo, bo->size, bo->cref, file, func, line); +#endif + bo->bom->funcs->bo_ref(bo); } -static inline void radeon_bo_unpin(struct radeon_bo *bo) +static inline void _radeon_bo_unref(struct radeon_bo *bo, + const char *file, + const char *func, + int line) { - return bo->bom->funcs->bo_unpin(bo); + bo->cref--; +#ifdef RADEON_BO_TRACK_REF + fprintf(stderr, "-unref(%p, %d, %d) at (%s, %s, %d)\n", + bo, bo->size, bo->cref, file, func, line); +#endif + bo->bom->funcs->bo_unref(bo); } -static inline int radeon_bo_map(struct radeon_bo *bo, unsigned int flags) +static inline int _radeon_bo_map(struct radeon_bo *bo, + int write, + const char *file, + const char *func, + int line) { - return bo->bom->funcs->bo_map(bo, flags); +#ifdef RADEON_BO_TRACK_MAP + fprintf(stderr, "+map (%p, %d, %d) at (%s, %s, %d)\n", + bo, bo->size, bo->cref, file, func, line); +#endif + return bo->bom->funcs->bo_map(bo, write); } -static inline int radeon_bo_unmap(struct radeon_bo *bo) +static inline int _radeon_bo_unmap(struct radeon_bo *bo, + const char *file, + const char *func, + int line) { +#ifdef RADEON_BO_TRACK_MAP + fprintf(stderr, "-unmap(%p, %d, %d) at (%s, %s, %d)\n", + bo, bo->size, bo->cref, file, func, line); +#endif return bo->bom->funcs->bo_unmap(bo); } +#define radeon_bo_open(bom, h, s, a, f)\ + _radeon_bo_open(bom, h, s, a, f, __FILE__, __FUNCTION__, __LINE__) +#define radeon_bo_ref(bo)\ + _radeon_bo_ref(bo, __FILE__, __FUNCTION__, __LINE__) +#define radeon_bo_unref(bo)\ + _radeon_bo_unref(bo, __FILE__, __FUNCTION__, __LINE__) +#define radeon_bo_map(bo, w)\ + _radeon_bo_map(bo, w, __FILE__, __FUNCTION__, __LINE__) +#define radeon_bo_unmap(bo)\ + _radeon_bo_unmap(bo, __FILE__, __FUNCTION__, __LINE__) + #endif diff --git a/libdrm/radeon/radeon_cs.h b/libdrm/radeon/radeon_cs.h index 6d560748..347e9f35 100644 --- a/libdrm/radeon/radeon_cs.h +++ b/libdrm/radeon/radeon_cs.h @@ -50,6 +50,7 @@ struct radeon_cs { void *relocs; uint32_t *packets; unsigned crelocs; + unsigned relocs_total_size; unsigned cdw; unsigned ndw; int section; @@ -82,6 +83,7 @@ struct radeon_cs_funcs { int (*cs_emit)(struct radeon_cs *cs); int (*cs_destroy)(struct radeon_cs *cs); int (*cs_erase)(struct radeon_cs *cs); + int (*cs_need_flush)(struct radeon_cs *cs); }; struct radeon_cs_manager { @@ -141,4 +143,9 @@ static inline int radeon_cs_erase(struct radeon_cs *cs) return cs->csm->funcs->cs_erase(cs); } +static inline int radeon_cs_need_flush(struct radeon_cs *cs) +{ + return cs->csm->funcs->cs_need_flush(cs); +} + #endif -- cgit v1.2.3 From 7651b4c424aa6c6ac6c47b2d07c8f65d0b9d0191 Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Sun, 2 Nov 2008 16:00:06 +0100 Subject: radeon: debug bo --- libdrm/radeon/radeon_bo.h | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'libdrm') diff --git a/libdrm/radeon/radeon_bo.h b/libdrm/radeon/radeon_bo.h index 00dd521b..68adc3e9 100644 --- a/libdrm/radeon/radeon_bo.h +++ b/libdrm/radeon/radeon_bo.h @@ -65,6 +65,16 @@ struct radeon_bo_manager { struct radeon_bo_funcs *funcs; int fd; }; + +static inline void _radeon_bo_debug(struct radeon_bo *bo, + int opcode, + const char *file, + const char *func, + int line) +{ + fprintf(stderr, "%02d %p 0x%08X 0x%08X [%s %s %d]\n", + opcode, bo, bo->size, bo->cref, file, func, line); +} static inline struct radeon_bo *_radeon_bo_open(struct radeon_bo_manager *bom, uint32_t handle, @@ -79,8 +89,7 @@ static inline struct radeon_bo *_radeon_bo_open(struct radeon_bo_manager *bom, bo = bom->funcs->bo_open(bom, handle, size, alignment, flags); #ifdef RADEON_BO_TRACK_OPEN if (bo) { - fprintf(stderr, "+open (%p, %d, %d) at (%s, %s, %d)\n", - bo, bo->size, bo->cref, file, func, line); + _radeon_bo_debug(bo, 1, file, func, line); } #endif return bo; @@ -93,8 +102,7 @@ static inline void _radeon_bo_ref(struct radeon_bo *bo, { bo->cref++; #ifdef RADEON_BO_TRACK_REF - fprintf(stderr, "+ref (%p, %d, %d) at (%s, %s, %d)\n", - bo, bo->size, bo->cref, file, func, line); + _radeon_bo_debug(bo, 2, file, func, line); #endif bo->bom->funcs->bo_ref(bo); } @@ -106,8 +114,7 @@ static inline void _radeon_bo_unref(struct radeon_bo *bo, { bo->cref--; #ifdef RADEON_BO_TRACK_REF - fprintf(stderr, "-unref(%p, %d, %d) at (%s, %s, %d)\n", - bo, bo->size, bo->cref, file, func, line); + _radeon_bo_debug(bo, 3, file, func, line); #endif bo->bom->funcs->bo_unref(bo); } @@ -119,8 +126,7 @@ static inline int _radeon_bo_map(struct radeon_bo *bo, int line) { #ifdef RADEON_BO_TRACK_MAP - fprintf(stderr, "+map (%p, %d, %d) at (%s, %s, %d)\n", - bo, bo->size, bo->cref, file, func, line); + _radeon_bo_debug(bo, 4, file, func, line); #endif return bo->bom->funcs->bo_map(bo, write); } @@ -131,8 +137,7 @@ static inline int _radeon_bo_unmap(struct radeon_bo *bo, int line) { #ifdef RADEON_BO_TRACK_MAP - fprintf(stderr, "-unmap(%p, %d, %d) at (%s, %s, %d)\n", - bo, bo->size, bo->cref, file, func, line); + _radeon_bo_debug(bo, 5, file, func, line); #endif return bo->bom->funcs->bo_unmap(bo); } @@ -147,5 +152,7 @@ static inline int _radeon_bo_unmap(struct radeon_bo *bo, _radeon_bo_map(bo, w, __FILE__, __FUNCTION__, __LINE__) #define radeon_bo_unmap(bo)\ _radeon_bo_unmap(bo, __FILE__, __FUNCTION__, __LINE__) +#define radeon_bo_debug(bo, opcode)\ + _radeon_bo_debug(bo, opcode, __FILE__, __FUNCTION__, __LINE__) #endif -- cgit v1.2.3 From 2d822542c74c9a38d18724f568642397b5a4d13d Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Wed, 5 Nov 2008 16:00:04 +0100 Subject: radeon: libdrm_radeon add handle to debug string --- libdrm/radeon/radeon_bo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdrm') diff --git a/libdrm/radeon/radeon_bo.h b/libdrm/radeon/radeon_bo.h index 68adc3e9..c1f25fa1 100644 --- a/libdrm/radeon/radeon_bo.h +++ b/libdrm/radeon/radeon_bo.h @@ -72,8 +72,8 @@ static inline void _radeon_bo_debug(struct radeon_bo *bo, const char *func, int line) { - fprintf(stderr, "%02d %p 0x%08X 0x%08X [%s %s %d]\n", - opcode, bo, bo->size, bo->cref, file, func, line); + fprintf(stderr, "%02d %p 0x%08X 0x%08X 0x%08X [%s %s %d]\n", + opcode, bo, bo->handle, bo->size, bo->cref, file, func, line); } static inline struct radeon_bo *_radeon_bo_open(struct radeon_bo_manager *bom, -- cgit v1.2.3 From 273cc1a69887df2bccfab96120f992c506c9035e Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Thu, 6 Nov 2008 00:40:06 +0100 Subject: radeon: lib radeon add bo & cs gem backend --- libdrm/radeon/Makefile.am | 9 +- libdrm/radeon/radeon_bo.h | 9 +- libdrm/radeon/radeon_bo_gem.c | 76 +++++++----- libdrm/radeon/radeon_bo_gem.h | 3 +- libdrm/radeon/radeon_cs_gem.c | 266 ++++++++++++++++++++++++++++++++++++++++++ libdrm/radeon/radeon_cs_gem.h | 40 +++++++ 6 files changed, 365 insertions(+), 38 deletions(-) create mode 100644 libdrm/radeon/radeon_cs_gem.c create mode 100644 libdrm/radeon/radeon_cs_gem.h (limited to 'libdrm') diff --git a/libdrm/radeon/Makefile.am b/libdrm/radeon/Makefile.am index 6af06a7f..cc4951a9 100644 --- a/libdrm/radeon/Makefile.am +++ b/libdrm/radeon/Makefile.am @@ -35,9 +35,12 @@ libdrm_radeon_la_LDFLAGS = -version-number 1:0:0 -no-undefined libdrm_radeon_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@ libdrm_radeon_la_SOURCES = \ - radeon_bo_gem.c + radeon_bo_gem.c \ + radeon_cs_gem.c -libdrm_radeonincludedir = ${includedir} +libdrm_radeonincludedir = ${includedir}/drm libdrm_radeoninclude_HEADERS = \ radeon_bo.h \ - radeon_cs.h + radeon_cs.h \ + radeon_bo_gem.h \ + radeon_cs_gem.h diff --git a/libdrm/radeon/radeon_bo.h b/libdrm/radeon/radeon_bo.h index c1f25fa1..a0739265 100644 --- a/libdrm/radeon/radeon_bo.h +++ b/libdrm/radeon/radeon_bo.h @@ -42,6 +42,7 @@ struct radeon_bo { uint32_t alignment; uint32_t handle; uint32_t size; + uint32_t domains; uint32_t flags; unsigned cref; void *ptr; @@ -54,6 +55,7 @@ struct radeon_bo_funcs { uint32_t handle, uint32_t size, uint32_t alignment, + uint32_t domains, uint32_t flags); void (*bo_ref)(struct radeon_bo *bo); void (*bo_unref)(struct radeon_bo *bo); @@ -80,13 +82,14 @@ static inline struct radeon_bo *_radeon_bo_open(struct radeon_bo_manager *bom, uint32_t handle, uint32_t size, uint32_t alignment, + uint32_t domains, uint32_t flags, const char *file, const char *func, int line) { struct radeon_bo *bo; - bo = bom->funcs->bo_open(bom, handle, size, alignment, flags); + bo = bom->funcs->bo_open(bom, handle, size, alignment, domains, flags); #ifdef RADEON_BO_TRACK_OPEN if (bo) { _radeon_bo_debug(bo, 1, file, func, line); @@ -142,8 +145,8 @@ static inline int _radeon_bo_unmap(struct radeon_bo *bo, return bo->bom->funcs->bo_unmap(bo); } -#define radeon_bo_open(bom, h, s, a, f)\ - _radeon_bo_open(bom, h, s, a, f, __FILE__, __FUNCTION__, __LINE__) +#define radeon_bo_open(bom, h, s, a, d, f)\ + _radeon_bo_open(bom, h, s, a, d, f, __FILE__, __FUNCTION__, __LINE__) #define radeon_bo_ref(bo)\ _radeon_bo_ref(bo, __FILE__, __FUNCTION__, __LINE__) #define radeon_bo_unref(bo)\ diff --git a/libdrm/radeon/radeon_bo_gem.c b/libdrm/radeon/radeon_bo_gem.c index 21fe41f9..04e36c59 100644 --- a/libdrm/radeon/radeon_bo_gem.c +++ b/libdrm/radeon/radeon_bo_gem.c @@ -42,14 +42,19 @@ struct radeon_bo_gem { struct radeon_bo base; - int ref_count; + uint32_t name; int map_count; }; +struct bo_manager_gem { + struct radeon_bo_manager base; +}; + static struct radeon_bo *bo_open(struct radeon_bo_manager *bom, uint32_t handle, uint32_t size, uint32_t alignment, + uint32_t domains, uint32_t flags) { struct radeon_bo_gem *bo; @@ -64,11 +69,10 @@ static struct radeon_bo *bo_open(struct radeon_bo_manager *bom, bo->base.handle = 0; bo->base.size = size; bo->base.alignment = alignment; + bo->base.domains = domains; bo->base.flags = flags; bo->base.ptr = NULL; - bo->ref_count = 0; bo->map_count = 0; - if (handle) { struct drm_gem_open open_arg; @@ -80,13 +84,15 @@ static struct radeon_bo *bo_open(struct radeon_bo_manager *bom, free(bo); return NULL; } - bo->base.handle = handle; + bo->base.handle = open_arg.handle; + bo->base.size = open_arg.size; + bo->name = handle; } else { struct drm_radeon_gem_create args; args.size = size; args.alignment = alignment; - args.initial_domain = RADEON_GEM_DOMAIN_CPU; + args.initial_domain = bo->base.domains; args.no_backing_store = 0; r = drmCommandWriteRead(bom->fd, DRM_RADEON_GEM_CREATE, &args, sizeof(args)); @@ -99,7 +105,11 @@ static struct radeon_bo *bo_open(struct radeon_bo_manager *bom, return (struct radeon_bo*)bo; } -static void bo_close(struct radeon_bo *bo) +static void bo_ref(struct radeon_bo *bo) +{ +} + +static void bo_unref(struct radeon_bo *bo) { struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo; struct drm_gem_close args; @@ -107,10 +117,10 @@ static void bo_close(struct radeon_bo *bo) if (bo == NULL) { return; } - if (bo_gem->ref_count) { + if (bo->cref) { /* FIXME: what to do ? */ + return; } - if (bo_gem->map_count) { munmap(bo->ptr, bo->size); } @@ -121,33 +131,20 @@ static void bo_close(struct radeon_bo *bo) free(bo_gem); } -static void bo_pin(struct radeon_bo *bo) -{ - struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo; - - bo_gem->ref_count++; -} - -static void bo_unpin(struct radeon_bo *bo) -{ - struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo; - - bo_gem->ref_count--; -} - -static int bo_map(struct radeon_bo *bo, unsigned int flags) +static int bo_map(struct radeon_bo *bo, int write) { struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo; struct drm_radeon_gem_mmap args; int r; + uint8_t *tt; if (bo_gem->map_count++ != 0) { return 0; } + bo->ptr = NULL; args.handle = bo->handle; args.offset = 0; - args.size = bo->size; - + args.size = (uint64_t)bo->size; r = drmCommandWriteRead(bo->bom->fd, DRM_RADEON_GEM_MMAP, &args, @@ -155,6 +152,7 @@ static int bo_map(struct radeon_bo *bo, unsigned int flags) if (!r) { bo->ptr = (void *)(unsigned long)args.addr_ptr; } + tt = bo->ptr; return r; } @@ -165,7 +163,6 @@ static int bo_unmap(struct radeon_bo *bo) if (--bo_gem->map_count > 0) { return 0; } - munmap(bo->ptr, bo->size); bo->ptr = NULL; return 0; @@ -173,14 +170,31 @@ static int bo_unmap(struct radeon_bo *bo) static struct radeon_bo_funcs bo_gem_funcs = { bo_open, - bo_close, - bo_pin, - bo_unpin, + bo_ref, + bo_unref, bo_map, bo_unmap }; -struct radeon_bo_funcs *radeon_bo_gem_initialize(int fd) +struct radeon_bo_manager *radeon_bo_manager_gem(int fd) { - return &bo_gem_funcs; + struct bo_manager_gem *bomg; + + bomg = (struct bo_manager_gem*)calloc(1, sizeof(struct bo_manager_gem)); + if (bomg == NULL) { + return NULL; + } + bomg->base.funcs = &bo_gem_funcs; + bomg->base.fd = fd; + return (struct radeon_bo_manager*)bomg; +} + +void radeon_bo_manager_gem_shutdown(struct radeon_bo_manager *bom) +{ + struct bo_manager_gem *bomg = (struct bo_manager_gem*)bom; + + if (bom == NULL) { + return; + } + free(bomg); } diff --git a/libdrm/radeon/radeon_bo_gem.h b/libdrm/radeon/radeon_bo_gem.h index e0ed61fb..d0997614 100644 --- a/libdrm/radeon/radeon_bo_gem.h +++ b/libdrm/radeon/radeon_bo_gem.h @@ -33,6 +33,7 @@ #include "radeon_bo.h" -struct radeon_bo_funcs *radeon_bo_gem_initialize(int fd); +struct radeon_bo_manager *radeon_bo_manager_gem(int fd); +void radeon_bo_manager_gem_shutdown(struct radeon_bo_manager *bom); #endif diff --git a/libdrm/radeon/radeon_cs_gem.c b/libdrm/radeon/radeon_cs_gem.c new file mode 100644 index 00000000..7ed5780b --- /dev/null +++ b/libdrm/radeon/radeon_cs_gem.c @@ -0,0 +1,266 @@ +/* + * Copyright © 2008 Jérôme Glisse + * 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, sub license, 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 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Jérôme Glisse + */ +#include +#include +#include "radeon_cs.h" +#include "radeon_cs_gem.h" +#include "radeon_bo_gem.h" +#include "drm.h" +#include "radeon_drm.h" + +#pragma pack(1) +struct cs_reloc_gem { + uint32_t handle; + uint32_t domains; + uint32_t soffset; + uint32_t eoffset; +}; +#pragma pack() + +struct cs_gem { + struct radeon_cs base; + struct drm_radeon_cs2 cs; + struct drm_radeon_cs_chunk chunks[2]; + unsigned nrelocs; + uint32_t *relocs; +}; + +static struct radeon_cs *cs_create(struct radeon_cs_manager *csm, + uint32_t ndw) +{ + struct cs_gem *csg; + + /* max cmd buffer size is 64Kb */ + if (ndw > (64 * 1024 / 4)) { + return NULL; + } + csg = (struct cs_gem*)calloc(1, sizeof(struct cs_gem)); + if (csg == NULL) { + return NULL; + } + csg->base.csm = csm; + csg->base.ndw = 64 * 1024 / 4; + csg->base.packets = (uint32_t*)calloc(1, 64 * 1024); + if (csg->base.packets == NULL) { + free(csg); + return NULL; + } + csg->base.relocs_total_size = 0; + csg->base.crelocs = 0; + csg->nrelocs = 4096 / (4 * 4) ; + csg->base.relocs = csg->relocs = (uint32_t*)calloc(1, 4096); + if (csg->relocs == NULL) { + free(csg->base.packets); + free(csg); + return NULL; + } + csg->chunks[0].chunk_id = RADEON_CHUNK_ID_IB; + csg->chunks[0].length_dw = 0; + csg->chunks[0].chunk_data = (uint64_t)(intptr_t)csg->base.packets; + csg->chunks[1].chunk_id = RADEON_CHUNK_ID_RELOCS; + csg->chunks[1].length_dw = 0; + csg->chunks[1].chunk_data = (uint64_t)(intptr_t)csg->relocs; + return (struct radeon_cs*)csg; +} + +static int cs_write_dword(struct radeon_cs *cs, uint32_t dword) +{ + if (cs->cdw >= cs->ndw) { + uint32_t tmp, *ptr; + tmp = (cs->cdw + 1 + 0x3FF) & (~0x3FF); + ptr = (uint32_t*)realloc(cs->packets, 4 * tmp); + if (ptr == NULL) { + return -ENOMEM; + } + cs->packets = ptr; + cs->ndw = tmp; + } + cs->packets[cs->cdw++] = dword; + if (cs->section) { + cs->section_cdw++; + } + return 0; +} + +static int cs_write_reloc(struct radeon_cs *cs, + struct radeon_bo *bo, + uint32_t soffset, + uint32_t eoffset, + uint32_t domains) +{ + struct cs_gem *csg = (struct cs_gem*)cs; + struct cs_reloc_gem *reloc; + unsigned i; + + /* check reloc window */ + if (eoffset > bo->size) { + return -EINVAL; + } + if (soffset > eoffset) { + return -EINVAL; + } + /* check if bo is already referenced */ + for(i = 0; i < cs->crelocs; i++) { + reloc = (struct cs_reloc_gem*)&csg->relocs[i * 4]; + + if (reloc->handle == bo->handle) { + /* update start offset and size */ + if (eoffset > reloc->eoffset) { + reloc->eoffset = eoffset; + } + if (soffset < reloc->soffset) { + reloc->soffset = soffset; + } + reloc->domains |= domains; + return 0; + } + } + /* add bo */ + if (csg->base.crelocs >= csg->nrelocs) { + uint32_t *tmp, size; + size = (csg->nrelocs * 4 * 4) + (4096 / (4 * 4)); + tmp = (uint32_t*)realloc(csg->relocs, size); + if (tmp == NULL) { + return -ENOMEM; + } + cs->relocs = csg->relocs = tmp; + csg->nrelocs = size / (4 * 4); + } + reloc = (struct cs_reloc_gem*)&csg->relocs[csg->base.crelocs * 4]; + reloc->handle = bo->handle; + reloc->soffset = soffset; + reloc->eoffset = eoffset; + reloc->domains = domains; + cs->crelocs++; + radeon_bo_ref(bo); + return 0; +} + +static int cs_begin(struct radeon_cs *cs, + uint32_t ndw, + const char *file, + const char *func, + int line) +{ + if (cs->section) { + fprintf(stderr, "CS already in a section(%s,%s,%d)\n", + cs->section_file, cs->section_func, cs->section_line); + fprintf(stderr, "CS can't start section(%s,%s,%d)\n", + file, func, line); + return -EPIPE; + } + cs->section = 1; + cs->section_ndw = ndw; + cs->section_cdw = 0; + cs->section_file = file; + cs->section_func = func; + cs->section_line = line; + return 0; +} + +static int cs_end(struct radeon_cs *cs, + const char *file, + const char *func, + int line) + +{ + if (!cs->section) { + fprintf(stderr, "CS no section to end at (%s,%s,%d)\n", + file, func, line); + return -EPIPE; + } + cs->section = 0; + if (cs->section_ndw != cs->section_cdw) { + fprintf(stderr, "CS section size missmatch start at (%s,%s,%d)\n", + cs->section_file, cs->section_func, cs->section_line); + fprintf(stderr, "CS section end at (%s,%s,%d)\n", + file, func, line); + return -EPIPE; + } + return 0; +} + +static int cs_emit(struct radeon_cs *cs) +{ + return 0; +} + +static int cs_destroy(struct radeon_cs *cs) +{ + free(cs->relocs); + free(cs->packets); + free(cs); + return 0; +} + +static int cs_erase(struct radeon_cs *cs) +{ + cs->relocs_total_size = 0; + cs->relocs = NULL; + cs->crelocs = 0; + cs->cdw = 0; + cs->section = 0; + return 0; +} + +static int cs_need_flush(struct radeon_cs *cs) +{ + return (cs->relocs_total_size > (7*1024*1024)); +} + +struct radeon_cs_funcs radeon_cs_funcs = { + cs_create, + cs_write_dword, + cs_write_reloc, + cs_begin, + cs_end, + cs_emit, + cs_destroy, + cs_erase, + cs_need_flush +}; + +struct radeon_cs_manager *radeon_cs_manager_gem(int fd) +{ + struct radeon_cs_manager *csm; + + csm = (struct radeon_cs_manager*)calloc(1, + sizeof(struct radeon_cs_manager)); + if (csm == NULL) { + return NULL; + } + csm->funcs = &radeon_cs_funcs; + csm->fd = fd; + return csm; +} + +void radeon_cs_manager_gem_shutdown(struct radeon_cs_manager *csm) +{ + free(csm); +} diff --git a/libdrm/radeon/radeon_cs_gem.h b/libdrm/radeon/radeon_cs_gem.h new file mode 100644 index 00000000..a032a8cc --- /dev/null +++ b/libdrm/radeon/radeon_cs_gem.h @@ -0,0 +1,40 @@ +/* + * Copyright © 2008 Nicolai Haehnle + * Copyright © 2008 Jérôme Glisse + * 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, sub license, 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 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Aapo Tahkola + * Nicolai Haehnle + * Jérôme Glisse + */ +#ifndef RADEON_CS_GEM_H +#define RADEON_CS_GEM_H + +#include "radeon_cs.h" + +struct radeon_cs_manager *radeon_cs_manager_gem(int fd); +void radeon_cs_manager_gem_shutdown(struct radeon_cs_manager *csm); + +#endif -- cgit v1.2.3 From 751d024dd5c91831a8141810c0f40ecdb235e7ca Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Sun, 9 Nov 2008 18:45:43 +0100 Subject: libdrm-radeon: update libdrm-radeon to match current CS relocation structures --- libdrm/radeon/radeon_bo.h | 17 ++--- libdrm/radeon/radeon_bo_gem.c | 19 ++--- libdrm/radeon/radeon_bo_gem.h | 17 ++--- libdrm/radeon/radeon_cs_gem.c | 162 +++++++++++++++++++++++++++--------------- libdrm/radeon/radeon_cs_gem.h | 17 ++--- 5 files changed, 143 insertions(+), 89 deletions(-) (limited to 'libdrm') diff --git a/libdrm/radeon/radeon_bo.h b/libdrm/radeon/radeon_bo.h index a0739265..f884e0fa 100644 --- a/libdrm/radeon/radeon_bo.h +++ b/libdrm/radeon/radeon_bo.h @@ -2,20 +2,21 @@ * Copyright © 2008 Jérôme Glisse * All Rights Reserved. * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the + * 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, sub license, 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 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 NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS 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 + * 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 + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * 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. * * The above copyright notice and this permission notice (including the diff --git a/libdrm/radeon/radeon_bo_gem.c b/libdrm/radeon/radeon_bo_gem.c index 04e36c59..fc198711 100644 --- a/libdrm/radeon/radeon_bo_gem.c +++ b/libdrm/radeon/radeon_bo_gem.c @@ -3,20 +3,21 @@ * Copyright © 2008 Jérôme Glisse * All Rights Reserved. * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the + * 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, sub license, 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 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 NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS 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 + * 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 + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * 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. * * The above copyright notice and this permission notice (including the @@ -102,6 +103,7 @@ static struct radeon_bo *bo_open(struct radeon_bo_manager *bom, return NULL; } } + radeon_bo_ref(bo); return (struct radeon_bo*)bo; } @@ -118,7 +120,6 @@ static void bo_unref(struct radeon_bo *bo) return; } if (bo->cref) { - /* FIXME: what to do ? */ return; } if (bo_gem->map_count) { diff --git a/libdrm/radeon/radeon_bo_gem.h b/libdrm/radeon/radeon_bo_gem.h index d0997614..aaefd8c3 100644 --- a/libdrm/radeon/radeon_bo_gem.h +++ b/libdrm/radeon/radeon_bo_gem.h @@ -3,20 +3,21 @@ * Copyright © 2008 Jérôme Glisse * All Rights Reserved. * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the + * 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, sub license, 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 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 NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS 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 + * 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 + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * 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. * * The above copyright notice and this permission notice (including the diff --git a/libdrm/radeon/radeon_cs_gem.c b/libdrm/radeon/radeon_cs_gem.c index 7ed5780b..00aa9086 100644 --- a/libdrm/radeon/radeon_cs_gem.c +++ b/libdrm/radeon/radeon_cs_gem.c @@ -2,20 +2,21 @@ * Copyright © 2008 Jérôme Glisse * All Rights Reserved. * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the + * 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, sub license, 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 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 NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS 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 + * 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 + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * 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. * * The above copyright notice and this permission notice (including the @@ -24,22 +25,27 @@ */ /* * Authors: + * Aapo Tahkola + * Nicolai Haehnle * Jérôme Glisse */ #include #include +#include +#include #include "radeon_cs.h" #include "radeon_cs_gem.h" #include "radeon_bo_gem.h" #include "drm.h" +#include "xf86drm.h" #include "radeon_drm.h" #pragma pack(1) struct cs_reloc_gem { uint32_t handle; - uint32_t domains; - uint32_t soffset; - uint32_t eoffset; + uint32_t rdomain; + uint32_t wdomain; + uint32_t cnt; }; #pragma pack() @@ -49,6 +55,7 @@ struct cs_gem { struct drm_radeon_cs_chunk chunks[2]; unsigned nrelocs; uint32_t *relocs; + struct radeon_bo **relocs_bo; }; static struct radeon_cs *cs_create(struct radeon_cs_manager *csm, @@ -74,8 +81,16 @@ static struct radeon_cs *cs_create(struct radeon_cs_manager *csm, csg->base.relocs_total_size = 0; csg->base.crelocs = 0; csg->nrelocs = 4096 / (4 * 4) ; + csg->relocs_bo = (struct radeon_bo**)calloc(1, + csg->nrelocs*sizeof(void*)); + if (csg->relocs_bo == NULL) { + free(csg->base.packets); + free(csg); + return NULL; + } csg->base.relocs = csg->relocs = (uint32_t*)calloc(1, 4096); if (csg->relocs == NULL) { + free(csg->relocs_bo); free(csg->base.packets); free(csg); return NULL; @@ -91,6 +106,7 @@ static struct radeon_cs *cs_create(struct radeon_cs_manager *csm, static int cs_write_dword(struct radeon_cs *cs, uint32_t dword) { + struct cs_gem *csg = (struct cs_gem*)cs; if (cs->cdw >= cs->ndw) { uint32_t tmp, *ptr; tmp = (cs->cdw + 1 + 0x3FF) & (~0x3FF); @@ -100,11 +116,10 @@ static int cs_write_dword(struct radeon_cs *cs, uint32_t dword) } cs->packets = ptr; cs->ndw = tmp; + csg->chunks[0].chunk_data = (uint64_t)(intptr_t)csg->base.packets; } cs->packets[cs->cdw++] = dword; - if (cs->section) { - cs->section_cdw++; - } + csg->chunks[0].length_dw += 1; return 0; } @@ -116,6 +131,7 @@ static int cs_write_reloc(struct radeon_cs *cs, { struct cs_gem *csg = (struct cs_gem*)cs; struct cs_reloc_gem *reloc; + uint32_t idx; unsigned i; /* check reloc window */ @@ -127,38 +143,73 @@ static int cs_write_reloc(struct radeon_cs *cs, } /* check if bo is already referenced */ for(i = 0; i < cs->crelocs; i++) { - reloc = (struct cs_reloc_gem*)&csg->relocs[i * 4]; + idx = i * 4; + reloc = (struct cs_reloc_gem*)&csg->relocs[idx]; if (reloc->handle == bo->handle) { /* update start offset and size */ - if (eoffset > reloc->eoffset) { - reloc->eoffset = eoffset; + switch (bo->domains) { + case RADEON_GEM_DOMAIN_VRAM: + reloc->rdomain = 0; + reloc->wdomain = RADEON_GEM_DOMAIN_VRAM; + break; + case RADEON_GEM_DOMAIN_GTT: + reloc->rdomain = RADEON_GEM_DOMAIN_GTT; + reloc->wdomain = 0; + break; + default: + exit(0); + break; } - if (soffset < reloc->soffset) { - reloc->soffset = soffset; - } - reloc->domains |= domains; + reloc->cnt++; + cs_write_dword(cs, 0xc0001000); + cs_write_dword(cs, idx); return 0; } } /* add bo */ if (csg->base.crelocs >= csg->nrelocs) { uint32_t *tmp, size; - size = (csg->nrelocs * 4 * 4) + (4096 / (4 * 4)); + size = ((csg->nrelocs + 1) * sizeof(struct radeon_bo*)); + tmp = (uint32_t*)realloc(csg->relocs_bo, size); + if (tmp == NULL) { + return -ENOMEM; + } + csg->relocs_bo = (struct radeon_bo**)tmp; + size = ((csg->nrelocs + 1) * 4 * 4); tmp = (uint32_t*)realloc(csg->relocs, size); if (tmp == NULL) { return -ENOMEM; } cs->relocs = csg->relocs = tmp; - csg->nrelocs = size / (4 * 4); + csg->nrelocs += 1; + csg->chunks[1].chunk_data = (uint64_t)(intptr_t)csg->relocs; } - reloc = (struct cs_reloc_gem*)&csg->relocs[csg->base.crelocs * 4]; + csg->relocs_bo[csg->base.crelocs] = bo; + idx = (csg->base.crelocs++) * 4; + reloc = (struct cs_reloc_gem*)&csg->relocs[idx]; reloc->handle = bo->handle; - reloc->soffset = soffset; - reloc->eoffset = eoffset; - reloc->domains = domains; - cs->crelocs++; + reloc->rdomain = bo->domains; + reloc->wdomain = bo->domains; + switch (bo->domains) { + case RADEON_GEM_DOMAIN_VRAM: + reloc->rdomain = 0; + reloc->wdomain = RADEON_GEM_DOMAIN_VRAM; + break; + case RADEON_GEM_DOMAIN_GTT: + reloc->rdomain = RADEON_GEM_DOMAIN_GTT; + reloc->wdomain = 0; + break; + default: + exit(0); + break; + } + reloc->cnt = 1; + csg->chunks[1].length_dw += 4; radeon_bo_ref(bo); + cs->relocs_total_size += bo->size; + cs_write_dword(cs, 0xc0001000); + cs_write_dword(cs, idx); return 0; } @@ -168,19 +219,6 @@ static int cs_begin(struct radeon_cs *cs, const char *func, int line) { - if (cs->section) { - fprintf(stderr, "CS already in a section(%s,%s,%d)\n", - cs->section_file, cs->section_func, cs->section_line); - fprintf(stderr, "CS can't start section(%s,%s,%d)\n", - file, func, line); - return -EPIPE; - } - cs->section = 1; - cs->section_ndw = ndw; - cs->section_cdw = 0; - cs->section_file = file; - cs->section_func = func; - cs->section_line = line; return 0; } @@ -190,29 +228,38 @@ static int cs_end(struct radeon_cs *cs, int line) { - if (!cs->section) { - fprintf(stderr, "CS no section to end at (%s,%s,%d)\n", - file, func, line); - return -EPIPE; - } cs->section = 0; - if (cs->section_ndw != cs->section_cdw) { - fprintf(stderr, "CS section size missmatch start at (%s,%s,%d)\n", - cs->section_file, cs->section_func, cs->section_line); - fprintf(stderr, "CS section end at (%s,%s,%d)\n", - file, func, line); - return -EPIPE; - } return 0; } static int cs_emit(struct radeon_cs *cs) { + struct cs_gem *csg = (struct cs_gem*)cs; + uint64_t chunk_array[2]; + int r; + + chunk_array[0] = (uint64_t)(intptr_t)&csg->chunks[0]; + chunk_array[1] = (uint64_t)(intptr_t)&csg->chunks[1]; + + csg->cs.num_chunks = 2; + csg->cs.chunks = (uint64_t)(intptr_t)chunk_array; + + r = drmCommandWriteRead(cs->csm->fd, DRM_RADEON_CS2, + &csg->cs, sizeof(struct drm_radeon_cs2)); + if (r) { + return r; + } + for(i = 0; i < cs->crelocs; i++) { + radeon_bo_unref(csg->relocs_bo[i]); + } return 0; } static int cs_destroy(struct radeon_cs *cs) { + struct cs_gem *csg = (struct cs_gem*)cs; + + free(csg->relocs_bo); free(cs->relocs); free(cs->packets); free(cs); @@ -221,17 +268,20 @@ static int cs_destroy(struct radeon_cs *cs) static int cs_erase(struct radeon_cs *cs) { + struct cs_gem *csg = (struct cs_gem*)cs; + cs->relocs_total_size = 0; - cs->relocs = NULL; - cs->crelocs = 0; cs->cdw = 0; cs->section = 0; + cs->crelocs = 0; + csg->chunks[0].length_dw = 0; + csg->chunks[1].length_dw = 0; return 0; } static int cs_need_flush(struct radeon_cs *cs) { - return (cs->relocs_total_size > (7*1024*1024)); + return (cs->relocs_total_size > (16*1024*1024)); } struct radeon_cs_funcs radeon_cs_funcs = { diff --git a/libdrm/radeon/radeon_cs_gem.h b/libdrm/radeon/radeon_cs_gem.h index a032a8cc..f50c5e84 100644 --- a/libdrm/radeon/radeon_cs_gem.h +++ b/libdrm/radeon/radeon_cs_gem.h @@ -3,20 +3,21 @@ * Copyright © 2008 Jérôme Glisse * All Rights Reserved. * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the + * 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, sub license, 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 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 NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS 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 + * 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 + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * 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. * * The above copyright notice and this permission notice (including the -- cgit v1.2.3 From 72997fb3726b99b99c44e96e59abd8c70abbd8be Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Mon, 10 Nov 2008 22:18:22 +0100 Subject: libdrm-radeon: be verbose on bo failure and cleanup cs a bit --- libdrm/radeon/radeon_bo_gem.c | 11 +++++-- libdrm/radeon/radeon_cs_gem.c | 75 +++++++++++++++++++++---------------------- 2 files changed, 44 insertions(+), 42 deletions(-) (limited to 'libdrm') diff --git a/libdrm/radeon/radeon_bo_gem.c b/libdrm/radeon/radeon_bo_gem.c index fc198711..8ce82919 100644 --- a/libdrm/radeon/radeon_bo_gem.c +++ b/libdrm/radeon/radeon_bo_gem.c @@ -99,11 +99,15 @@ static struct radeon_bo *bo_open(struct radeon_bo_manager *bom, &args, sizeof(args)); bo->base.handle = args.handle; if (r) { + fprintf(stderr, "Failed to allocate :\n"); + fprintf(stderr, " size : %d bytes\n", size); + fprintf(stderr, " alignment : %d bytes\n", alignment); + fprintf(stderr, " domains : %d\n", bo->base.domains); free(bo); return NULL; } } - radeon_bo_ref(bo); + radeon_bo_ref((struct radeon_bo*)bo); return (struct radeon_bo*)bo; } @@ -137,7 +141,6 @@ static int bo_map(struct radeon_bo *bo, int write) struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo; struct drm_radeon_gem_mmap args; int r; - uint8_t *tt; if (bo_gem->map_count++ != 0) { return 0; @@ -152,8 +155,10 @@ static int bo_map(struct radeon_bo *bo, int write) sizeof(args)); if (!r) { bo->ptr = (void *)(unsigned long)args.addr_ptr; + } else { + fprintf(stderr, "error mapping %p 0x%08X (error = %d)\n", + bo, bo->handle, r); } - tt = bo->ptr; return r; } diff --git a/libdrm/radeon/radeon_cs_gem.c b/libdrm/radeon/radeon_cs_gem.c index 00aa9086..6be1728f 100644 --- a/libdrm/radeon/radeon_cs_gem.c +++ b/libdrm/radeon/radeon_cs_gem.c @@ -58,8 +58,8 @@ struct cs_gem { struct radeon_bo **relocs_bo; }; -static struct radeon_cs *cs_create(struct radeon_cs_manager *csm, - uint32_t ndw) +static struct radeon_cs *cs_gem_create(struct radeon_cs_manager *csm, + uint32_t ndw) { struct cs_gem *csg; @@ -104,7 +104,7 @@ static struct radeon_cs *cs_create(struct radeon_cs_manager *csm, return (struct radeon_cs*)csg; } -static int cs_write_dword(struct radeon_cs *cs, uint32_t dword) +static int cs_gem_write_dword(struct radeon_cs *cs, uint32_t dword) { struct cs_gem *csg = (struct cs_gem*)cs; if (cs->cdw >= cs->ndw) { @@ -123,11 +123,11 @@ static int cs_write_dword(struct radeon_cs *cs, uint32_t dword) return 0; } -static int cs_write_reloc(struct radeon_cs *cs, - struct radeon_bo *bo, - uint32_t soffset, - uint32_t eoffset, - uint32_t domains) +static int cs_gem_write_reloc(struct radeon_cs *cs, + struct radeon_bo *bo, + uint32_t soffset, + uint32_t eoffset, + uint32_t domains) { struct cs_gem *csg = (struct cs_gem*)cs; struct cs_reloc_gem *reloc; @@ -162,8 +162,8 @@ static int cs_write_reloc(struct radeon_cs *cs, break; } reloc->cnt++; - cs_write_dword(cs, 0xc0001000); - cs_write_dword(cs, idx); + cs_gem_write_dword(cs, 0xc0001000); + cs_gem_write_dword(cs, idx); return 0; } } @@ -208,31 +208,31 @@ static int cs_write_reloc(struct radeon_cs *cs, csg->chunks[1].length_dw += 4; radeon_bo_ref(bo); cs->relocs_total_size += bo->size; - cs_write_dword(cs, 0xc0001000); - cs_write_dword(cs, idx); + cs_gem_write_dword(cs, 0xc0001000); + cs_gem_write_dword(cs, idx); return 0; } -static int cs_begin(struct radeon_cs *cs, - uint32_t ndw, - const char *file, - const char *func, - int line) +static int cs_gem_begin(struct radeon_cs *cs, + uint32_t ndw, + const char *file, + const char *func, + int line) { return 0; } -static int cs_end(struct radeon_cs *cs, - const char *file, - const char *func, - int line) +static int cs_gem_end(struct radeon_cs *cs, + const char *file, + const char *func, + int line) { cs->section = 0; return 0; } -static int cs_emit(struct radeon_cs *cs) +static int cs_gem_emit(struct radeon_cs *cs) { struct cs_gem *csg = (struct cs_gem*)cs; uint64_t chunk_array[2]; @@ -249,13 +249,10 @@ static int cs_emit(struct radeon_cs *cs) if (r) { return r; } - for(i = 0; i < cs->crelocs; i++) { - radeon_bo_unref(csg->relocs_bo[i]); - } return 0; } -static int cs_destroy(struct radeon_cs *cs) +static int cs_gem_destroy(struct radeon_cs *cs) { struct cs_gem *csg = (struct cs_gem*)cs; @@ -266,7 +263,7 @@ static int cs_destroy(struct radeon_cs *cs) return 0; } -static int cs_erase(struct radeon_cs *cs) +static int cs_gem_erase(struct radeon_cs *cs) { struct cs_gem *csg = (struct cs_gem*)cs; @@ -279,21 +276,21 @@ static int cs_erase(struct radeon_cs *cs) return 0; } -static int cs_need_flush(struct radeon_cs *cs) +static int cs_gem_need_flush(struct radeon_cs *cs) { return (cs->relocs_total_size > (16*1024*1024)); } -struct radeon_cs_funcs radeon_cs_funcs = { - cs_create, - cs_write_dword, - cs_write_reloc, - cs_begin, - cs_end, - cs_emit, - cs_destroy, - cs_erase, - cs_need_flush +static struct radeon_cs_funcs radeon_cs_gem_funcs = { + cs_gem_create, + cs_gem_write_dword, + cs_gem_write_reloc, + cs_gem_begin, + cs_gem_end, + cs_gem_emit, + cs_gem_destroy, + cs_gem_erase, + cs_gem_need_flush }; struct radeon_cs_manager *radeon_cs_manager_gem(int fd) @@ -305,7 +302,7 @@ struct radeon_cs_manager *radeon_cs_manager_gem(int fd) if (csm == NULL) { return NULL; } - csm->funcs = &radeon_cs_funcs; + csm->funcs = &radeon_cs_gem_funcs; csm->fd = fd; return csm; } -- cgit v1.2.3 From a7457915f5775137436f3b16a640eb8bd6424ca6 Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Wed, 12 Nov 2008 15:56:40 +0100 Subject: radeon+libdrm-radeon: change relocation informations Relocation now consist of the following informations (in this order) : handle buffer object handle identifier start_offset start offset of first data of the buffer object used by the cs end_offset end offset of last data of the buffer object used by the cs read_domain read domain (either VRAM, or GTT as GPU is invalid for CS) write_domain write domain (either VRAM, or GTT as GPU is invalid for CS) flags flags used for further optimization (like discard previous buffer content or forget buffer content after cs which can help in avoiding moving content in or out) --- libdrm/radeon/Makefile.am | 2 +- libdrm/radeon/radeon_cs.h | 33 +++++++++----- libdrm/radeon/radeon_cs_gem.c | 103 ++++++++++++++++++++++++------------------ 3 files changed, 82 insertions(+), 56 deletions(-) (limited to 'libdrm') diff --git a/libdrm/radeon/Makefile.am b/libdrm/radeon/Makefile.am index cc4951a9..d15a266b 100644 --- a/libdrm/radeon/Makefile.am +++ b/libdrm/radeon/Makefile.am @@ -29,7 +29,7 @@ AM_CFLAGS = \ $(PTHREADSTUBS_CFLAGS) \ -I$(top_srcdir)/shared-core -libdrm_radeon_la_LTLIBRARIES = libdrm_radeon.la +libdrm_radeon_la_LTLIBRARIES = libdrm-radeon.la libdrm_radeon_ladir = $(libdir) libdrm_radeon_la_LDFLAGS = -version-number 1:0:0 -no-undefined libdrm_radeon_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@ diff --git a/libdrm/radeon/radeon_cs.h b/libdrm/radeon/radeon_cs.h index 347e9f35..63f104b6 100644 --- a/libdrm/radeon/radeon_cs.h +++ b/libdrm/radeon/radeon_cs.h @@ -37,10 +37,11 @@ struct radeon_cs_reloc { struct radeon_bo *bo; - uint32_t soffset; - uint32_t eoffset; - uint32_t size; - uint32_t domains; + uint32_t start_offset; + uint32_t end_offset; + uint32_t read_domain; + uint32_t write_domain; + uint32_t flags; }; struct radeon_cs_manager; @@ -68,9 +69,11 @@ struct radeon_cs_funcs { int (*cs_write_dword)(struct radeon_cs *cs, uint32_t dword); int (*cs_write_reloc)(struct radeon_cs *cs, struct radeon_bo *bo, - uint32_t soffset, - uint32_t eoffset, - uint32_t domains); + uint32_t start_offset, + uint32_t end_offset, + uint32_t read_domain, + uint32_t write_domain, + uint32_t flags); int (*cs_begin)(struct radeon_cs *cs, uint32_t ndw, const char *file, @@ -104,11 +107,19 @@ static inline int radeon_cs_write_dword(struct radeon_cs *cs, uint32_t dword) static inline int radeon_cs_write_reloc(struct radeon_cs *cs, struct radeon_bo *bo, - uint32_t soffset, - uint32_t eoffset, - uint32_t domains) + uint32_t start_offset, + uint32_t end_offset, + uint32_t read_domain, + uint32_t write_domain, + uint32_t flags) { - return cs->csm->funcs->cs_write_reloc(cs, bo, soffset, eoffset, domains); + return cs->csm->funcs->cs_write_reloc(cs, + bo, + start_offset, + end_offset, + read_domain, + write_domain, + flags); } static inline int radeon_cs_begin(struct radeon_cs *cs, diff --git a/libdrm/radeon/radeon_cs_gem.c b/libdrm/radeon/radeon_cs_gem.c index 6be1728f..f9c9fabb 100644 --- a/libdrm/radeon/radeon_cs_gem.c +++ b/libdrm/radeon/radeon_cs_gem.c @@ -43,9 +43,11 @@ #pragma pack(1) struct cs_reloc_gem { uint32_t handle; - uint32_t rdomain; - uint32_t wdomain; - uint32_t cnt; + uint32_t start_offset; + uint32_t end_offset; + uint32_t read_domain; + uint32_t write_domain; + uint32_t flags; }; #pragma pack() @@ -125,50 +127,74 @@ static int cs_gem_write_dword(struct radeon_cs *cs, uint32_t dword) static int cs_gem_write_reloc(struct radeon_cs *cs, struct radeon_bo *bo, - uint32_t soffset, - uint32_t eoffset, - uint32_t domains) + uint32_t start_offset, + uint32_t end_offset, + uint32_t read_domain, + uint32_t write_domain, + uint32_t flags) { struct cs_gem *csg = (struct cs_gem*)cs; struct cs_reloc_gem *reloc; uint32_t idx; unsigned i; + /* check domains */ + if ((read_domain && write_domain) || (!read_domain && !write_domain)) { + /* in one CS a bo can only be in read or write domain but not + * in read & write domain at the same sime + */ + return -EINVAL; + } + if (read_domain == RADEON_GEM_DOMAIN_CPU) { + return -EINVAL; + } + if (write_domain == RADEON_GEM_DOMAIN_CPU) { + return -EINVAL; + } /* check reloc window */ - if (eoffset > bo->size) { + if (end_offset > bo->size) { return -EINVAL; } - if (soffset > eoffset) { + if (start_offset > end_offset) { return -EINVAL; } /* check if bo is already referenced */ for(i = 0; i < cs->crelocs; i++) { - idx = i * 4; + idx = i * 6; reloc = (struct cs_reloc_gem*)&csg->relocs[idx]; - if (reloc->handle == bo->handle) { - /* update start offset and size */ - switch (bo->domains) { - case RADEON_GEM_DOMAIN_VRAM: - reloc->rdomain = 0; - reloc->wdomain = RADEON_GEM_DOMAIN_VRAM; - break; - case RADEON_GEM_DOMAIN_GTT: - reloc->rdomain = RADEON_GEM_DOMAIN_GTT; - reloc->wdomain = 0; - break; - default: - exit(0); - break; + /* Check domains must be in read or write. As we check already + * checked that in argument one of the read or write domain was + * set we only need to check that if previous reloc as the read + * domain set then the read_domain should also be set for this + * new relocation. + */ + if (reloc->read_domain && !read_domain) { + return -EINVAL; + } + if (reloc->write_domain && !write_domain) { + return -EINVAL; + } + reloc->read_domain |= read_domain; + reloc->write_domain |= write_domain; + /* update start and end offset */ + if (start_offset < reloc->start_offset) { + reloc->start_offset = start_offset; } - reloc->cnt++; + if (end_offset > reloc->end_offset) { + reloc->end_offset = end_offset; + } + /* update flags */ + reloc->flags |= (flags & reloc->flags); + /* write relocation packet */ cs_gem_write_dword(cs, 0xc0001000); cs_gem_write_dword(cs, idx); return 0; } } - /* add bo */ + /* new relocation */ if (csg->base.crelocs >= csg->nrelocs) { + /* allocate more memory (TODO: should use a slab allocatore maybe) */ uint32_t *tmp, size; size = ((csg->nrelocs + 1) * sizeof(struct radeon_bo*)); tmp = (uint32_t*)realloc(csg->relocs_bo, size); @@ -176,7 +202,7 @@ static int cs_gem_write_reloc(struct radeon_cs *cs, return -ENOMEM; } csg->relocs_bo = (struct radeon_bo**)tmp; - size = ((csg->nrelocs + 1) * 4 * 4); + size = ((csg->nrelocs + 1) * 6 * 4); tmp = (uint32_t*)realloc(csg->relocs, size); if (tmp == NULL) { return -ENOMEM; @@ -186,26 +212,15 @@ static int cs_gem_write_reloc(struct radeon_cs *cs, csg->chunks[1].chunk_data = (uint64_t)(intptr_t)csg->relocs; } csg->relocs_bo[csg->base.crelocs] = bo; - idx = (csg->base.crelocs++) * 4; + idx = (csg->base.crelocs++) * 6; reloc = (struct cs_reloc_gem*)&csg->relocs[idx]; reloc->handle = bo->handle; - reloc->rdomain = bo->domains; - reloc->wdomain = bo->domains; - switch (bo->domains) { - case RADEON_GEM_DOMAIN_VRAM: - reloc->rdomain = 0; - reloc->wdomain = RADEON_GEM_DOMAIN_VRAM; - break; - case RADEON_GEM_DOMAIN_GTT: - reloc->rdomain = RADEON_GEM_DOMAIN_GTT; - reloc->wdomain = 0; - break; - default: - exit(0); - break; - } - reloc->cnt = 1; - csg->chunks[1].length_dw += 4; + reloc->start_offset = start_offset; + reloc->end_offset = end_offset; + reloc->read_domain = read_domain; + reloc->write_domain = write_domain; + reloc->flags = flags; + csg->chunks[1].length_dw += 6; radeon_bo_ref(bo); cs->relocs_total_size += bo->size; cs_gem_write_dword(cs, 0xc0001000); -- cgit v1.2.3 From 1ead45c8f02e7c51cfe977383726d20479385688 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 12 Nov 2008 18:40:04 +0100 Subject: mode: Remove hotplug support from ioctl interface --- libdrm/xf86drmMode.c | 9 --------- libdrm/xf86drmMode.h | 5 ----- 2 files changed, 14 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index a25b11bb..38fdbc11 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -183,15 +183,6 @@ err_allocs: return r; } -uint32_t drmModeGetHotplug(int fd) -{ - struct drm_mode_hotplug arg; - arg.counter = 0; - - ioctl(fd, DRM_IOCTL_MODE_HOTPLUG, &arg); - return arg.counter; -} - int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, uint8_t bpp, uint32_t pitch, uint32_t bo_handle, uint32_t *buf_id) diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index 59612a94..ee45717b 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -158,11 +158,6 @@ extern void drmModeFreeEncoder( drmModeEncoderPtr ptr ); */ extern drmModeResPtr drmModeGetResources(int fd); -/** - * Retrives the hotplug counter - */ -extern uint32_t drmModeGetHotplug(int fd); - /* * FrameBuffer manipulation. */ -- cgit v1.2.3 From ea849d7ca6aaedd3aba6ec7239f01426521d8604 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 12 Nov 2008 18:49:46 +0100 Subject: mode: Unify userspace API to uint_t --- libdrm/xf86drmMode.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.h b/libdrm/xf86drmMode.h index ee45717b..b68d1469 100644 --- a/libdrm/xf86drmMode.h +++ b/libdrm/xf86drmMode.h @@ -77,8 +77,8 @@ typedef struct _drmModePropertyBlob { } drmModePropertyBlobRes, *drmModePropertyBlobPtr; typedef struct _drmModeProperty { - unsigned int prop_id; - unsigned int flags; + uint32_t prop_id; + uint32_t flags; char name[DRM_PROP_NAME_LEN]; int count_values; uint64_t *values; // store the blob lengths @@ -89,8 +89,8 @@ typedef struct _drmModeProperty { } drmModePropertyRes, *drmModePropertyPtr; typedef struct _drmModeCrtc { - unsigned int crtc_id; - unsigned int buffer_id; /**< FB id to connect to 0 = disconnect */ + uint32_t crtc_id; + uint32_t buffer_id; /**< FB id to connect to 0 = disconnect */ uint32_t x, y; /**< Position on the framebuffer */ uint32_t width, height; @@ -102,9 +102,9 @@ typedef struct _drmModeCrtc { } drmModeCrtc, *drmModeCrtcPtr; typedef struct _drmModeEncoder { - unsigned int encoder_id; - unsigned int encoder_type; - unsigned int crtc_id; + uint32_t encoder_id; + uint32_t encoder_type; + uint32_t crtc_id; uint32_t possible_crtcs; uint32_t possible_clones; } drmModeEncoder, *drmModeEncoderPtr; @@ -125,10 +125,10 @@ typedef enum { } drmModeSubPixel; typedef struct _drmModeConnector { - unsigned int connector_id; - unsigned int encoder_id; /**< Encoder currently connected to */ - unsigned int connector_type; - unsigned int connector_type_id; + uint32_t connector_id; + uint32_t encoder_id; /**< Encoder currently connected to */ + uint32_t connector_type; + uint32_t connector_type_id; drmModeConnection connection; uint32_t mmWidth, mmHeight; /**< HxW in millimeters */ drmModeSubPixel subpixel; -- cgit v1.2.3 From 9a4cb7eab4f74747cc777a3fef31dbb46e1191e5 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 12 Nov 2008 19:17:18 +0100 Subject: mode: Minor reodering and renaming --- libdrm/xf86drmMode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libdrm') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 38fdbc11..a0a164de 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -200,7 +200,7 @@ int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, if ((ret = ioctl(fd, DRM_IOCTL_MODE_ADDFB, &f))) return ret; - *buf_id = f.buffer_id; + *buf_id = f.fb_id; return 0; } @@ -216,7 +216,7 @@ drmModeFBPtr drmModeGetFB(int fd, uint32_t buf) struct drm_mode_fb_cmd info; drmModeFBPtr r; - info.buffer_id = buf; + info.fb_id = buf; if (ioctl(fd, DRM_IOCTL_MODE_GETFB, &info)) return NULL; @@ -224,7 +224,7 @@ drmModeFBPtr drmModeGetFB(int fd, uint32_t buf) if (!(r = drmMalloc(sizeof(*r)))) return NULL; - r->buffer_id = info.buffer_id; + r->fb_id = info.fb_id; r->width = info.width; r->height = info.height; r->pitch = info.pitch; @@ -639,7 +639,7 @@ int drmModeReplaceFB(int fd, uint32_t buffer_id, f.bpp = bpp; f.depth = depth; f.handle = bo_handle; - f.buffer_id = buffer_id; + f.fb_id = buffer_id; if ((ret = ioctl(fd, DRM_IOCTL_MODE_REPLACEFB, &f))) return ret; -- cgit v1.2.3 From bfbecc5c42d9669fceaab683d1464dd353be9492 Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Fri, 14 Nov 2008 12:08:27 +0100 Subject: libdrm-radeon: new tracker tools To keep record of bo activities and print them when necessary, should help in tracking unbalanced ref/unref calls. --- libdrm/radeon/Makefile.am | 6 +- libdrm/radeon/radeon_bo.h | 29 +++++---- libdrm/radeon/radeon_track.c | 139 +++++++++++++++++++++++++++++++++++++++++++ libdrm/radeon/radeon_track.h | 64 ++++++++++++++++++++ 4 files changed, 224 insertions(+), 14 deletions(-) create mode 100644 libdrm/radeon/radeon_track.c create mode 100644 libdrm/radeon/radeon_track.h (limited to 'libdrm') diff --git a/libdrm/radeon/Makefile.am b/libdrm/radeon/Makefile.am index d15a266b..39ee021f 100644 --- a/libdrm/radeon/Makefile.am +++ b/libdrm/radeon/Makefile.am @@ -36,11 +36,13 @@ libdrm_radeon_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@ libdrm_radeon_la_SOURCES = \ radeon_bo_gem.c \ - radeon_cs_gem.c + radeon_cs_gem.c \ + radeon_track.c libdrm_radeonincludedir = ${includedir}/drm libdrm_radeoninclude_HEADERS = \ radeon_bo.h \ radeon_cs.h \ radeon_bo_gem.h \ - radeon_cs_gem.h + radeon_cs_gem.h \ + radeon_track.h diff --git a/libdrm/radeon/radeon_bo.h b/libdrm/radeon/radeon_bo.h index f884e0fa..ed785034 100644 --- a/libdrm/radeon/radeon_bo.h +++ b/libdrm/radeon/radeon_bo.h @@ -32,6 +32,7 @@ #include #include +#include "radeon_track.h" /* bo object */ #define RADEON_BO_FLAGS_MACRO_TILE 1 @@ -46,6 +47,9 @@ struct radeon_bo { uint32_t domains; uint32_t flags; unsigned cref; +#ifdef RADEON_BO_TRACK + struct radeon_track *track; +#endif void *ptr; struct radeon_bo_manager *bom; }; @@ -67,6 +71,7 @@ struct radeon_bo_funcs { struct radeon_bo_manager { struct radeon_bo_funcs *funcs; int fd; + struct radeon_tracker tracker; }; static inline void _radeon_bo_debug(struct radeon_bo *bo, @@ -90,10 +95,12 @@ static inline struct radeon_bo *_radeon_bo_open(struct radeon_bo_manager *bom, int line) { struct radeon_bo *bo; + bo = bom->funcs->bo_open(bom, handle, size, alignment, domains, flags); -#ifdef RADEON_BO_TRACK_OPEN +#ifdef RADEON_BO_TRACK if (bo) { - _radeon_bo_debug(bo, 1, file, func, line); + bo->track = radeon_tracker_add_track(&bom->tracker, bo->handle); + radeon_track_add_event(bo->track, file, func, "open", line); } #endif return bo; @@ -105,8 +112,8 @@ static inline void _radeon_bo_ref(struct radeon_bo *bo, int line) { bo->cref++; -#ifdef RADEON_BO_TRACK_REF - _radeon_bo_debug(bo, 2, file, func, line); +#ifdef RADEON_BO_TRACK + radeon_track_add_event(bo->track, file, func, "ref", line); #endif bo->bom->funcs->bo_ref(bo); } @@ -117,8 +124,12 @@ static inline void _radeon_bo_unref(struct radeon_bo *bo, int line) { bo->cref--; -#ifdef RADEON_BO_TRACK_REF - _radeon_bo_debug(bo, 3, file, func, line); +#ifdef RADEON_BO_TRACK + radeon_track_add_event(bo->track, file, func, "unref", line); + if (bo->cref <= 0) { + radeon_tracker_remove_track(&bo->bom->tracker, bo->track); + bo->track = NULL; + } #endif bo->bom->funcs->bo_unref(bo); } @@ -129,9 +140,6 @@ static inline int _radeon_bo_map(struct radeon_bo *bo, const char *func, int line) { -#ifdef RADEON_BO_TRACK_MAP - _radeon_bo_debug(bo, 4, file, func, line); -#endif return bo->bom->funcs->bo_map(bo, write); } @@ -140,9 +148,6 @@ static inline int _radeon_bo_unmap(struct radeon_bo *bo, const char *func, int line) { -#ifdef RADEON_BO_TRACK_MAP - _radeon_bo_debug(bo, 5, file, func, line); -#endif return bo->bom->funcs->bo_unmap(bo); } diff --git a/libdrm/radeon/radeon_track.c b/libdrm/radeon/radeon_track.c new file mode 100644 index 00000000..c0c6f850 --- /dev/null +++ b/libdrm/radeon/radeon_track.c @@ -0,0 +1,139 @@ +/* + * Copyright © 2008 Jérôme Glisse + * 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, sub license, 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 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 + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Jérôme Glisse + */ +#include +#include +#include +#include "radeon_track.h" + +void radeon_track_add_event(struct radeon_track *track, + const char *file, + const char *func, + const char *op, + unsigned line) +{ + struct radeon_track_event *event; + + if (track == NULL) { + return; + } + event = (void*)calloc(1,sizeof(struct radeon_track_event)); + if (event == NULL) { + return; + } + event->line = line; + event->file = strdup(file); + event->func = strdup(func); + event->op = strdup(op); + if (event->file == NULL || event->func == NULL || event->op == NULL) { + free(event->file); + free(event->func); + free(event->op); + free(event); + return; + } + event->next = track->events; + track->events = event; +} + +struct radeon_track *radeon_tracker_add_track(struct radeon_tracker *tracker, + unsigned key) +{ + struct radeon_track *track; + + track = (struct radeon_track*)calloc(1, sizeof(struct radeon_track)); + if (track) { + track->next = tracker->tracks.next; + track->prev = &tracker->tracks; + tracker->tracks.next = track; + if (track->next) { + track->next->prev = track; + } + track->key = key; + track->events = NULL; + } + return track; +} + +void radeon_tracker_remove_track(struct radeon_tracker *tracker, + struct radeon_track *track) +{ + struct radeon_track_event *event; + void *tmp; + + if (track == NULL) { + return; + } + track->prev->next = track->next; + if (track->next) { + track->next->prev = track->prev; + } + event = track->events; + while (event) { + tmp = event; + free(event->file); + free(event->func); + free(event->op); + event = event->next; + free(tmp); + } + track->events = NULL; + free(track); +} + +void radeon_tracker_print(struct radeon_tracker *tracker, FILE *file) +{ + struct radeon_track *track; + struct radeon_track_event *event; + void *tmp; + + track = tracker->tracks.next; + while (track) { + event = track->events; + fprintf(file, "[0x%08X] :\n", track->key); + while (event) { + tmp = event; + fprintf(file, " [0x%08X:%s](%s:%s:%d)\n", + track->key, event->op, event->file, + event->func, event->line); + free(event->file); + free(event->func); + free(event->op); + event->file = NULL; + event->func = NULL; + event->op = NULL; + event = event->next; + free(tmp); + } + track->events = NULL; + tmp = track; + track = track->next; + free(tmp); + } +} diff --git a/libdrm/radeon/radeon_track.h b/libdrm/radeon/radeon_track.h new file mode 100644 index 00000000..838d1f38 --- /dev/null +++ b/libdrm/radeon/radeon_track.h @@ -0,0 +1,64 @@ +/* + * Copyright © 2008 Jérôme Glisse + * 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, sub license, 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 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 + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Jérôme Glisse + */ +#ifndef RADEON_TRACK_H +#define RADEON_TRACK_H + +struct radeon_track_event { + struct radeon_track_event *next; + char *file; + char *func; + char *op; + unsigned line; +}; + +struct radeon_track { + struct radeon_track *next; + struct radeon_track *prev; + unsigned key; + struct radeon_track_event *events; +}; + +struct radeon_tracker { + struct radeon_track tracks; +}; + +void radeon_track_add_event(struct radeon_track *track, + const char *file, + const char *func, + const char *op, + unsigned line); +struct radeon_track *radeon_tracker_add_track(struct radeon_tracker *tracker, + unsigned key); +void radeon_tracker_remove_track(struct radeon_tracker *tracker, + struct radeon_track *track); +void radeon_tracker_print(struct radeon_tracker *tracker, + FILE *file); + +#endif -- cgit v1.2.3 From 080a45624b2b0ac9e0173f5b93760ae018394dd1 Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Fri, 14 Nov 2008 12:13:53 +0100 Subject: libdrm-radeon: unreference buffer once cs stream is submited or on cs clean BO are referenced once by reloc to make sure that they not destroyed before we get a chance to flush the cmd stream, so we need to unreference them once in cs submit or cs erase if cs i never submitted so bo can be destructed. --- libdrm/radeon/radeon_cs_gem.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'libdrm') diff --git a/libdrm/radeon/radeon_cs_gem.c b/libdrm/radeon/radeon_cs_gem.c index f9c9fabb..9488f81c 100644 --- a/libdrm/radeon/radeon_cs_gem.c +++ b/libdrm/radeon/radeon_cs_gem.c @@ -251,7 +251,7 @@ static int cs_gem_emit(struct radeon_cs *cs) { struct cs_gem *csg = (struct cs_gem*)cs; uint64_t chunk_array[2]; - int r; + int r, i; chunk_array[0] = (uint64_t)(intptr_t)&csg->chunks[0]; chunk_array[1] = (uint64_t)(intptr_t)&csg->chunks[1]; @@ -261,10 +261,11 @@ static int cs_gem_emit(struct radeon_cs *cs) r = drmCommandWriteRead(cs->csm->fd, DRM_RADEON_CS2, &csg->cs, sizeof(struct drm_radeon_cs2)); - if (r) { - return r; + for (i = 0; i < csg->base.crelocs; i++) { + radeon_bo_unref(csg->relocs_bo[i]); + csg->relocs_bo[i] = NULL; } - return 0; + return r; } static int cs_gem_destroy(struct radeon_cs *cs) @@ -281,7 +282,16 @@ static int cs_gem_destroy(struct radeon_cs *cs) static int cs_gem_erase(struct radeon_cs *cs) { struct cs_gem *csg = (struct cs_gem*)cs; + int i; + if (csg->relocs_bo) { + for (i = 0; i < csg->base.crelocs; i++) { + if (csg->relocs_bo[i]) { + radeon_bo_unref(csg->relocs_bo[i]); + csg->relocs_bo[i] = NULL; + } + } + } cs->relocs_total_size = 0; cs->cdw = 0; cs->section = 0; -- cgit v1.2.3 From 5ae79e7edd819b84d9e447a2ab9b995a862ac3a7 Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Sat, 15 Nov 2008 10:38:44 +0100 Subject: libdrm-radeon: unref return current BO ptr to reflect BO destruction --- libdrm/radeon/radeon_bo.h | 12 ++++++------ libdrm/radeon/radeon_bo_gem.c | 11 ++++++----- libdrm/radeon/radeon_bo_gem.h | 4 ++-- libdrm/radeon/radeon_cs_gem.c | 9 +++++---- libdrm/radeon/radeon_cs_gem.h | 4 ++-- 5 files changed, 21 insertions(+), 19 deletions(-) (limited to 'libdrm') diff --git a/libdrm/radeon/radeon_bo.h b/libdrm/radeon/radeon_bo.h index ed785034..523cf38e 100644 --- a/libdrm/radeon/radeon_bo.h +++ b/libdrm/radeon/radeon_bo.h @@ -63,7 +63,7 @@ struct radeon_bo_funcs { uint32_t domains, uint32_t flags); void (*bo_ref)(struct radeon_bo *bo); - void (*bo_unref)(struct radeon_bo *bo); + struct radeon_bo *(*bo_unref)(struct radeon_bo *bo); int (*bo_map)(struct radeon_bo *bo, int write); int (*bo_unmap)(struct radeon_bo *bo); }; @@ -118,10 +118,10 @@ static inline void _radeon_bo_ref(struct radeon_bo *bo, bo->bom->funcs->bo_ref(bo); } -static inline void _radeon_bo_unref(struct radeon_bo *bo, - const char *file, - const char *func, - int line) +static inline struct radeon_bo *_radeon_bo_unref(struct radeon_bo *bo, + const char *file, + const char *func, + int line) { bo->cref--; #ifdef RADEON_BO_TRACK @@ -131,7 +131,7 @@ static inline void _radeon_bo_unref(struct radeon_bo *bo, bo->track = NULL; } #endif - bo->bom->funcs->bo_unref(bo); + return bo->bom->funcs->bo_unref(bo); } static inline int _radeon_bo_map(struct radeon_bo *bo, diff --git a/libdrm/radeon/radeon_bo_gem.c b/libdrm/radeon/radeon_bo_gem.c index 8ce82919..b6d5b294 100644 --- a/libdrm/radeon/radeon_bo_gem.c +++ b/libdrm/radeon/radeon_bo_gem.c @@ -115,16 +115,16 @@ static void bo_ref(struct radeon_bo *bo) { } -static void bo_unref(struct radeon_bo *bo) +static struct radeon_bo *bo_unref(struct radeon_bo *bo) { struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo; struct drm_gem_close args; if (bo == NULL) { - return; + return NULL; } if (bo->cref) { - return; + return bo; } if (bo_gem->map_count) { munmap(bo->ptr, bo->size); @@ -134,6 +134,7 @@ static void bo_unref(struct radeon_bo *bo) args.handle = bo->handle; ioctl(bo->bom->fd, DRM_IOCTL_GEM_CLOSE, &args); free(bo_gem); + return NULL; } static int bo_map(struct radeon_bo *bo, int write) @@ -182,7 +183,7 @@ static struct radeon_bo_funcs bo_gem_funcs = { bo_unmap }; -struct radeon_bo_manager *radeon_bo_manager_gem(int fd) +struct radeon_bo_manager *radeon_bo_manager_gem_ctor(int fd) { struct bo_manager_gem *bomg; @@ -195,7 +196,7 @@ struct radeon_bo_manager *radeon_bo_manager_gem(int fd) return (struct radeon_bo_manager*)bomg; } -void radeon_bo_manager_gem_shutdown(struct radeon_bo_manager *bom) +void radeon_bo_manager_gem_dtor(struct radeon_bo_manager *bom) { struct bo_manager_gem *bomg = (struct bo_manager_gem*)bom; diff --git a/libdrm/radeon/radeon_bo_gem.h b/libdrm/radeon/radeon_bo_gem.h index aaefd8c3..c0f68e6d 100644 --- a/libdrm/radeon/radeon_bo_gem.h +++ b/libdrm/radeon/radeon_bo_gem.h @@ -34,7 +34,7 @@ #include "radeon_bo.h" -struct radeon_bo_manager *radeon_bo_manager_gem(int fd); -void radeon_bo_manager_gem_shutdown(struct radeon_bo_manager *bom); +struct radeon_bo_manager *radeon_bo_manager_gem_ctor(int fd); +void radeon_bo_manager_gem_dtor(struct radeon_bo_manager *bom); #endif diff --git a/libdrm/radeon/radeon_cs_gem.c b/libdrm/radeon/radeon_cs_gem.c index 9488f81c..91489dff 100644 --- a/libdrm/radeon/radeon_cs_gem.c +++ b/libdrm/radeon/radeon_cs_gem.c @@ -251,7 +251,8 @@ static int cs_gem_emit(struct radeon_cs *cs) { struct cs_gem *csg = (struct cs_gem*)cs; uint64_t chunk_array[2]; - int r, i; + unsigned i; + int r; chunk_array[0] = (uint64_t)(intptr_t)&csg->chunks[0]; chunk_array[1] = (uint64_t)(intptr_t)&csg->chunks[1]; @@ -282,7 +283,7 @@ static int cs_gem_destroy(struct radeon_cs *cs) static int cs_gem_erase(struct radeon_cs *cs) { struct cs_gem *csg = (struct cs_gem*)cs; - int i; + unsigned i; if (csg->relocs_bo) { for (i = 0; i < csg->base.crelocs; i++) { @@ -318,7 +319,7 @@ static struct radeon_cs_funcs radeon_cs_gem_funcs = { cs_gem_need_flush }; -struct radeon_cs_manager *radeon_cs_manager_gem(int fd) +struct radeon_cs_manager *radeon_cs_manager_gem_ctor(int fd) { struct radeon_cs_manager *csm; @@ -332,7 +333,7 @@ struct radeon_cs_manager *radeon_cs_manager_gem(int fd) return csm; } -void radeon_cs_manager_gem_shutdown(struct radeon_cs_manager *csm) +void radeon_cs_manager_gem_dtor(struct radeon_cs_manager *csm) { free(csm); } diff --git a/libdrm/radeon/radeon_cs_gem.h b/libdrm/radeon/radeon_cs_gem.h index f50c5e84..5efd146f 100644 --- a/libdrm/radeon/radeon_cs_gem.h +++ b/libdrm/radeon/radeon_cs_gem.h @@ -35,7 +35,7 @@ #include "radeon_cs.h" -struct radeon_cs_manager *radeon_cs_manager_gem(int fd); -void radeon_cs_manager_gem_shutdown(struct radeon_cs_manager *csm); +struct radeon_cs_manager *radeon_cs_manager_gem_ctor(int fd); +void radeon_cs_manager_gem_dtor(struct radeon_cs_manager *csm); #endif -- cgit v1.2.3 From c0ba14fd90e7495d5634c1ce0a9fb5be26230010 Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Sun, 16 Nov 2008 18:04:43 +0100 Subject: libdrm-radeon: add print callback to cs & small fixes --- libdrm/radeon/radeon_bo.h | 6 +-- libdrm/radeon/radeon_bo_gem.c | 3 +- libdrm/radeon/radeon_cs.h | 6 +++ libdrm/radeon/radeon_cs_gem.c | 103 +++++++++++++++++++++++++++++++++++++++++- libdrm/radeon/radeon_track.c | 1 + 5 files changed, 113 insertions(+), 6 deletions(-) (limited to 'libdrm') diff --git a/libdrm/radeon/radeon_bo.h b/libdrm/radeon/radeon_bo.h index 523cf38e..44dc0901 100644 --- a/libdrm/radeon/radeon_bo.h +++ b/libdrm/radeon/radeon_bo.h @@ -75,13 +75,13 @@ struct radeon_bo_manager { }; static inline void _radeon_bo_debug(struct radeon_bo *bo, - int opcode, + const char *op, const char *file, const char *func, int line) { - fprintf(stderr, "%02d %p 0x%08X 0x%08X 0x%08X [%s %s %d]\n", - opcode, bo, bo->handle, bo->size, bo->cref, file, func, line); + fprintf(stderr, "%s %p 0x%08X 0x%08X 0x%08X [%s %s %d]\n", + op, bo, bo->handle, bo->size, bo->cref, file, func, line); } static inline struct radeon_bo *_radeon_bo_open(struct radeon_bo_manager *bom, diff --git a/libdrm/radeon/radeon_bo_gem.c b/libdrm/radeon/radeon_bo_gem.c index b6d5b294..fdf852a2 100644 --- a/libdrm/radeon/radeon_bo_gem.c +++ b/libdrm/radeon/radeon_bo_gem.c @@ -81,7 +81,6 @@ static struct radeon_bo *bo_open(struct radeon_bo_manager *bom, open_arg.name = handle; r = ioctl(bom->fd, DRM_IOCTL_GEM_OPEN, &open_arg); if (r != 0) { - fprintf(stderr, "GEM open failed: %d (%s)\n",r,strerror(r)); free(bo); return NULL; } @@ -95,6 +94,7 @@ static struct radeon_bo *bo_open(struct radeon_bo_manager *bom, args.alignment = alignment; args.initial_domain = bo->base.domains; args.no_backing_store = 0; + args.handle = 0; r = drmCommandWriteRead(bom->fd, DRM_RADEON_GEM_CREATE, &args, sizeof(args)); bo->base.handle = args.handle; @@ -133,6 +133,7 @@ static struct radeon_bo *bo_unref(struct radeon_bo *bo) /* close object */ args.handle = bo->handle; ioctl(bo->bom->fd, DRM_IOCTL_GEM_CLOSE, &args); + memset(bo_gem, 0, sizeof(struct radeon_bo_gem)); free(bo_gem); return NULL; } diff --git a/libdrm/radeon/radeon_cs.h b/libdrm/radeon/radeon_cs.h index 63f104b6..e76121ea 100644 --- a/libdrm/radeon/radeon_cs.h +++ b/libdrm/radeon/radeon_cs.h @@ -87,6 +87,7 @@ struct radeon_cs_funcs { int (*cs_destroy)(struct radeon_cs *cs); int (*cs_erase)(struct radeon_cs *cs); int (*cs_need_flush)(struct radeon_cs *cs); + void (*cs_print)(struct radeon_cs *cs, FILE *file); }; struct radeon_cs_manager { @@ -159,4 +160,9 @@ static inline int radeon_cs_need_flush(struct radeon_cs *cs) return cs->csm->funcs->cs_need_flush(cs); } +static inline void radeon_cs_print(struct radeon_cs *cs, FILE *file) +{ + cs->csm->funcs->cs_print(cs, file); +} + #endif diff --git a/libdrm/radeon/radeon_cs_gem.c b/libdrm/radeon/radeon_cs_gem.c index 91489dff..319d1b9e 100644 --- a/libdrm/radeon/radeon_cs_gem.c +++ b/libdrm/radeon/radeon_cs_gem.c @@ -254,6 +254,8 @@ static int cs_gem_emit(struct radeon_cs *cs) unsigned i; int r; + csg->chunks[0].length_dw = cs->cdw; + chunk_array[0] = (uint64_t)(intptr_t)&csg->chunks[0]; chunk_array[1] = (uint64_t)(intptr_t)&csg->chunks[1]; @@ -304,7 +306,103 @@ static int cs_gem_erase(struct radeon_cs *cs) static int cs_gem_need_flush(struct radeon_cs *cs) { - return (cs->relocs_total_size > (16*1024*1024)); + return (cs->relocs_total_size > (32*1024*1024)); +} + +#define PACKET_TYPE0 0 +#define PACKET_TYPE1 1 +#define PACKET_TYPE2 2 +#define PACKET_TYPE3 3 + +#define PACKET3_NOP 0x10 +#define PACKET3_SET_SCISSORS 0x1E +#define PACKET3_3D_DRAW_VBUF 0x28 +#define PACKET3_3D_DRAW_IMMD 0x29 +#define PACKET3_3D_DRAW_INDX 0x2A +#define PACKET3_3D_LOAD_VBPNTR 0x2F +#define PACKET3_INDX_BUFFER 0x33 +#define PACKET3_3D_DRAW_VBUF_2 0x34 +#define PACKET3_3D_DRAW_IMMD_2 0x35 +#define PACKET3_3D_DRAW_INDX_2 0x36 + +#define CP_PACKET_GET_TYPE(h) (((h) >> 30) & 3) +#define CP_PACKET_GET_COUNT(h) (((h) >> 16) & 0x3FFF) +#define CP_PACKET0_GET_REG(h) (((h) & 0x1FFF) << 2) +#define CP_PACKET0_GET_ONE_REG_WR(h) (((h) >> 15) & 1) +#define CP_PACKET3_GET_OPCODE(h) (((h) >> 8) & 0xFF) + +static void cs_gem_print(struct radeon_cs *cs, FILE *file) +{ + unsigned opcode; + unsigned reg; + unsigned cnt; + int i, j; + + for (i = 0; i < cs->cdw;) { + cnt = CP_PACKET_GET_COUNT(cs->packets[i]); + switch (CP_PACKET_GET_TYPE(cs->packets[i])) { + case PACKET_TYPE0: + fprintf(file, "Pkt0 at %d (%d dwords):\n", i, cnt + 1); + reg = CP_PACKET0_GET_REG(cs->packets[i]); + if (CP_PACKET0_GET_ONE_REG_WR(cs->packets[i++])) { + for (j = 0; j <= cnt; j++) { + fprintf(file, " 0x%08X -> 0x%04X\n", + cs->packets[i++], reg); + } + } else { + for (j = 0; j <= cnt; j++) { + fprintf(file, " 0x%08X -> 0x%04X\n", + cs->packets[i++], reg); + reg += 4; + } + } + break; + case PACKET_TYPE3: + fprintf(file, "Pkt3 at %d :\n", i); + opcode = CP_PACKET3_GET_OPCODE(cs->packets[i++]); + switch (opcode) { + case PACKET3_NOP: + fprintf(file, " PACKET3_NOP:\n"); + break; + case PACKET3_3D_DRAW_VBUF: + fprintf(file, " PACKET3_3D_DRAW_VBUF:\n"); + break; + case PACKET3_3D_DRAW_IMMD: + fprintf(file, " PACKET3_3D_DRAW_IMMD:\n"); + break; + case PACKET3_3D_DRAW_INDX: + fprintf(file, " PACKET3_3D_DRAW_INDX:\n"); + break; + case PACKET3_3D_LOAD_VBPNTR: + fprintf(file, " PACKET3_3D_LOAD_VBPNTR:\n"); + break; + case PACKET3_INDX_BUFFER: + fprintf(file, " PACKET3_INDX_BUFFER:\n"); + break; + case PACKET3_3D_DRAW_VBUF_2: + fprintf(file, " PACKET3_3D_DRAW_VBUF_2:\n"); + break; + case PACKET3_3D_DRAW_IMMD_2: + fprintf(file, " PACKET3_3D_DRAW_IMMD_2:\n"); + break; + case PACKET3_3D_DRAW_INDX_2: + fprintf(file, " PACKET3_3D_DRAW_INDX_2:\n"); + break; + default: + fprintf(file, "Unknow opcode 0x%02X at %d\n", opcode, i); + return; + } + for (j = 0; j <= cnt; j++) { + fprintf(file, " 0x%08X\n", cs->packets[i++]); + } + break; + case PACKET_TYPE1: + case PACKET_TYPE2: + default: + fprintf(file, "Unknow packet 0x%08X at %d\n", cs->packets[i], i); + return; + } + } } static struct radeon_cs_funcs radeon_cs_gem_funcs = { @@ -316,7 +414,8 @@ static struct radeon_cs_funcs radeon_cs_gem_funcs = { cs_gem_emit, cs_gem_destroy, cs_gem_erase, - cs_gem_need_flush + cs_gem_need_flush, + cs_gem_print }; struct radeon_cs_manager *radeon_cs_manager_gem_ctor(int fd) diff --git a/libdrm/radeon/radeon_track.c b/libdrm/radeon/radeon_track.c index c0c6f850..1623906f 100644 --- a/libdrm/radeon/radeon_track.c +++ b/libdrm/radeon/radeon_track.c @@ -94,6 +94,7 @@ void radeon_tracker_remove_track(struct radeon_tracker *tracker, if (track->next) { track->next->prev = track->prev; } + track->next = track->prev = NULL; event = track->events; while (event) { tmp = event; -- cgit v1.2.3 From 60c1e3a09e33bfaec893c1d4780553b9b344293a Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Wed, 19 Nov 2008 10:56:48 -0800 Subject: libdrm_intel: fix merge error don't take the lock twice --- libdrm/intel/intel_bufmgr_gem.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'libdrm') diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c index 8b8cda62..64d32d38 100644 --- a/libdrm/intel/intel_bufmgr_gem.c +++ b/libdrm/intel/intel_bufmgr_gem.c @@ -809,8 +809,6 @@ drm_intel_gem_bo_emit_reloc(drm_intel_bo *bo, uint32_t offset, pthread_mutex_lock(&bufmgr_gem->lock); - pthread_mutex_lock(&bufmgr_gem->lock); - /* Create a new relocation list if needed */ if (bo_gem->relocs == NULL) drm_intel_setup_reloc_list(bo); -- cgit v1.2.3