2007-04-04 19:21:06 -06:00
|
|
|
#include <linux/list.h>
|
|
|
|
#include "drmP.h"
|
|
|
|
#include "drm.h"
|
|
|
|
#include "drm_crtc.h"
|
|
|
|
|
2007-04-05 01:06:42 -06:00
|
|
|
int drm_mode_idr_get(struct drm_device *dev, void *ptr)
|
|
|
|
{
|
|
|
|
int new_id = 0;
|
|
|
|
int ret;
|
|
|
|
again:
|
2007-04-10 02:56:02 -06:00
|
|
|
if (idr_pre_get(&dev->mode_config.crtc_idr, GFP_KERNEL) == 0) {
|
2007-04-05 01:06:42 -06:00
|
|
|
DRM_ERROR("Ran out memory getting a mode number\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
spin_lock(&dev->mode_config.config_lock);
|
2007-04-05 01:06:42 -06:00
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
ret = idr_get_new_above(&dev->mode_config.crtc_idr, ptr, 1, &new_id);
|
2007-04-05 01:06:42 -06:00
|
|
|
if (ret == -EAGAIN) {
|
2007-04-10 02:56:02 -06:00
|
|
|
spin_unlock(&dev->mode_config.config_lock);
|
2007-04-05 01:06:42 -06:00
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
spin_unlock(&dev->mode_config.config_lock);
|
2007-04-05 01:06:42 -06:00
|
|
|
return new_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void drm_mode_idr_put(struct drm_device *dev, int id)
|
|
|
|
{
|
2007-04-10 02:56:02 -06:00
|
|
|
idr_remove(&dev->mode_config.crtc_idr, id);
|
2007-04-05 01:06:42 -06:00
|
|
|
}
|
|
|
|
|
2007-04-04 19:21:06 -06:00
|
|
|
struct drm_framebuffer *drm_framebuffer_create(drm_device_t *dev)
|
|
|
|
{
|
|
|
|
struct drm_framebuffer *fb;
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
spin_lock(&dev->mode_config.config_lock);
|
2007-04-04 19:21:06 -06:00
|
|
|
/* Limit to single framebuffer for now */
|
2007-04-10 02:56:02 -06:00
|
|
|
if (dev->mode_config.num_fb > 1) {
|
2007-04-11 19:28:55 -06:00
|
|
|
spin_unlock(&dev->mode_config.config_lock);
|
2007-04-04 19:21:06 -06:00
|
|
|
DRM_ERROR("Attempt to add multiple framebuffers failed\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-04-10 02:56:02 -06:00
|
|
|
spin_unlock(&dev->mode_config.config_lock);
|
2007-04-04 19:21:06 -06:00
|
|
|
|
|
|
|
fb = kzalloc(sizeof(struct drm_framebuffer), GFP_KERNEL);
|
|
|
|
if (!fb) {
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-04-05 01:06:42 -06:00
|
|
|
|
|
|
|
fb->id = drm_mode_idr_get(dev, fb);
|
2007-04-04 19:21:06 -06:00
|
|
|
fb->dev = dev;
|
2007-04-10 02:56:02 -06:00
|
|
|
spin_lock(&dev->mode_config.config_lock);
|
|
|
|
dev->mode_config.num_fb++;
|
|
|
|
list_add(&fb->head, &dev->mode_config.fb_list);
|
|
|
|
spin_unlock(&dev->mode_config.config_lock);
|
2007-04-04 19:21:06 -06:00
|
|
|
|
|
|
|
return fb;
|
|
|
|
}
|
2007-04-11 08:07:54 -06:00
|
|
|
EXPORT_SYMBOL(drm_framebuffer_create);
|
2007-04-04 19:21:06 -06:00
|
|
|
|
|
|
|
void drm_framebuffer_destroy(struct drm_framebuffer *fb)
|
|
|
|
{
|
|
|
|
drm_device_t *dev = fb->dev;
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
spin_lock(&dev->mode_config.config_lock);
|
2007-04-05 01:06:42 -06:00
|
|
|
drm_mode_idr_put(dev, fb->id);
|
2007-04-04 19:21:06 -06:00
|
|
|
list_del(&fb->head);
|
2007-04-10 02:56:02 -06:00
|
|
|
dev->mode_config.num_fb--;
|
|
|
|
spin_unlock(&dev->mode_config.config_lock);
|
2007-04-04 19:21:06 -06:00
|
|
|
|
|
|
|
kfree(fb);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct drm_crtc *drm_crtc_create(drm_device_t *dev,
|
|
|
|
const struct drm_crtc_funcs *funcs)
|
|
|
|
{
|
2007-04-05 01:06:42 -06:00
|
|
|
struct drm_crtc *crtc;
|
|
|
|
|
|
|
|
crtc = kzalloc(sizeof(struct drm_crtc), GFP_KERNEL);
|
2007-04-04 19:21:06 -06:00
|
|
|
if (!crtc)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
crtc->dev = dev;
|
|
|
|
crtc->funcs = funcs;
|
|
|
|
|
2007-04-05 01:06:42 -06:00
|
|
|
crtc->id = drm_mode_idr_get(dev, crtc);
|
2007-04-04 19:21:06 -06:00
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
spin_lock(&dev->mode_config.config_lock);
|
|
|
|
list_add_tail(&crtc->head, &dev->mode_config.crtc_list);
|
|
|
|
dev->mode_config.num_crtc++;
|
|
|
|
spin_unlock(&dev->mode_config.config_lock);
|
2007-04-04 19:21:06 -06:00
|
|
|
|
|
|
|
return crtc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_crtc_create);
|
|
|
|
|
|
|
|
void drm_crtc_destroy(struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
drm_device_t *dev = crtc->dev;
|
|
|
|
|
|
|
|
if (crtc->funcs->cleanup)
|
|
|
|
(*crtc->funcs->cleanup)(crtc);
|
|
|
|
|
2007-04-05 01:06:42 -06:00
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
spin_lock(&dev->mode_config.config_lock);
|
2007-04-05 01:06:42 -06:00
|
|
|
drm_mode_idr_put(dev, crtc->id);
|
2007-04-04 19:21:06 -06:00
|
|
|
list_del(&crtc->head);
|
2007-04-10 02:56:02 -06:00
|
|
|
dev->mode_config.num_crtc--;
|
|
|
|
spin_unlock(&dev->mode_config.config_lock);
|
2007-04-04 19:21:06 -06:00
|
|
|
kfree(crtc);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_crtc_destroy);
|
|
|
|
|
|
|
|
bool drm_crtc_in_use(struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
struct drm_output *output;
|
|
|
|
drm_device_t *dev = crtc->dev;
|
2007-04-10 10:49:02 -06:00
|
|
|
/* FIXME: Locking around list access? */
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list, head)
|
2007-04-04 19:21:06 -06:00
|
|
|
if (output->crtc == crtc)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_crtc_in_use);
|
|
|
|
|
|
|
|
void drm_crtc_probe_output_modes(struct drm_device *dev, int maxX, int maxY)
|
|
|
|
{
|
|
|
|
struct drm_output *output;
|
|
|
|
struct drm_display_mode *mode, *t;
|
|
|
|
int ret;
|
|
|
|
//if (maxX == 0 || maxY == 0)
|
|
|
|
// TODO
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list, head) {
|
2007-04-04 19:21:06 -06:00
|
|
|
|
|
|
|
list_for_each_entry_safe(mode, t, &output->modes, head)
|
|
|
|
drm_mode_remove(output, mode);
|
|
|
|
|
|
|
|
output->status = (*output->funcs->detect)(output);
|
|
|
|
|
|
|
|
if (output->status == output_status_disconnected) {
|
|
|
|
/* TODO set EDID to NULL */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = (*output->funcs->get_modes)(output);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
/* move the modes over to the main mode list */
|
|
|
|
drm_mode_list_concat(&output->probed_modes,
|
|
|
|
&output->modes);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maxX && maxY)
|
|
|
|
drm_mode_validate_size(dev, &output->modes, maxX,
|
|
|
|
maxY, 0);
|
|
|
|
list_for_each_entry_safe(mode, t, &output->modes, head) {
|
|
|
|
if (mode->status == MODE_OK)
|
|
|
|
mode->status = (*output->funcs->mode_valid)(output,mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
drm_mode_prune_invalid(dev, &output->modes, TRUE);
|
|
|
|
|
|
|
|
if (list_empty(&output->modes))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
drm_mode_sort(&output->modes);
|
|
|
|
|
|
|
|
DRM_DEBUG("Probed modes for %s\n", output->name);
|
|
|
|
list_for_each_entry_safe(mode, t, &output->modes, head) {
|
|
|
|
mode->vrefresh = drm_mode_vrefresh(mode);
|
|
|
|
|
|
|
|
drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
|
|
|
|
drm_mode_debug_printmodeline(dev, mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool drm_crtc_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
|
|
|
|
int x, int y)
|
|
|
|
{
|
|
|
|
drm_device_t *dev = crtc->dev;
|
|
|
|
struct drm_display_mode *adjusted_mode, saved_mode;
|
|
|
|
int saved_x, saved_y;
|
|
|
|
bool didLock = false;
|
|
|
|
bool ret = false;
|
|
|
|
struct drm_output *output;
|
|
|
|
|
2007-04-04 21:34:50 -06:00
|
|
|
adjusted_mode = drm_mode_duplicate(dev, mode);
|
2007-04-04 19:21:06 -06:00
|
|
|
|
|
|
|
crtc->enabled = drm_crtc_in_use(crtc);
|
|
|
|
|
|
|
|
if (!crtc->enabled) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
didLock = crtc->funcs->lock(crtc);
|
|
|
|
|
|
|
|
saved_mode = crtc->mode;
|
|
|
|
saved_x = crtc->x;
|
|
|
|
saved_y = crtc->y;
|
|
|
|
|
|
|
|
/* Update crtc values up front so the driver can rely on them for mode
|
|
|
|
* setting.
|
|
|
|
*/
|
|
|
|
crtc->mode = *mode;
|
|
|
|
crtc->x = x;
|
|
|
|
crtc->y = y;
|
|
|
|
|
|
|
|
/* XXX short-circuit changes to base location only */
|
|
|
|
|
|
|
|
/* Pass our mode to the outputs and the CRTC to give them a chance to
|
|
|
|
* adjust it according to limitations or output properties, and also
|
|
|
|
* a chance to reject the mode entirely.
|
|
|
|
*/
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list, head) {
|
2007-04-04 19:21:06 -06:00
|
|
|
|
|
|
|
if (output->crtc != crtc)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!output->funcs->mode_fixup(output, mode, adjusted_mode)) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!crtc->funcs->mode_fixup(crtc, mode, adjusted_mode)) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepare the outputs and CRTCs before setting the mode. */
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list, head) {
|
2007-04-04 19:21:06 -06:00
|
|
|
|
|
|
|
if (output->crtc != crtc)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Disable the output as the first thing we do. */
|
|
|
|
output->funcs->prepare(output);
|
|
|
|
}
|
|
|
|
|
|
|
|
crtc->funcs->prepare(crtc);
|
|
|
|
|
|
|
|
/* Set up the DPLL and any output state that needs to adjust or depend
|
|
|
|
* on the DPLL.
|
|
|
|
*/
|
|
|
|
crtc->funcs->mode_set(crtc, mode, adjusted_mode, x, y);
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list, head) {
|
2007-04-04 19:21:06 -06:00
|
|
|
if (output->crtc == crtc)
|
|
|
|
output->funcs->mode_set(output, mode, adjusted_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, enable the clocks, plane, pipe, and outputs that we set up. */
|
|
|
|
crtc->funcs->commit(crtc);
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list, head) {
|
2007-04-11 19:43:13 -06:00
|
|
|
if (output->crtc == crtc) {
|
2007-04-04 19:21:06 -06:00
|
|
|
output->funcs->commit(output);
|
|
|
|
#if 0 // TODO def RANDR_12_INTERFACE
|
|
|
|
if (output->randr_output)
|
|
|
|
RRPostPendingProperties (output->randr_output);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX free adjustedmode */
|
2007-04-04 21:34:50 -06:00
|
|
|
drm_crtc_mode_destroy(dev, adjusted_mode);
|
2007-04-04 19:21:06 -06:00
|
|
|
ret = TRUE;
|
|
|
|
/* TODO */
|
|
|
|
// if (scrn->pScreen)
|
|
|
|
// drm_crtc_set_screen_sub_pixel_order(dev);
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (!ret) {
|
|
|
|
crtc->x = saved_x;
|
|
|
|
crtc->y = saved_y;
|
|
|
|
crtc->mode = saved_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (didLock)
|
|
|
|
crtc->funcs->unlock (crtc);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool drm_set_desired_modes(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct drm_crtc *crtc;
|
|
|
|
struct drm_output *output, *list_output;
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
|
2007-04-04 19:21:06 -06:00
|
|
|
output = NULL;
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(list_output, &dev->mode_config.output_list, head) {
|
2007-04-04 19:21:06 -06:00
|
|
|
if (list_output->crtc == crtc) {
|
|
|
|
output = list_output;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Skip disabled crtcs */
|
|
|
|
if (!output)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
memset(&crtc->mode, 0, sizeof(crtc->mode));
|
2007-04-05 02:01:02 -06:00
|
|
|
if (!crtc->desired_mode->crtc_hdisplay) {
|
2007-04-04 19:21:06 -06:00
|
|
|
|
|
|
|
}
|
2007-04-05 02:01:02 -06:00
|
|
|
if (!drm_crtc_set_mode(crtc, crtc->desired_mode,
|
2007-04-04 19:21:06 -06:00
|
|
|
crtc->desired_x, crtc->desired_y))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
drm_disable_unused_functions(dev);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_set_desired_modes);
|
|
|
|
|
|
|
|
void drm_disable_unused_functions(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct drm_output *output;
|
|
|
|
struct drm_crtc *crtc;
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list, head) {
|
2007-04-04 19:21:06 -06:00
|
|
|
if (!output->crtc)
|
|
|
|
(*output->funcs->dpms)(output, DPMSModeOff);
|
|
|
|
}
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
|
2007-04-04 19:21:06 -06:00
|
|
|
if (!crtc->enabled)
|
|
|
|
crtc->funcs->dpms(crtc, DPMSModeOff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_mode_probed_add - add a mode to the specified output's probed mode list
|
|
|
|
* @output: output the new mode
|
|
|
|
* @mode: mode data
|
|
|
|
*
|
|
|
|
* Add @mode to @output's mode list for later use.
|
|
|
|
*/
|
|
|
|
void drm_mode_probed_add(struct drm_output *output, struct drm_display_mode *mode)
|
|
|
|
{
|
|
|
|
spin_lock(&output->modes_lock);
|
|
|
|
list_add(&mode->head, &output->probed_modes);
|
|
|
|
spin_unlock(&output->modes_lock);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_probed_add);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_mode_remove - remove and free a mode
|
|
|
|
* @output: output list to modify
|
|
|
|
* @mode: mode to remove
|
|
|
|
*
|
|
|
|
* Remove @mode from @output's mode list, then free it.
|
|
|
|
*/
|
|
|
|
void drm_mode_remove(struct drm_output *output, struct drm_display_mode *mode)
|
|
|
|
{
|
|
|
|
spin_lock(&output->modes_lock);
|
|
|
|
list_del(&mode->head);
|
|
|
|
spin_unlock(&output->modes_lock);
|
|
|
|
kfree(mode);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_remove);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Probably belongs in the DRM device structure
|
|
|
|
*/
|
|
|
|
struct drm_output *drm_output_create(drm_device_t *dev,
|
|
|
|
const struct drm_output_funcs *funcs,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct drm_output *output = NULL;
|
|
|
|
|
2007-04-09 22:49:49 -06:00
|
|
|
output = kzalloc(sizeof(struct drm_output), GFP_KERNEL);
|
2007-04-04 19:21:06 -06:00
|
|
|
if (!output)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
output->dev = dev;
|
|
|
|
output->funcs = funcs;
|
2007-04-05 01:06:42 -06:00
|
|
|
output->id = drm_mode_idr_get(dev, output);
|
2007-04-04 19:21:06 -06:00
|
|
|
if (name)
|
|
|
|
strncpy(output->name, name, DRM_OUTPUT_LEN);
|
|
|
|
output->name[DRM_OUTPUT_LEN - 1] = 0;
|
|
|
|
output->subpixel_order = SubPixelUnknown;
|
|
|
|
INIT_LIST_HEAD(&output->probed_modes);
|
|
|
|
INIT_LIST_HEAD(&output->modes);
|
|
|
|
spin_lock_init(&output->modes_lock);
|
|
|
|
/* randr_output? */
|
|
|
|
/* output_set_monitor(output)? */
|
|
|
|
/* check for output_ignored(output)? */
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
spin_lock(&dev->mode_config.config_lock);
|
|
|
|
list_add_tail(&output->head, &dev->mode_config.output_list);
|
|
|
|
dev->mode_config.num_output++;
|
2007-04-04 19:21:06 -06:00
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
spin_unlock(&dev->mode_config.config_lock);
|
2007-04-04 19:21:06 -06:00
|
|
|
|
|
|
|
return output;
|
|
|
|
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_output_create);
|
|
|
|
|
|
|
|
void drm_output_destroy(struct drm_output *output)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = output->dev;
|
|
|
|
struct drm_display_mode *mode, *t;
|
|
|
|
|
|
|
|
if (*output->funcs->cleanup)
|
|
|
|
(*output->funcs->cleanup)(output);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(mode, t, &output->probed_modes, head)
|
|
|
|
drm_mode_remove(output, mode);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(mode, t, &output->modes, head)
|
|
|
|
drm_mode_remove(output, mode);
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
spin_lock(&dev->mode_config.config_lock);
|
2007-04-05 01:06:42 -06:00
|
|
|
drm_mode_idr_put(dev, output->id);
|
2007-04-04 19:21:06 -06:00
|
|
|
list_del(&output->head);
|
2007-04-10 02:56:02 -06:00
|
|
|
spin_unlock(&dev->mode_config.config_lock);
|
2007-04-04 19:21:06 -06:00
|
|
|
kfree(output);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_output_destroy);
|
|
|
|
|
|
|
|
bool drm_output_rename(struct drm_output *output, const char *name)
|
|
|
|
{
|
|
|
|
if (!name)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
strncpy(output->name, name, DRM_OUTPUT_LEN);
|
|
|
|
output->name[DRM_OUTPUT_LEN - 1] = 0;
|
|
|
|
// drm_output_set_monitor(output);
|
|
|
|
// if (drm_output_ignored(output))
|
|
|
|
// return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_output_rename);
|
|
|
|
|
2007-04-04 21:34:50 -06:00
|
|
|
struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct drm_display_mode *nmode;
|
|
|
|
|
|
|
|
nmode = kzalloc(sizeof(struct drm_display_mode), GFP_KERNEL);
|
|
|
|
if (!nmode)
|
|
|
|
return NULL;
|
|
|
|
|
2007-04-05 01:06:42 -06:00
|
|
|
nmode->mode_id = drm_mode_idr_get(dev, nmode);
|
2007-04-04 21:34:50 -06:00
|
|
|
return nmode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void drm_crtc_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode)
|
|
|
|
{
|
2007-04-05 01:06:42 -06:00
|
|
|
drm_mode_idr_put(dev, mode->mode_id);
|
2007-04-04 21:34:50 -06:00
|
|
|
|
|
|
|
kfree(mode);
|
|
|
|
}
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
void drm_mode_config_init(drm_device_t *dev)
|
2007-04-04 19:21:06 -06:00
|
|
|
{
|
2007-04-10 02:56:02 -06:00
|
|
|
spin_lock_init(&dev->mode_config.config_lock);
|
|
|
|
INIT_LIST_HEAD(&dev->mode_config.fb_list);
|
|
|
|
INIT_LIST_HEAD(&dev->mode_config.crtc_list);
|
|
|
|
INIT_LIST_HEAD(&dev->mode_config.output_list);
|
|
|
|
idr_init(&dev->mode_config.crtc_idr);
|
2007-04-04 19:21:06 -06:00
|
|
|
}
|
2007-04-10 02:56:02 -06:00
|
|
|
EXPORT_SYMBOL(drm_mode_config_init);
|
2007-04-04 19:21:06 -06:00
|
|
|
|
2007-04-10 02:44:47 -06:00
|
|
|
static int drm_get_buffer_object(drm_device_t *dev, struct drm_buffer_object **bo, unsigned long handle)
|
2007-04-04 19:21:06 -06:00
|
|
|
{
|
|
|
|
drm_user_object_t *uo;
|
|
|
|
drm_hash_item_t *hash;
|
|
|
|
int ret;
|
|
|
|
|
2007-04-09 22:49:49 -06:00
|
|
|
*bo = NULL;
|
2007-04-10 02:44:47 -06:00
|
|
|
|
2007-04-04 19:21:06 -06:00
|
|
|
mutex_lock(&dev->struct_mutex);
|
|
|
|
ret = drm_ht_find_item(&dev->object_hash, handle, &hash);
|
|
|
|
if (ret) {
|
|
|
|
DRM_ERROR("Couldn't find handle.\n");
|
2007-04-09 22:49:49 -06:00
|
|
|
ret = -EINVAL;
|
2007-04-04 19:21:06 -06:00
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
uo = drm_hash_entry(hash, drm_user_object_t, hash);
|
|
|
|
if (uo->type != drm_buffer_type) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2007-04-10 02:44:47 -06:00
|
|
|
*bo = drm_user_object_entry(uo, drm_buffer_object_t, base);
|
2007-04-04 19:21:06 -06:00
|
|
|
ret = 0;
|
|
|
|
out_err:
|
|
|
|
mutex_unlock(&dev->struct_mutex);
|
2007-04-10 02:44:47 -06:00
|
|
|
return ret;
|
2007-04-04 19:21:06 -06:00
|
|
|
}
|
|
|
|
|
2007-04-11 08:07:54 -06:00
|
|
|
/**
|
|
|
|
* drm_initial_config - setup a sane initial output configuration
|
|
|
|
* @dev: DRM device
|
|
|
|
* @fb: framebuffer backing for new setup
|
|
|
|
* @can_grow: this configuration is growable
|
|
|
|
*
|
|
|
|
* Scan the CRTCs and outputs and try to put together an initial setup.
|
|
|
|
* At the moment, this is a cloned configuration across all heads with
|
|
|
|
* @fb as the backing store.
|
|
|
|
*/
|
|
|
|
bool drm_initial_config(drm_device_t *dev, struct drm_framebuffer *fb,
|
|
|
|
bool can_grow)
|
2007-04-04 19:21:06 -06:00
|
|
|
{
|
|
|
|
/* do a hardcoded initial configuration here */
|
2007-04-07 20:22:39 -06:00
|
|
|
struct drm_crtc *crtc, *vga_crtc = NULL, *dvi_crtc = NULL,
|
2007-04-10 10:49:02 -06:00
|
|
|
*lvds_crtc = NULL;
|
2007-04-04 19:21:06 -06:00
|
|
|
struct drm_output *output, *use_output = NULL;
|
|
|
|
|
|
|
|
/* bind both CRTCs to this fb */
|
|
|
|
/* only initialise one crtc to enabled state */
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
|
2007-04-11 08:07:54 -06:00
|
|
|
crtc->fb = fb;
|
2007-04-04 19:21:06 -06:00
|
|
|
if (!vga_crtc) {
|
|
|
|
vga_crtc = crtc;
|
|
|
|
crtc->enabled = 1;
|
|
|
|
crtc->desired_x = 0;
|
|
|
|
crtc->desired_y = 0;
|
2007-04-07 20:22:39 -06:00
|
|
|
} else if (!lvds_crtc) {
|
|
|
|
lvds_crtc = crtc;
|
|
|
|
crtc->enabled = 1;
|
|
|
|
crtc->desired_x = 0;
|
|
|
|
crtc->desired_y = 0;
|
2007-04-11 08:07:54 -06:00
|
|
|
} else if (!dvi_crtc) {
|
2007-04-04 19:21:06 -06:00
|
|
|
dvi_crtc = crtc;
|
|
|
|
crtc->enabled = 1;
|
|
|
|
crtc->desired_x = 0;
|
|
|
|
crtc->desired_y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-11 08:07:54 -06:00
|
|
|
drm_crtc_probe_output_modes(dev, 2048, 2048);
|
2007-04-04 19:21:06 -06:00
|
|
|
|
|
|
|
/* hard bind the CRTCS */
|
|
|
|
|
|
|
|
/* bind analog output to one crtc */
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list, head) {
|
2007-04-04 19:21:06 -06:00
|
|
|
struct drm_display_mode *des_mode;
|
|
|
|
|
2007-04-11 19:28:55 -06:00
|
|
|
if (list_empty(&output->modes))
|
|
|
|
continue;
|
|
|
|
|
2007-04-07 20:22:39 -06:00
|
|
|
/* Get the first preferred moded */
|
|
|
|
list_for_each_entry(des_mode, &output->modes, head) {
|
|
|
|
if (des_mode->flags & DRM_MODE_TYPE_PREFERRED)
|
2007-04-04 19:21:06 -06:00
|
|
|
break;
|
2007-04-07 20:22:39 -06:00
|
|
|
}
|
|
|
|
if (!strncmp(output->name, "VGA", 3)) {
|
|
|
|
output->crtc = vga_crtc;
|
2007-04-11 08:07:54 -06:00
|
|
|
DRM_DEBUG("VGA preferred mode: %s\n", des_mode->name);
|
2007-04-05 02:01:02 -06:00
|
|
|
output->crtc->desired_mode = des_mode;
|
2007-04-04 19:21:06 -06:00
|
|
|
output->initial_x = 0;
|
|
|
|
output->initial_y = 0;
|
|
|
|
use_output = output;
|
2007-04-07 20:22:39 -06:00
|
|
|
} else if (!strncmp(output->name, "TMDS", 4)) {
|
2007-04-04 19:21:06 -06:00
|
|
|
output->crtc = vga_crtc;
|
2007-04-11 08:07:54 -06:00
|
|
|
DRM_DEBUG("TMDS preferred mode: %s\n", des_mode->name);
|
2007-04-05 02:01:02 -06:00
|
|
|
output->crtc->desired_mode = des_mode;
|
2007-04-04 19:21:06 -06:00
|
|
|
output->initial_x = 0;
|
|
|
|
output->initial_y = 0;
|
2007-04-07 20:22:39 -06:00
|
|
|
} else if (!strncmp(output->name, "LVDS", 3)) {
|
|
|
|
output->crtc = lvds_crtc;
|
2007-04-11 08:07:54 -06:00
|
|
|
DRM_DEBUG("LVDS preferred mode: %s\n", des_mode->name);
|
2007-04-07 20:22:39 -06:00
|
|
|
output->crtc->desired_mode = des_mode;
|
|
|
|
output->initial_x = 0;
|
|
|
|
output->initial_y = 0;
|
2007-04-04 19:21:06 -06:00
|
|
|
} else
|
|
|
|
output->crtc = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_initial_config);
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
void drm_mode_config_cleanup(drm_device_t *dev)
|
2007-04-04 19:21:06 -06:00
|
|
|
{
|
|
|
|
struct drm_output *output, *ot;
|
|
|
|
struct drm_crtc *crtc, *ct;
|
2007-04-11 19:55:10 -06:00
|
|
|
struct drm_crtc *fb, *fbt;
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry_safe(output, ot, &dev->mode_config.output_list, head) {
|
2007-04-04 19:21:06 -06:00
|
|
|
drm_output_destroy(output);
|
|
|
|
}
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) {
|
2007-04-04 19:21:06 -06:00
|
|
|
drm_crtc_destroy(crtc);
|
|
|
|
}
|
2007-04-11 19:55:10 -06:00
|
|
|
|
|
|
|
list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) {
|
|
|
|
drmfb_remove(dev, fb);
|
|
|
|
drm_framebuffer_destroy(fb);
|
|
|
|
}
|
2007-04-04 19:21:06 -06:00
|
|
|
}
|
2007-04-10 02:56:02 -06:00
|
|
|
EXPORT_SYMBOL(drm_mode_config_cleanup);
|
2007-04-04 19:21:06 -06:00
|
|
|
|
2007-04-11 16:54:31 -06:00
|
|
|
int drm_crtc_set_config(struct drm_crtc *crtc, struct drm_mode_crtc *crtc_info, struct drm_display_mode *new_mode, struct drm_output **output_set, struct drm_framebuffer *fb)
|
2007-04-05 02:01:02 -06:00
|
|
|
{
|
|
|
|
drm_device_t *dev = crtc->dev;
|
|
|
|
struct drm_crtc **save_crtcs, *new_crtc;
|
|
|
|
bool save_enabled = crtc->enabled;
|
|
|
|
bool changed;
|
|
|
|
struct drm_output *output;
|
|
|
|
int count = 0, ro;
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
save_crtcs = kzalloc(dev->mode_config.num_crtc * sizeof(struct drm_crtc *), GFP_KERNEL);
|
2007-04-05 02:01:02 -06:00
|
|
|
if (!save_crtcs)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2007-04-11 16:54:31 -06:00
|
|
|
if (crtc->fb != fb)
|
|
|
|
changed = true;
|
|
|
|
|
2007-04-05 02:01:02 -06:00
|
|
|
if (crtc_info->x != crtc->x || crtc_info->y != crtc->y)
|
|
|
|
changed = true;
|
|
|
|
|
2007-04-10 21:19:30 -06:00
|
|
|
if (new_mode && (crtc->mode.mode_id != new_mode->mode_id))
|
2007-04-05 02:01:02 -06:00
|
|
|
changed = true;
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list, head) {
|
2007-04-05 02:01:02 -06:00
|
|
|
save_crtcs[count++] = output->crtc;
|
|
|
|
|
|
|
|
if (output->crtc == crtc)
|
|
|
|
new_crtc = NULL;
|
|
|
|
else
|
|
|
|
new_crtc = output->crtc;
|
|
|
|
|
2007-04-11 19:43:13 -06:00
|
|
|
for (ro = 0; ro < crtc_info->count_outputs; ro++) {
|
2007-04-05 02:01:02 -06:00
|
|
|
if (output_set[ro] == output)
|
|
|
|
new_crtc = crtc;
|
|
|
|
}
|
|
|
|
if (new_crtc != output->crtc) {
|
|
|
|
changed = true;
|
|
|
|
output->crtc = new_crtc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed) {
|
2007-04-11 16:54:31 -06:00
|
|
|
crtc->fb = fb;
|
2007-04-10 21:19:30 -06:00
|
|
|
crtc->enabled = (new_mode != NULL);
|
|
|
|
if (new_mode != NULL) {
|
2007-04-05 02:01:02 -06:00
|
|
|
DRM_DEBUG("attempting to set mode from userspace\n");
|
|
|
|
drm_mode_debug_printmodeline(dev, new_mode);
|
|
|
|
if (!drm_crtc_set_mode(crtc, new_mode, crtc_info->x,
|
|
|
|
crtc_info->y)) {
|
|
|
|
crtc->enabled = save_enabled;
|
|
|
|
count = 0;
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list, head)
|
2007-04-05 02:01:02 -06:00
|
|
|
output->crtc = save_crtcs[count++];
|
|
|
|
kfree(save_crtcs);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
crtc->desired_x = crtc_info->x;
|
|
|
|
crtc->desired_y = crtc_info->y;
|
2007-04-10 21:19:30 -06:00
|
|
|
crtc->desired_mode = new_mode;
|
2007-04-05 02:01:02 -06:00
|
|
|
}
|
|
|
|
drm_disable_unused_functions(dev);
|
|
|
|
}
|
|
|
|
kfree(save_crtcs);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-04 21:34:50 -06:00
|
|
|
void drm_crtc_convert_to_umode(struct drm_mode_modeinfo *out, struct drm_display_mode *in)
|
|
|
|
{
|
|
|
|
|
|
|
|
out->id = in->mode_id;
|
|
|
|
out->clock = in->clock;
|
|
|
|
out->hdisplay = in->hdisplay;
|
|
|
|
out->hsync_start = in->hsync_start;
|
|
|
|
out->hsync_end = in->hsync_end;
|
|
|
|
out->htotal = in->htotal;
|
|
|
|
out->hskew = in->hskew;
|
|
|
|
out->vdisplay = in->vdisplay;
|
|
|
|
out->vsync_start = in->vsync_start;
|
|
|
|
out->vsync_end = in->vsync_end;
|
|
|
|
out->vtotal = in->vtotal;
|
|
|
|
out->vscan = in->vscan;
|
|
|
|
|
|
|
|
out->flags = in->flags;
|
2007-04-05 01:06:42 -06:00
|
|
|
strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
|
|
|
|
out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
|
2007-04-04 21:34:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* IOCTL code from userspace */
|
|
|
|
int drm_mode_getresources(struct inode *inode, struct file *filp,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
drm_file_t *priv = filp->private_data;
|
|
|
|
drm_device_t *dev = priv->head->dev;
|
|
|
|
struct drm_mode_card_res __user *argp = (void __user *)arg;
|
|
|
|
struct drm_mode_card_res card_res;
|
|
|
|
struct list_head *lh;
|
2007-04-10 21:19:30 -06:00
|
|
|
struct drm_framebuffer *fb;
|
2007-04-04 21:34:50 -06:00
|
|
|
struct drm_output *output;
|
2007-04-05 01:06:42 -06:00
|
|
|
struct drm_crtc *crtc;
|
2007-04-04 21:34:50 -06:00
|
|
|
struct drm_mode_modeinfo u_mode;
|
|
|
|
struct drm_display_mode *mode;
|
|
|
|
int retcode = 0;
|
|
|
|
int mode_count= 0;
|
2007-04-05 01:06:42 -06:00
|
|
|
int output_count = 0;
|
|
|
|
int crtc_count = 0;
|
2007-04-10 21:19:30 -06:00
|
|
|
int fb_count = 0;
|
2007-04-05 01:06:42 -06:00
|
|
|
int copied = 0;
|
2007-04-09 22:49:49 -06:00
|
|
|
|
2007-04-04 21:34:50 -06:00
|
|
|
memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
|
2007-04-05 01:06:42 -06:00
|
|
|
|
2007-04-10 21:19:30 -06:00
|
|
|
list_for_each(lh, &dev->mode_config.fb_list)
|
|
|
|
fb_count++;
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each(lh, &dev->mode_config.crtc_list)
|
2007-04-05 01:06:42 -06:00
|
|
|
crtc_count++;
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list,
|
2007-04-09 22:49:49 -06:00
|
|
|
head) {
|
2007-04-05 01:06:42 -06:00
|
|
|
output_count++;
|
2007-04-04 21:34:50 -06:00
|
|
|
list_for_each(lh, &output->modes)
|
|
|
|
mode_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copy_from_user(&card_res, argp, sizeof(card_res)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2007-04-09 22:49:49 -06:00
|
|
|
if (card_res.count_modes == 0) {
|
|
|
|
DRM_DEBUG("probing modes %dx%d\n", dev->mode_config.max_width, dev->mode_config.max_height);
|
|
|
|
drm_crtc_probe_output_modes(dev, dev->mode_config.max_width, dev->mode_config.max_height);
|
|
|
|
mode_count = 0;
|
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list, head) {
|
|
|
|
list_for_each(lh, &output->modes)
|
|
|
|
mode_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-10 21:19:30 -06:00
|
|
|
/* handle this in 4 parts */
|
|
|
|
/* FBs */
|
|
|
|
if (card_res.count_fbs >= fb_count) {
|
|
|
|
copied = 0;
|
|
|
|
list_for_each_entry(fb, &dev->mode_config.fb_list, head) {
|
|
|
|
if (put_user(fb->id, &card_res.fb_id[copied++])) {
|
|
|
|
retcode = -EFAULT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
card_res.count_fbs = fb_count;
|
|
|
|
|
2007-04-05 01:06:42 -06:00
|
|
|
/* CRTCs */
|
|
|
|
if (card_res.count_crtcs >= crtc_count) {
|
|
|
|
copied = 0;
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head){
|
2007-04-05 01:06:42 -06:00
|
|
|
DRM_DEBUG("CRTC ID is %d\n", crtc->id);
|
|
|
|
if (put_user(crtc->id, &card_res.crtc_id[copied++])) {
|
|
|
|
retcode = -EFAULT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
card_res.count_crtcs = crtc_count;
|
|
|
|
|
|
|
|
|
|
|
|
/* Outputs */
|
|
|
|
if (card_res.count_outputs >= output_count) {
|
|
|
|
copied = 0;
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list,
|
2007-04-05 01:06:42 -06:00
|
|
|
head) {
|
|
|
|
DRM_DEBUG("OUTPUT ID is %d\n", output->id);
|
|
|
|
if (put_user(output->id, &card_res.output_id[copied++])) {
|
|
|
|
retcode = -EFAULT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
card_res.count_outputs = output_count;
|
|
|
|
|
|
|
|
/* Modes */
|
2007-04-04 21:34:50 -06:00
|
|
|
if (card_res.count_modes >= mode_count) {
|
2007-04-05 01:06:42 -06:00
|
|
|
copied = 0;
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list,
|
2007-04-04 21:34:50 -06:00
|
|
|
head) {
|
|
|
|
list_for_each_entry(mode, &output->modes, head) {
|
|
|
|
drm_crtc_convert_to_umode(&u_mode, mode);
|
|
|
|
if (copy_to_user(&card_res.modes[copied++], &u_mode, sizeof(struct drm_mode_modeinfo))) {
|
|
|
|
retcode = -EFAULT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-04-05 01:06:42 -06:00
|
|
|
card_res.count_modes = mode_count;
|
2007-04-04 21:34:50 -06:00
|
|
|
|
|
|
|
done:
|
|
|
|
DRM_DEBUG("Counted %d %d %d\n", card_res.count_crtcs,
|
|
|
|
card_res.count_outputs,
|
|
|
|
card_res.count_modes);
|
|
|
|
|
|
|
|
if (copy_to_user(argp, &card_res, sizeof(card_res)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return retcode;
|
|
|
|
}
|
2007-04-05 01:06:42 -06:00
|
|
|
|
|
|
|
int drm_mode_getcrtc(struct inode *inode, struct file *filp,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
drm_file_t *priv = filp->private_data;
|
|
|
|
drm_device_t *dev = priv->head->dev;
|
|
|
|
struct drm_mode_crtc __user *argp = (void __user *)arg;
|
|
|
|
struct drm_mode_crtc crtc_resp;
|
|
|
|
struct drm_crtc *crtc;
|
|
|
|
struct drm_output *output;
|
|
|
|
int ocount;
|
|
|
|
int retcode = 0;
|
|
|
|
|
|
|
|
if (copy_from_user(&crtc_resp, argp, sizeof(crtc_resp)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
crtc = idr_find(&dev->mode_config.crtc_idr, crtc_resp.crtc_id);
|
2007-04-05 01:06:42 -06:00
|
|
|
if (!crtc || (crtc->id != crtc_resp.crtc_id))
|
|
|
|
return -EINVAL;
|
|
|
|
crtc_resp.x = crtc->x;
|
|
|
|
crtc_resp.y = crtc->y;
|
|
|
|
crtc_resp.fb_id = 1;
|
|
|
|
|
|
|
|
crtc_resp.outputs = 0;
|
|
|
|
if (crtc->enabled) {
|
|
|
|
|
|
|
|
crtc_resp.mode = crtc->mode.mode_id;
|
|
|
|
ocount = 0;
|
2007-04-10 02:56:02 -06:00
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list, head) {
|
2007-04-05 01:06:42 -06:00
|
|
|
if (output->crtc == crtc)
|
|
|
|
crtc_resp.outputs |= 1 << (ocount++);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
crtc_resp.mode = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copy_to_user(argp, &crtc_resp, sizeof(crtc_resp)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return retcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
int drm_mode_getoutput(struct inode *inode, struct file *filp,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
drm_file_t *priv = filp->private_data;
|
|
|
|
drm_device_t *dev = priv->head->dev;
|
|
|
|
struct drm_mode_get_output __user *argp = (void __user *)arg;
|
|
|
|
struct drm_mode_get_output out_resp;
|
|
|
|
struct drm_output *output;
|
|
|
|
struct drm_display_mode *mode;
|
|
|
|
int mode_count = 0;
|
|
|
|
int retcode = 0;
|
|
|
|
int copied = 0;
|
|
|
|
|
|
|
|
if (copy_from_user(&out_resp, argp, sizeof(out_resp)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2007-04-10 00:25:31 -06:00
|
|
|
DRM_DEBUG("output id %d:\n", out_resp.output);
|
2007-04-10 02:56:02 -06:00
|
|
|
output= idr_find(&dev->mode_config.crtc_idr, out_resp.output);
|
2007-04-05 01:06:42 -06:00
|
|
|
if (!output || (output->id != out_resp.output))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
list_for_each_entry(mode, &output->modes, head)
|
|
|
|
mode_count++;
|
|
|
|
|
2007-04-10 00:25:31 -06:00
|
|
|
strncpy(out_resp.name, output->name, DRM_OUTPUT_NAME_LEN);
|
|
|
|
out_resp.name[DRM_OUTPUT_NAME_LEN-1] = 0;
|
|
|
|
|
2007-04-05 01:06:42 -06:00
|
|
|
out_resp.mm_width = output->mm_width;
|
|
|
|
out_resp.mm_height = output->mm_height;
|
|
|
|
out_resp.subpixel = output->subpixel_order;
|
|
|
|
out_resp.connection = output->status;
|
|
|
|
if (output->crtc)
|
|
|
|
out_resp.crtc = output->crtc->id;
|
|
|
|
else
|
|
|
|
out_resp.crtc = 0;
|
|
|
|
|
2007-04-09 22:49:49 -06:00
|
|
|
if ((out_resp.count_modes >= mode_count) && mode_count) {
|
2007-04-05 01:06:42 -06:00
|
|
|
copied = 0;
|
|
|
|
list_for_each_entry(mode, &output->modes, head) {
|
|
|
|
if (put_user(mode->mode_id, &out_resp.modes[copied++])) {
|
|
|
|
retcode = -EFAULT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out_resp.count_modes = mode_count;
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (copy_to_user(argp, &out_resp, sizeof(out_resp)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return retcode;
|
|
|
|
}
|
2007-04-05 02:01:02 -06:00
|
|
|
|
|
|
|
|
|
|
|
int drm_mode_setcrtc(struct inode *inode, struct file *filp,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
drm_file_t *priv = filp->private_data;
|
|
|
|
drm_device_t *dev = priv->head->dev;
|
|
|
|
struct drm_mode_crtc __user *argp = (void __user *)arg;
|
|
|
|
struct drm_mode_crtc crtc_req;
|
|
|
|
struct drm_crtc *crtc;
|
|
|
|
struct drm_output **output_set = NULL, *output;
|
|
|
|
struct drm_display_mode *mode;
|
2007-04-11 16:54:31 -06:00
|
|
|
struct drm_framebuffer *fb = NULL;
|
2007-04-05 02:01:02 -06:00
|
|
|
int retcode = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (copy_from_user(&crtc_req, argp, sizeof(crtc_req)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
crtc = idr_find(&dev->mode_config.crtc_idr, crtc_req.crtc_id);
|
2007-04-11 19:43:13 -06:00
|
|
|
if (!crtc || (crtc->id != crtc_req.crtc_id)) {
|
2007-04-09 22:49:49 -06:00
|
|
|
DRM_DEBUG("Unknown CRTC ID %d\n", crtc_req.crtc_id);
|
2007-04-05 02:01:02 -06:00
|
|
|
return -EINVAL;
|
2007-04-09 22:49:49 -06:00
|
|
|
}
|
2007-04-05 02:01:02 -06:00
|
|
|
|
|
|
|
if (crtc_req.mode) {
|
2007-04-11 16:54:31 -06:00
|
|
|
|
|
|
|
/* if we have a mode we need a framebuffer */
|
|
|
|
if (crtc_req.fb_id) {
|
|
|
|
fb = idr_find(&dev->mode_config.crtc_idr, crtc_req.fb_id);
|
|
|
|
if (!fb || (fb->id != crtc_req.fb_id)) {
|
|
|
|
DRM_DEBUG("Unknown FB ID%d\n", crtc_req.fb_id);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2007-04-10 02:56:02 -06:00
|
|
|
mode = idr_find(&dev->mode_config.crtc_idr, crtc_req.mode);
|
2007-04-11 19:43:13 -06:00
|
|
|
if (!mode || (mode->mode_id != crtc_req.mode)) {
|
|
|
|
struct drm_output *output;
|
|
|
|
|
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list, head) {
|
|
|
|
list_for_each_entry(mode, &output->modes, head) {
|
|
|
|
drm_mode_debug_printmodeline(dev, mode);
|
2007-04-09 22:49:49 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DRM_DEBUG("Unknown mode id %d, %p\n", crtc_req.mode, mode);
|
2007-04-05 02:01:02 -06:00
|
|
|
return -EINVAL;
|
2007-04-09 22:49:49 -06:00
|
|
|
}
|
2007-04-05 02:01:02 -06:00
|
|
|
} else
|
|
|
|
mode = NULL;
|
|
|
|
|
2007-04-09 22:49:49 -06:00
|
|
|
if (crtc_req.count_outputs == 0 && mode) {
|
|
|
|
DRM_DEBUG("Count outputs is 0 but mode set\n");
|
2007-04-05 02:01:02 -06:00
|
|
|
return -EINVAL;
|
2007-04-09 22:49:49 -06:00
|
|
|
}
|
2007-04-05 02:01:02 -06:00
|
|
|
|
2007-04-11 16:54:31 -06:00
|
|
|
if (crtc_req.count_outputs > 0 && !mode && !fb) {
|
|
|
|
DRM_DEBUG("Count outputs is %d but no mode or fb set\n", crtc_req.count_outputs);
|
2007-04-05 02:01:02 -06:00
|
|
|
return -EINVAL;
|
2007-04-09 22:49:49 -06:00
|
|
|
}
|
2007-04-05 02:01:02 -06:00
|
|
|
|
|
|
|
if (crtc_req.count_outputs > 0) {
|
|
|
|
u32 out_id;
|
|
|
|
output_set = kmalloc(crtc_req.count_outputs * sizeof(struct drm_output *), GFP_KERNEL);
|
|
|
|
if (!output_set)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2007-04-09 22:49:49 -06:00
|
|
|
for (i = 0; i < crtc_req.count_outputs; i++) {
|
2007-04-05 02:01:02 -06:00
|
|
|
if (get_user(out_id, &crtc_req.set_outputs[i]))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
output = idr_find(&dev->mode_config.crtc_idr, out_id);
|
2007-04-09 22:49:49 -06:00
|
|
|
if (!output || (out_id != output->id)) {
|
|
|
|
DRM_DEBUG("Output id %d unknown\n", out_id);
|
2007-04-05 02:01:02 -06:00
|
|
|
return -EINVAL;
|
2007-04-09 22:49:49 -06:00
|
|
|
}
|
2007-04-05 02:01:02 -06:00
|
|
|
|
|
|
|
output_set[i] = output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-11 16:54:31 -06:00
|
|
|
retcode = drm_crtc_set_config(crtc, &crtc_req, mode, output_set, fb);
|
2007-04-05 02:01:02 -06:00
|
|
|
return retcode;
|
|
|
|
}
|
2007-04-10 02:44:47 -06:00
|
|
|
|
|
|
|
/* Add framebuffer ioctl */
|
|
|
|
int drm_mode_addfb(struct inode *inode, struct file *filp,
|
2007-04-09 22:49:49 -06:00
|
|
|
unsigned int cmd, unsigned long arg)
|
2007-04-10 02:44:47 -06:00
|
|
|
{
|
|
|
|
struct drm_file *priv = filp->private_data;
|
|
|
|
struct drm_device *dev = priv->head->dev;
|
|
|
|
struct drm_mode_fb_cmd __user *argp = (void __user *)arg;
|
|
|
|
struct drm_mode_fb_cmd r;
|
2007-04-09 22:49:49 -06:00
|
|
|
struct drm_mode_config *config = &dev->mode_config;
|
2007-04-10 02:44:47 -06:00
|
|
|
struct drm_framebuffer *fb;
|
|
|
|
struct drm_buffer_object *bo;
|
2007-04-09 22:49:49 -06:00
|
|
|
int ret;
|
2007-04-10 02:44:47 -06:00
|
|
|
|
2007-04-09 19:51:31 -06:00
|
|
|
if (copy_from_user(&r, argp, sizeof(r)))
|
2007-04-10 02:44:47 -06:00
|
|
|
return -EFAULT;
|
|
|
|
|
2007-04-09 19:51:31 -06:00
|
|
|
if ((config->min_width > r.width) || (r.width > config->max_width)) {
|
|
|
|
DRM_ERROR("mode new framebuffer width not within limits\n");
|
2007-04-10 02:44:47 -06:00
|
|
|
return -EINVAL;
|
2007-04-09 22:49:49 -06:00
|
|
|
}
|
2007-04-09 19:51:31 -06:00
|
|
|
if ((config->min_height > r.height) || (r.height > config->max_height)) {
|
|
|
|
DRM_ERROR("mode new framebuffer height not within limits\n");
|
2007-04-10 02:44:47 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO check limits are okay */
|
2007-04-09 22:49:49 -06:00
|
|
|
ret = drm_get_buffer_object(dev, &bo, r.handle);
|
|
|
|
if (ret || !bo)
|
|
|
|
return -EINVAL;
|
2007-04-10 02:44:47 -06:00
|
|
|
|
|
|
|
/* TODO check buffer is sufficently large */
|
|
|
|
/* TODO setup destructor callback */
|
|
|
|
|
|
|
|
fb = drm_framebuffer_create(dev);
|
|
|
|
if(!fb)
|
|
|
|
return -EINVAL;;
|
|
|
|
|
2007-04-11 01:13:45 -06:00
|
|
|
fb->width = r.width;
|
|
|
|
fb->height = r.height;
|
|
|
|
fb->pitch = r.pitch;
|
2007-04-10 02:44:47 -06:00
|
|
|
fb->bits_per_pixel = r.bpp;
|
2007-04-11 01:13:45 -06:00
|
|
|
fb->depth = r.depth;
|
|
|
|
fb->offset = bo->offset;
|
|
|
|
fb->bo = bo;
|
2007-04-10 02:44:47 -06:00
|
|
|
|
2007-04-09 22:49:49 -06:00
|
|
|
r.buffer_id = fb->id;
|
|
|
|
|
|
|
|
/* bind the fb to the crtc for now */
|
|
|
|
{
|
|
|
|
struct drm_crtc *crtc;
|
|
|
|
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
|
|
|
|
crtc->fb = fb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (copy_to_user(argp, &r, sizeof(r)))
|
|
|
|
return -EFAULT;
|
2007-04-10 02:44:47 -06:00
|
|
|
|
2007-04-11 00:33:03 -06:00
|
|
|
drmfb_probe(dev, fb);
|
2007-04-10 02:44:47 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int drm_mode_rmfb(struct inode *inode, struct file *filp,
|
2007-04-09 22:49:49 -06:00
|
|
|
unsigned int cmd, unsigned long arg)
|
2007-04-10 02:44:47 -06:00
|
|
|
{
|
|
|
|
drm_file_t *priv = filp->private_data;
|
|
|
|
drm_device_t *dev = priv->head->dev;
|
|
|
|
struct drm_framebuffer *fb = 0;
|
|
|
|
uint32_t id = arg;
|
|
|
|
|
2007-04-10 02:56:02 -06:00
|
|
|
fb = idr_find(&dev->mode_config.crtc_idr, id);
|
2007-04-10 02:44:47 -06:00
|
|
|
/* TODO check that we realy get a framebuffer back. */
|
|
|
|
if (!fb || (id != fb->id)) {
|
|
|
|
DRM_ERROR("mode invalid framebuffer id\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2007-04-11 00:33:03 -06:00
|
|
|
drmfb_remove(dev, fb);
|
2007-04-10 02:44:47 -06:00
|
|
|
/* TODO check if we own the buffer */
|
|
|
|
/* TODO release all crtc connected to the framebuffer */
|
2007-04-10 21:19:30 -06:00
|
|
|
/* bind the fb to the crtc for now */
|
|
|
|
{
|
|
|
|
struct drm_crtc *crtc;
|
|
|
|
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
|
|
|
|
if (crtc->fb == fb)
|
|
|
|
crtc->fb = NULL;
|
|
|
|
}
|
|
|
|
}
|
2007-04-10 02:44:47 -06:00
|
|
|
/* TODO unhock the destructor from the buffer object */
|
|
|
|
|
|
|
|
drm_framebuffer_destroy(fb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2007-04-10 21:19:30 -06:00
|
|
|
|
2007-04-11 16:45:40 -06:00
|
|
|
int drm_mode_getfb(struct inode *inode, struct file *filp,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
drm_file_t *priv = filp->private_data;
|
|
|
|
drm_device_t *dev = priv->head->dev;
|
|
|
|
struct drm_mode_fb_cmd __user *argp = (void __user *)arg;
|
|
|
|
struct drm_mode_fb_cmd r;
|
|
|
|
struct drm_framebuffer *fb;
|
|
|
|
|
|
|
|
if (copy_from_user(&r, argp, sizeof(r)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
fb = idr_find(&dev->mode_config.crtc_idr, r.buffer_id);
|
|
|
|
if (!fb || (r.buffer_id != fb->id)) {
|
|
|
|
DRM_ERROR("invalid framebuffer id\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
r.height = fb->height;
|
|
|
|
r.width = fb->width;
|
|
|
|
r.depth = fb->depth;
|
|
|
|
r.bpp = fb->bits_per_pixel;
|
|
|
|
r.handle = fb->bo->base.hash.key;
|
|
|
|
r.pitch = fb->pitch;
|
|
|
|
|
|
|
|
if (copy_to_user(argp, &r, sizeof(r)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|