diff --git a/src/drmmode_display.c b/src/drmmode_display.c index 52a41e8..ec2760d 100644 --- a/src/drmmode_display.c +++ b/src/drmmode_display.c @@ -32,14 +32,21 @@ #ifdef XF86DRM_MODE #include "i830.h" -static Bool drmmode_resize_fb(ScrnInfoPtr scrn, drmmode_ptr drmmode, int width, int height); + +/* + * Core X outputs approximately correspond to DRM connectors. + */ + +static Bool drmmode_resize_fb(ScrnInfoPtr scrn, struct drm_mode * drmmode, + int width, int height); static Bool drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height) { xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - drmmode_crtc_private_ptr drmmode_crtc = xf86_config->crtc[0]->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; + struct drm_crtc_private *drmmode_crtc = + xf86_config->crtc[0]->driver_private; + struct drm_mode * drmmode = drmmode_crtc->drmmode; Bool ret; ErrorF("resize called %d %d\n", width, height); @@ -50,9 +57,8 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height) } static void -drmmode_ConvertFromKMode(ScrnInfoPtr scrn, - struct drm_mode_modeinfo *kmode, - DisplayModePtr mode) +drmmode_ConvertFromKMode(ScrnInfoPtr scrn, struct drm_mode_modeinfo *kmode, + DisplayModePtr mode) { memset(mode, 0, sizeof(DisplayModeRec)); mode->status = MODE_OK; @@ -82,9 +88,8 @@ drmmode_ConvertFromKMode(ScrnInfoPtr scrn, } static void -drmmode_ConvertToKMode(ScrnInfoPtr scrn, - struct drm_mode_modeinfo *kmode, - DisplayModePtr mode) +drmmode_ConvertToKMode(ScrnInfoPtr scrn, struct drm_mode_modeinfo *kmode, + DisplayModePtr mode) { memset(kmode, 0, sizeof(*kmode)); @@ -120,15 +125,15 @@ drmmode_crtc_dpms(xf86CrtcPtr drmmode_crtc, int mode) static Bool drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode, - Rotation rotation, int x, int y) + Rotation rotation, int x, int y) { - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); + struct drm_crtc_private *crtc_priv = crtc->driver_private; + struct drm_mode *drmmode = crtc_priv->drmmode; int saved_x, saved_y; Rotation saved_rotation; DisplayModeRec saved_mode; - uint32_t *output_ids; + uint32_t *connector_ids; int output_count = 0; int ret = TRUE; int i; @@ -145,37 +150,37 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode, crtc->y = y; crtc->rotation = rotation; - output_ids = xcalloc(sizeof(uint32_t), xf86_config->num_output); - if (!output_ids) { + connector_ids = xcalloc(sizeof(uint32_t), xf86_config->num_output); + if (!connector_ids) { ret = FALSE; goto done; } + /* Find the X outputs for this crtc so we can get the connector info */ for (i = 0; i < xf86_config->num_output; i++) { xf86OutputPtr output = xf86_config->output[i]; - drmmode_output_private_ptr drmmode_output; + struct drm_connector_private *connector_priv; if (output->crtc != crtc) continue; - drmmode_output = output->driver_private; - output_ids[output_count] = drmmode_output->mode_output->output_id; + connector_priv = output->driver_private; + connector_ids[output_count] = + connector_priv->mode_connector->connector_id; output_count++; } - if (!xf86CrtcRotate(crtc, mode, rotation)) { + if (!xf86CrtcRotate(crtc, mode, rotation)) goto done; - } drmmode_ConvertToKMode(crtc->scrn, &kmode, mode); - fb_id = drmmode->fb_id; - if (drmmode_crtc->rotate_fb_id) - fb_id = drmmode_crtc->rotate_fb_id; + if (crtc_priv->rotate_fb_id) + fb_id = crtc_priv->rotate_fb_id; ErrorF("fb id is %d\n", fb_id); - drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, - fb_id, x, y, output_ids, output_count, &kmode); + drmModeSetCrtc(drmmode->fd, crtc_priv->mode_crtc->crtc_id, + fb_id, x, y, connector_ids, output_count, &kmode); done: @@ -189,30 +194,28 @@ done: } static void -drmmode_set_cursor_colors (xf86CrtcPtr crtc, int bg, int fg) +drmmode_set_cursor_colors(xf86CrtcPtr crtc, int bg, int fg) { - } static void -drmmode_set_cursor_position (xf86CrtcPtr crtc, int x, int y) +drmmode_set_cursor_position(xf86CrtcPtr crtc, int x, int y) { - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; + struct drm_crtc_private *drmmode_crtc = crtc->driver_private; + struct drm_mode *drmmode = drmmode_crtc->drmmode; drmModeMoveCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, x, y); } static void -drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image) +drmmode_load_cursor_argb(xf86CrtcPtr crtc, CARD32 *image) { - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - + struct drm_crtc_private *drmmode_crtc = crtc->driver_private; + struct drm_mode *drmmode = drmmode_crtc->drmmode; int ret; void *ptr; - /* need to map the cursor here */ - + + /* need to map the cursor here */ ret = drmBOMap(drmmode->fd, &drmmode_crtc->cursor_bo, DRM_BO_FLAG_WRITE, DRM_BO_HINT_DONT_FENCE, &ptr); @@ -222,7 +225,7 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image) return; } - memcpy (ptr, image, 64 * 64 * 4); + memcpy(ptr, image, 64 * 64 * 4); drmBOUnmap(drmmode->fd, &drmmode_crtc->cursor_bo); return; @@ -230,29 +233,31 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image) static void -drmmode_hide_cursor (xf86CrtcPtr crtc) +drmmode_hide_cursor(xf86CrtcPtr crtc) { - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; + struct drm_crtc_private *drmmode_crtc = crtc->driver_private; + struct drm_mode *drmmode = drmmode_crtc->drmmode; - drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0, I810_CURSOR_X, I810_CURSOR_Y); - + drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0, + I810_CURSOR_X, I810_CURSOR_Y); } static void -drmmode_show_cursor (xf86CrtcPtr crtc) +drmmode_show_cursor(xf86CrtcPtr crtc) { - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; + struct drm_crtc_private *drmmode_crtc = crtc->driver_private; + struct drm_mode *drmmode = drmmode_crtc->drmmode; - drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, drmmode_crtc->cursor_bo.handle, I810_CURSOR_X, I810_CURSOR_Y); + drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, + drmmode_crtc->cursor_bo.handle, I810_CURSOR_X, + I810_CURSOR_Y); } static void * drmmode_crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height) { - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; + struct drm_crtc_private *drmmode_crtc = crtc->driver_private; + struct drm_mode *drmmode = drmmode_crtc->drmmode; int ret; int size; unsigned long rotate_pitch; @@ -261,20 +266,29 @@ drmmode_crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height) size = rotate_pitch * height; drmmode_crtc->rotate_bo = dri_bo_alloc(drmmode->bufmgr, "rotate", - size, 4096, DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_CACHED | DRM_BO_FLAG_CACHED_MAPPED); + size, 4096, + DRM_BO_FLAG_MEM_TT | + DRM_BO_FLAG_CACHED | + DRM_BO_FLAG_CACHED_MAPPED); if (!drmmode_crtc->rotate_bo) { xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR, - "Couldn't allocate shadow memory for rotated CRTC\n"); + "Failed to allocate rotation buffer\n"); return NULL; } dri_bo_map(drmmode_crtc->rotate_bo, 1); ret = drmModeAddFB(drmmode->fd, width, height, crtc->scrn->depth, - crtc->scrn->bitsPerPixel, rotate_pitch, dri_bo_get_handle(drmmode_crtc->rotate_bo), &drmmode_crtc->rotate_fb_id); + crtc->scrn->bitsPerPixel, rotate_pitch, + dri_bo_get_handle(drmmode_crtc->rotate_bo), + &drmmode_crtc->rotate_fb_id); + if (ret) { ErrorF("failed to add rotate fb\n"); + drm_bo_unreference(drmmode_crtc->rotate_bo); + drmmode_crtc->rotate_bo = NULL; + return NULL; } return drmmode_crtc->rotate_bo->virtual; @@ -284,48 +298,49 @@ static PixmapPtr drmmode_crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height) { ScrnInfoPtr pScrn = crtc->scrn; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; + struct drm_crtc_private * drmmode_crtc = crtc->driver_private; + struct drm_mode * drmmode = drmmode_crtc->drmmode; unsigned long rotate_pitch; PixmapPtr rotate_pixmap; if (!data) - data = drmmode_crtc_shadow_allocate (crtc, width, height); + data = drmmode_crtc_shadow_allocate(crtc, width, height); + if (!data) + return NULL; rotate_pitch = pScrn->displayWidth * drmmode->cpp; - rotate_pixmap = GetScratchPixmapHeader(pScrn->pScreen, width, height, pScrn->depth, pScrn->bitsPerPixel, rotate_pitch, data); - - if (rotate_pixmap == NULL) { + if (!rotate_pixmap) xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "Couldn't allocate shadow pixmap for rotated CRTC\n"); - } + "Failed to allocate rotation pixmap\n"); + return rotate_pixmap; } static void -drmmode_crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data) +drmmode_crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, + void *data) { - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; + struct drm_crtc_private *drmmode_crtc = crtc->driver_private; + struct drm_mode *drmmode = drmmode_crtc->drmmode; if (rotate_pixmap) - FreeScratchPixmapHeader(rotate_pixmap); + FreeScratchPixmapHeader(rotate_pixmap); - if (data) { - /* Be sure to sync acceleration before the memory gets unbound. */ - drmModeRmFB(drmmode->fd, drmmode_crtc->rotate_fb_id); - drmmode_crtc->rotate_fb_id = 0; - dri_bo_unreference(drmmode_crtc->rotate_bo); - drmmode_crtc->rotate_bo = NULL; - } + if (!data) + return; + /* Be sure to sync acceleration before the memory gets unbound. */ + drmModeRmFB(drmmode->fd, drmmode_crtc->rotate_fb_id); + drmmode_crtc->rotate_fb_id = 0; + dri_bo_unreference(drmmode_crtc->rotate_bo); + drmmode_crtc->rotate_bo = NULL; } static const xf86CrtcFuncsRec drmmode_crtc_funcs = { @@ -352,48 +367,48 @@ static const xf86CrtcFuncsRec drmmode_crtc_funcs = { static void -drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num) +drmmode_crtc_init(ScrnInfoPtr pScrn, struct drm_mode *drmmode, int num) { xf86CrtcPtr crtc; - drmmode_crtc_private_ptr drmmode_crtc; + struct drm_crtc_private *drmmode_crtc; int cursor_size = 64 * 64 * 4; uint32_t mask; int ret; crtc = xf86CrtcCreate(pScrn, &drmmode_crtc_funcs); - if (crtc == NULL) + if (!crtc) return; drmmode_crtc = xnfcalloc(sizeof(drmmode_crtc_private_rec), 1); - drmmode_crtc->mode_crtc = drmModeGetCrtc(drmmode->fd, drmmode->mode_res->crtcs[num]); + drmmode_crtc->mode_crtc = drmModeGetCrtc(drmmode->fd, + drmmode->mode_res->crtcs[num]); drmmode_crtc->drmmode = drmmode; crtc->driver_private = drmmode_crtc; /* allocate cursor BO for this crtc */ mask = DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MAPPABLE | DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_NO_EVICT; - ret = drmBOCreate(drmmode->fd, cursor_size, 0, NULL, - mask, 0, &drmmode_crtc->cursor_bo); - - if (ret) { + ret = drmBOCreate(drmmode->fd, cursor_size, 0, NULL, mask, 0, + &drmmode_crtc->cursor_bo); + if (ret) ErrorF("failed to allocate cursor for crtc %d\n", ret); - return; - } + return; } static xf86OutputStatus -drmmode_output_detect(xf86OutputPtr output) +drmmode_encoder_detect(xf86OutputPtr output) { - /* go to the hw and retrieve a new output struct */ - drmmode_output_private_ptr drmmode_output = output->driver_private; - drmmode_ptr drmmode = drmmode_output->drmmode; + struct drm_connector_private *encoder_priv = output->driver_private; + struct drm_mode *drmmode = encoder_priv->drmmode; xf86OutputStatus status; - drmModeFreeOutput(drmmode_output->mode_output); - - drmmode_output->mode_output = drmModeGetOutput(drmmode->fd, drmmode_output->output_id); + drmModeFreeOutput(encoder_priv->mode_output); + + /* go to the hw and retrieve a new output struct */ + encoder_priv->mode_output = + drmModeGetOutput(drmmode->fd, encoder_priv->output_id); - switch (drmmode_output->mode_output->connection) { + switch (encoder_priv->mode_output->connection) { case DRM_MODE_CONNECTED: status = XF86OutputStatusConnected; break; @@ -417,9 +432,9 @@ drmmode_output_mode_valid(xf86OutputPtr output, DisplayModePtr pModes) static DisplayModePtr drmmode_output_get_modes(xf86OutputPtr output) { - drmmode_output_private_ptr drmmode_output = output->driver_private; + struct drm_connector_private * drmmode_output = output->driver_private; drmModeOutputPtr koutput = drmmode_output->mode_output; - drmmode_ptr drmmode = drmmode_output->drmmode; + struct drm_mode * drmmode = drmmode_output->drmmode; int i; DisplayModePtr Modes = NULL, Mode; drmModePropertyPtr props; @@ -456,7 +471,7 @@ drmmode_output_get_modes(xf86OutputPtr output) static void drmmode_output_destroy(xf86OutputPtr output) { - drmmode_output_private_ptr drmmode_output = output->driver_private; + struct drm_connector_private * drmmode_output = output->driver_private; if (drmmode_output->edid_blob) drmModeFreePropertyBlob(drmmode_output->edid_blob); @@ -503,11 +518,11 @@ const char *output_names[] = { "None", "TV" }; static void -drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num) +drmmode_output_init(ScrnInfoPtr pScrn, struct drm_mode * drmmode, int num) { xf86OutputPtr output; drmModeOutputPtr koutput; - drmmode_output_private_ptr drmmode_output; + struct drm_connector_private * drmmode_output; char name[32]; koutput = drmModeGetOutput(drmmode->fd, drmmode->mode_res->outputs[num]); @@ -538,7 +553,7 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num) return; } -Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, char *busId, char *driver_name, int cpp) +Bool drmmode_pre_init(ScrnInfoPtr pScrn, struct drm_mode * drmmode, char *busId, char *driver_name, int cpp) { xf86CrtcConfigPtr xf86_config; int i; @@ -576,13 +591,13 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, char *busId, char return TRUE; } -Bool drmmode_set_bufmgr(ScrnInfoPtr pScrn, drmmode_ptr drmmode, dri_bufmgr *bufmgr) +Bool drmmode_set_bufmgr(ScrnInfoPtr pScrn, struct drm_mode * drmmode, dri_bufmgr *bufmgr) { drmmode->bufmgr = bufmgr; return TRUE; } -void drmmode_set_fb(ScrnInfoPtr scrn, drmmode_ptr drmmode, int width, int height, int pitch, drmBO *bo) +void drmmode_set_fb(ScrnInfoPtr scrn, struct drm_mode * drmmode, int width, int height, int pitch, drmBO *bo) { int ret; @@ -608,7 +623,7 @@ Bool drmmode_is_rotate_pixmap(ScrnInfoPtr pScrn, pointer pPixData, dri_bo **bo) for (i = 0; i < config->num_crtc; i++) { xf86CrtcPtr crtc = config->crtc[i]; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + struct drm_crtc_private *drmmode_crtc = crtc->driver_private; if (!drmmode_crtc->rotate_bo) continue; @@ -619,10 +634,9 @@ Bool drmmode_is_rotate_pixmap(ScrnInfoPtr pScrn, pointer pPixData, dri_bo **bo) } } return FALSE; - } -static Bool drmmode_resize_fb(ScrnInfoPtr scrn, drmmode_ptr drmmode, int width, int height) +static Bool drmmode_resize_fb(ScrnInfoPtr scrn, struct drm_mode * drmmode, int width, int height) { uint32_t handle; int pitch; diff --git a/src/drmmode_display.h b/src/drmmode_display.h index dc68892..e9b0e78 100644 --- a/src/drmmode_display.h +++ b/src/drmmode_display.h @@ -31,7 +31,7 @@ #include "xf86drmMode.h" -typedef struct { +struct drm_mode { int fd; int fb_id; drmModeResPtr mode_res; @@ -39,30 +39,40 @@ typedef struct { int cpp; dri_bufmgr *bufmgr; - uint32_t (*create_new_fb)(ScrnInfoPtr pScrn, int width, int height, int *pitch); -} drmmode_rec, *drmmode_ptr; + uint32_t (*create_new_fb)(ScrnInfoPtr pScrn, int width, int height, + int *pitch); +}; -typedef struct { - - drmmode_ptr drmmode; +struct drm_crtc_private { + struct drm_mode *drmmode; drmModeCrtcPtr mode_crtc; drmBO cursor_bo; dri_bo *rotate_bo; int rotate_fb_id; -} drmmode_crtc_private_rec, *drmmode_crtc_private_ptr; +}; + +struct drm_encoder_private { + struct drmmode *drmmode; + int encoder_id; + drmModeEncoderPtr mode_encoder; +}; -typedef struct { - drmmode_ptr drmmode; - int output_id; - drmModeOutputPtr mode_output; +struct drm_connector_private { + struct drm_mode *drmmode; + int connector_id; + drmModeConnectorPtr mode_connector; drmModePropertyBlobPtr edid_blob; -} drmmode_output_private_rec, *drmmode_output_private_ptr; +}; +extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, struct drm_mode * drmmode, + char *busId, char *driver_name, int cpp); +extern Bool drmmode_set_bufmgr(ScrnInfoPtr pScrn, struct drm_mode * drmmode, + dri_bufmgr *bufmgr); +extern void drmmode_set_fb(ScrnInfoPtr pScrn, struct drm_mode * drmmode, + int width, int height, int pitch, drmBO *bo); +extern Bool drmmode_is_rotate_pixmap(ScrnInfoPtr pScrn, pointer pPixData, + dri_bo **bo); -extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, char *busId, char *driver_name, int cpp); -extern Bool drmmode_set_bufmgr(ScrnInfoPtr pScrn, drmmode_ptr drmmode, dri_bufmgr *bufmgr); -extern void drmmode_set_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int width, int height, int pitch, drmBO *bo); -extern Bool drmmode_is_rotate_pixmap(ScrnInfoPtr pScrn, pointer pPixData, dri_bo **bo); +#endif /* XF86DRM_MODE */ -#endif -#endif +#endif /* DRMMODE_DISPLAY_H */ diff --git a/src/i830.h b/src/i830.h index a05da9c..4218253 100644 --- a/src/i830.h +++ b/src/i830.h @@ -658,7 +658,7 @@ typedef struct _I830Rec { int use_drm_mode; #ifdef XF86DRM_MODE - drmmode_rec drmmode; + struct drm_mode drmmode; int drm_mm_init; #endif } I830Rec; diff --git a/src/i830_driver.c b/src/i830_driver.c index 4109d88..436345c 100644 --- a/src/i830_driver.c +++ b/src/i830_driver.c @@ -174,10 +174,13 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +#include + #include "xf86.h" #include "xf86_OSproc.h" #include "xf86Resources.h" #include "xf86RAC.h" +#include "xf86Priv.h" #include "xf86cmap.h" #include "compiler.h" #include "mibstore.h" @@ -1068,6 +1071,8 @@ static Bool i830_kernel_mode_enabled(ScrnInfoPtr pScrn) if (ret) return FALSE; + ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT); + return TRUE; } #else