2013-12-18 00:04:46 +07:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bochs.h"
|
2019-01-11 12:37:41 +07:00
|
|
|
#include <drm/drm_atomic_helper.h>
|
2014-10-29 16:03:57 +07:00
|
|
|
#include <drm/drm_plane_helper.h>
|
2019-01-11 12:37:41 +07:00
|
|
|
#include <drm/drm_atomic_uapi.h>
|
2013-12-18 00:04:46 +07:00
|
|
|
|
|
|
|
static int defx = 1024;
|
|
|
|
static int defy = 768;
|
|
|
|
|
|
|
|
module_param(defx, int, 0444);
|
|
|
|
module_param(defy, int, 0444);
|
|
|
|
MODULE_PARM_DESC(defx, "default x resolution");
|
|
|
|
MODULE_PARM_DESC(defy, "default y resolution");
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2019-01-11 12:37:40 +07:00
|
|
|
static void bochs_crtc_mode_set_nofb(struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
struct bochs_device *bochs =
|
|
|
|
container_of(crtc, struct bochs_device, crtc);
|
|
|
|
|
|
|
|
bochs_hw_setmode(bochs, &crtc->mode);
|
|
|
|
}
|
|
|
|
|
2019-01-11 12:37:39 +07:00
|
|
|
static void bochs_crtc_atomic_enable(struct drm_crtc *crtc,
|
|
|
|
struct drm_crtc_state *old_crtc_state)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bochs_crtc_atomic_flush(struct drm_crtc *crtc,
|
|
|
|
struct drm_crtc_state *old_crtc_state)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = crtc->dev;
|
|
|
|
struct drm_pending_vblank_event *event;
|
|
|
|
|
|
|
|
if (crtc->state && crtc->state->event) {
|
|
|
|
unsigned long irqflags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dev->event_lock, irqflags);
|
|
|
|
event = crtc->state->event;
|
|
|
|
crtc->state->event = NULL;
|
|
|
|
drm_crtc_send_vblank_event(crtc, event);
|
|
|
|
spin_unlock_irqrestore(&dev->event_lock, irqflags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-18 00:04:46 +07:00
|
|
|
/* These provide the minimum set of functions required to handle a CRTC */
|
|
|
|
static const struct drm_crtc_funcs bochs_crtc_funcs = {
|
2019-01-11 12:37:42 +07:00
|
|
|
.set_config = drm_atomic_helper_set_config,
|
2013-12-18 00:04:46 +07:00
|
|
|
.destroy = drm_crtc_cleanup,
|
2019-01-11 12:37:43 +07:00
|
|
|
.page_flip = drm_atomic_helper_page_flip,
|
2019-01-11 12:37:41 +07:00
|
|
|
.reset = drm_atomic_helper_crtc_reset,
|
|
|
|
.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
|
|
|
|
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
|
2013-12-18 00:04:46 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct drm_crtc_helper_funcs bochs_helper_funcs = {
|
2019-01-11 12:37:40 +07:00
|
|
|
.mode_set_nofb = bochs_crtc_mode_set_nofb,
|
2019-01-11 12:37:39 +07:00
|
|
|
.atomic_enable = bochs_crtc_atomic_enable,
|
|
|
|
.atomic_flush = bochs_crtc_atomic_flush,
|
2013-12-18 00:04:46 +07:00
|
|
|
};
|
|
|
|
|
2018-09-21 20:47:01 +07:00
|
|
|
static const uint32_t bochs_formats[] = {
|
2018-09-21 20:47:02 +07:00
|
|
|
DRM_FORMAT_XRGB8888,
|
|
|
|
DRM_FORMAT_BGRX8888,
|
2018-09-21 20:47:01 +07:00
|
|
|
};
|
|
|
|
|
2019-01-11 12:37:41 +07:00
|
|
|
static void bochs_plane_atomic_update(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *old_state)
|
|
|
|
{
|
|
|
|
struct bochs_device *bochs = plane->dev->dev_private;
|
|
|
|
struct bochs_bo *bo;
|
|
|
|
|
|
|
|
if (!plane->state->fb)
|
|
|
|
return;
|
|
|
|
bo = gem_to_bochs_bo(plane->state->fb->obj[0]);
|
|
|
|
bochs_hw_setbase(bochs,
|
|
|
|
plane->state->crtc_x,
|
|
|
|
plane->state->crtc_y,
|
|
|
|
bo->bo.offset);
|
|
|
|
bochs_hw_setformat(bochs, plane->state->fb->format);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bochs_plane_prepare_fb(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *new_state)
|
|
|
|
{
|
|
|
|
struct bochs_bo *bo;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!new_state->fb)
|
|
|
|
return 0;
|
|
|
|
bo = gem_to_bochs_bo(new_state->fb->obj[0]);
|
|
|
|
|
|
|
|
ret = ttm_bo_reserve(&bo->bo, true, false, NULL);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2019-01-11 12:37:47 +07:00
|
|
|
ret = bochs_bo_pin(bo, TTM_PL_FLAG_VRAM);
|
2019-01-11 12:37:41 +07:00
|
|
|
ttm_bo_unreserve(&bo->bo);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bochs_plane_cleanup_fb(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *old_state)
|
|
|
|
{
|
|
|
|
struct bochs_bo *bo;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!old_state->fb)
|
|
|
|
return;
|
|
|
|
bo = gem_to_bochs_bo(old_state->fb->obj[0]);
|
|
|
|
ret = ttm_bo_reserve(&bo->bo, true, false, NULL);
|
|
|
|
if (ret)
|
|
|
|
return;
|
|
|
|
bochs_bo_unpin(bo);
|
|
|
|
ttm_bo_unreserve(&bo->bo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_plane_helper_funcs bochs_plane_helper_funcs = {
|
|
|
|
.atomic_update = bochs_plane_atomic_update,
|
|
|
|
.prepare_fb = bochs_plane_prepare_fb,
|
|
|
|
.cleanup_fb = bochs_plane_cleanup_fb,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct drm_plane_funcs bochs_plane_funcs = {
|
|
|
|
.update_plane = drm_atomic_helper_update_plane,
|
|
|
|
.disable_plane = drm_atomic_helper_disable_plane,
|
|
|
|
.destroy = drm_primary_helper_destroy,
|
|
|
|
.reset = drm_atomic_helper_plane_reset,
|
|
|
|
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
|
|
|
|
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
|
|
|
|
};
|
|
|
|
|
2018-09-21 20:47:01 +07:00
|
|
|
static struct drm_plane *bochs_primary_plane(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct drm_plane *primary;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
primary = kzalloc(sizeof(*primary), GFP_KERNEL);
|
|
|
|
if (primary == NULL) {
|
|
|
|
DRM_DEBUG_KMS("Failed to allocate primary plane\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = drm_universal_plane_init(dev, primary, 0,
|
2019-01-11 12:37:41 +07:00
|
|
|
&bochs_plane_funcs,
|
2018-09-21 20:47:01 +07:00
|
|
|
bochs_formats,
|
|
|
|
ARRAY_SIZE(bochs_formats),
|
|
|
|
NULL,
|
|
|
|
DRM_PLANE_TYPE_PRIMARY, NULL);
|
|
|
|
if (ret) {
|
|
|
|
kfree(primary);
|
2019-01-11 12:37:41 +07:00
|
|
|
return NULL;
|
2018-09-21 20:47:01 +07:00
|
|
|
}
|
|
|
|
|
2019-01-11 12:37:41 +07:00
|
|
|
drm_plane_helper_add(primary, &bochs_plane_helper_funcs);
|
2018-09-21 20:47:01 +07:00
|
|
|
return primary;
|
|
|
|
}
|
|
|
|
|
2013-12-18 00:04:46 +07:00
|
|
|
static void bochs_crtc_init(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct bochs_device *bochs = dev->dev_private;
|
|
|
|
struct drm_crtc *crtc = &bochs->crtc;
|
2018-09-21 20:47:01 +07:00
|
|
|
struct drm_plane *primary = bochs_primary_plane(dev);
|
2013-12-18 00:04:46 +07:00
|
|
|
|
2018-09-21 20:47:01 +07:00
|
|
|
drm_crtc_init_with_planes(dev, crtc, primary, NULL,
|
|
|
|
&bochs_crtc_funcs, NULL);
|
2013-12-18 00:04:46 +07:00
|
|
|
drm_crtc_helper_add(crtc, &bochs_helper_funcs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_encoder_funcs bochs_encoder_encoder_funcs = {
|
|
|
|
.destroy = drm_encoder_cleanup,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void bochs_encoder_init(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct bochs_device *bochs = dev->dev_private;
|
|
|
|
struct drm_encoder *encoder = &bochs->encoder;
|
|
|
|
|
|
|
|
encoder->possible_crtcs = 0x1;
|
|
|
|
drm_encoder_init(dev, encoder, &bochs_encoder_encoder_funcs,
|
drm: Pass 'name' to drm_encoder_init()
Done with coccinelle for the most part. However, it thinks '...' is
part of the semantic patch, so I put an 'int DOTDOTDOT' placeholder
in its place and got rid of it with sed afterwards.
@@
identifier dev, encoder, funcs;
@@
int drm_encoder_init(struct drm_device *dev,
struct drm_encoder *encoder,
const struct drm_encoder_funcs *funcs,
int encoder_type
+ ,const char *name, int DOTDOTDOT
)
{ ... }
@@
identifier dev, encoder, funcs;
@@
int drm_encoder_init(struct drm_device *dev,
struct drm_encoder *encoder,
const struct drm_encoder_funcs *funcs,
int encoder_type
+ ,const char *name, int DOTDOTDOT
);
@@
expression E1, E2, E3, E4;
@@
drm_encoder_init(E1, E2, E3, E4
+ ,NULL
)
v2: Add ', or NULL...' to @name kernel doc (Jani)
Annotate the function with __printf() attribute (Jani)
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1449670818-2966-1-git-send-email-ville.syrjala@linux.intel.com
2015-12-09 21:20:18 +07:00
|
|
|
DRM_MODE_ENCODER_DAC, NULL);
|
2013-12-18 00:04:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-25 14:25:34 +07:00
|
|
|
static int bochs_connector_get_modes(struct drm_connector *connector)
|
2013-12-18 00:04:46 +07:00
|
|
|
{
|
2018-10-30 03:50:48 +07:00
|
|
|
struct bochs_device *bochs =
|
|
|
|
container_of(connector, struct bochs_device, connector);
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
if (bochs->edid)
|
|
|
|
count = drm_add_edid_modes(connector, bochs->edid);
|
2013-12-18 00:04:46 +07:00
|
|
|
|
2018-10-30 03:50:48 +07:00
|
|
|
if (!count) {
|
|
|
|
count = drm_add_modes_noedid(connector, 8192, 8192);
|
|
|
|
drm_set_preferred_mode(connector, defx, defy);
|
|
|
|
}
|
2013-12-18 00:04:46 +07:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2018-04-24 20:14:45 +07:00
|
|
|
static enum drm_mode_status bochs_connector_mode_valid(struct drm_connector *connector,
|
2013-12-18 00:04:46 +07:00
|
|
|
struct drm_display_mode *mode)
|
|
|
|
{
|
|
|
|
struct bochs_device *bochs =
|
|
|
|
container_of(connector, struct bochs_device, connector);
|
|
|
|
unsigned long size = mode->hdisplay * mode->vdisplay * 4;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure we can fit two framebuffers into video memory.
|
|
|
|
* This allows up to 1600x1200 with 16 MB (default size).
|
|
|
|
* If you want more try this:
|
|
|
|
* 'qemu -vga std -global VGA.vgamem_mb=32 $otherargs'
|
|
|
|
*/
|
|
|
|
if (size * 2 > bochs->fb_size)
|
|
|
|
return MODE_BAD;
|
|
|
|
|
|
|
|
return MODE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct drm_encoder *
|
|
|
|
bochs_connector_best_encoder(struct drm_connector *connector)
|
|
|
|
{
|
|
|
|
int enc_id = connector->encoder_ids[0];
|
|
|
|
/* pick the encoder ids */
|
2014-07-18 10:29:57 +07:00
|
|
|
if (enc_id)
|
2017-03-15 13:25:07 +07:00
|
|
|
return drm_encoder_find(connector->dev, NULL, enc_id);
|
2013-12-18 00:04:46 +07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-12-15 18:21:01 +07:00
|
|
|
static const struct drm_connector_helper_funcs bochs_connector_connector_helper_funcs = {
|
2013-12-18 00:04:46 +07:00
|
|
|
.get_modes = bochs_connector_get_modes,
|
|
|
|
.mode_valid = bochs_connector_mode_valid,
|
|
|
|
.best_encoder = bochs_connector_best_encoder,
|
|
|
|
};
|
|
|
|
|
2015-12-15 18:21:01 +07:00
|
|
|
static const struct drm_connector_funcs bochs_connector_connector_funcs = {
|
2013-12-18 00:04:46 +07:00
|
|
|
.dpms = drm_helper_connector_dpms,
|
|
|
|
.fill_modes = drm_helper_probe_single_connector_modes,
|
|
|
|
.destroy = drm_connector_cleanup,
|
2019-01-11 12:37:41 +07:00
|
|
|
.reset = drm_atomic_helper_connector_reset,
|
|
|
|
.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
|
|
|
|
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
|
2013-12-18 00:04:46 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void bochs_connector_init(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct bochs_device *bochs = dev->dev_private;
|
|
|
|
struct drm_connector *connector = &bochs->connector;
|
|
|
|
|
|
|
|
drm_connector_init(dev, connector, &bochs_connector_connector_funcs,
|
|
|
|
DRM_MODE_CONNECTOR_VIRTUAL);
|
|
|
|
drm_connector_helper_add(connector,
|
|
|
|
&bochs_connector_connector_helper_funcs);
|
2014-09-19 15:11:37 +07:00
|
|
|
drm_connector_register(connector);
|
2018-10-30 03:50:48 +07:00
|
|
|
|
|
|
|
bochs_hw_load_edid(bochs);
|
|
|
|
if (bochs->edid) {
|
|
|
|
DRM_INFO("Found EDID data blob.\n");
|
|
|
|
drm_connector_attach_edid_property(connector);
|
|
|
|
drm_connector_update_edid_property(connector, bochs->edid);
|
|
|
|
}
|
2013-12-18 00:04:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int bochs_kms_init(struct bochs_device *bochs)
|
|
|
|
{
|
|
|
|
drm_mode_config_init(bochs->dev);
|
|
|
|
bochs->mode_config_initialized = true;
|
|
|
|
|
|
|
|
bochs->dev->mode_config.max_width = 8192;
|
|
|
|
bochs->dev->mode_config.max_height = 8192;
|
|
|
|
|
|
|
|
bochs->dev->mode_config.fb_base = bochs->fb_base;
|
|
|
|
bochs->dev->mode_config.preferred_depth = 24;
|
|
|
|
bochs->dev->mode_config.prefer_shadow = 0;
|
2018-09-21 20:47:01 +07:00
|
|
|
bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order = true;
|
2013-12-18 00:04:46 +07:00
|
|
|
|
2015-12-15 18:21:01 +07:00
|
|
|
bochs->dev->mode_config.funcs = &bochs_mode_funcs;
|
2013-12-18 00:04:46 +07:00
|
|
|
|
|
|
|
bochs_crtc_init(bochs->dev);
|
|
|
|
bochs_encoder_init(bochs->dev);
|
|
|
|
bochs_connector_init(bochs->dev);
|
2018-07-09 15:40:07 +07:00
|
|
|
drm_connector_attach_encoder(&bochs->connector,
|
2013-12-18 00:04:46 +07:00
|
|
|
&bochs->encoder);
|
|
|
|
|
2019-01-11 12:37:41 +07:00
|
|
|
drm_mode_config_reset(bochs->dev);
|
|
|
|
|
2013-12-18 00:04:46 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bochs_kms_fini(struct bochs_device *bochs)
|
|
|
|
{
|
|
|
|
if (bochs->mode_config_initialized) {
|
|
|
|
drm_mode_config_cleanup(bochs->dev);
|
|
|
|
bochs->mode_config_initialized = false;
|
|
|
|
}
|
|
|
|
}
|