Commit d45e32c9 authored by Thomas Zimmermann's avatar Thomas Zimmermann

drm/mgag200: Call mgag200_device_probe_vram() from per-model init

Call mgag200_device_probe_vram() from each model's initializer. The
G200EW3 uses a special helper with additional instructions.
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: default avatarJocelyn Falempe <jfalempe@redhat.com>
Tested-by: default avatarJocelyn Falempe <jfalempe@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220601112522.5774-5-tzimmermann@suse.de
parent ce19021f
...@@ -50,6 +50,45 @@ int mgag200_init_pci_options(struct pci_dev *pdev, u32 option, u32 option2) ...@@ -50,6 +50,45 @@ int mgag200_init_pci_options(struct pci_dev *pdev, u32 option, u32 option2)
return 0; return 0;
} }
resource_size_t mgag200_probe_vram(void __iomem *mem, resource_size_t size)
{
int offset;
int orig;
int test1, test2;
int orig1, orig2;
size_t vram_size;
/* Probe */
orig = ioread16(mem);
iowrite16(0, mem);
vram_size = size;
for (offset = 0x100000; offset < vram_size; offset += 0x4000) {
orig1 = ioread8(mem + offset);
orig2 = ioread8(mem + offset + 0x100);
iowrite16(0xaa55, mem + offset);
iowrite16(0xaa55, mem + offset + 0x100);
test1 = ioread16(mem + offset);
test2 = ioread16(mem);
iowrite16(orig1, mem + offset);
iowrite16(orig2, mem + offset + 0x100);
if (test1 != 0xaa55)
break;
if (test2)
break;
}
iowrite16(orig, mem);
return offset - 65536;
}
/* /*
* DRM driver * DRM driver
*/ */
......
...@@ -214,7 +214,7 @@ struct mga_device { ...@@ -214,7 +214,7 @@ struct mga_device {
struct mga_mc mc; struct mga_mc mc;
void __iomem *vram; void __iomem *vram;
size_t vram_fb_available; resource_size_t vram_available;
enum mga_type type; enum mga_type type;
...@@ -257,6 +257,7 @@ static inline struct mgag200_g200se_device *to_mgag200_g200se_device(struct drm_ ...@@ -257,6 +257,7 @@ static inline struct mgag200_g200se_device *to_mgag200_g200se_device(struct drm_
/* mgag200_drv.c */ /* mgag200_drv.c */
int mgag200_init_pci_options(struct pci_dev *pdev, u32 option, u32 option2); int mgag200_init_pci_options(struct pci_dev *pdev, u32 option, u32 option2);
resource_size_t mgag200_probe_vram(void __iomem *mem, resource_size_t size);
int mgag200_regs_init(struct mga_device *mdev); int mgag200_regs_init(struct mga_device *mdev);
/* mgag200_<device type>.c */ /* mgag200_<device type>.c */
...@@ -278,7 +279,8 @@ struct mga_device *mgag200_g200ew3_device_create(struct pci_dev *pdev, const str ...@@ -278,7 +279,8 @@ struct mga_device *mgag200_g200ew3_device_create(struct pci_dev *pdev, const str
enum mga_type type, unsigned long flags); enum mga_type type, unsigned long flags);
/* mgag200_mode.c */ /* mgag200_mode.c */
int mgag200_modeset_init(struct mga_device *mdev); resource_size_t mgag200_device_probe_vram(struct mga_device *mdev);
int mgag200_modeset_init(struct mga_device *mdev, resource_size_t vram_fb_available);
/* mgag200_i2c.c */ /* mgag200_i2c.c */
int mgag200_i2c_init(struct mga_device *mdev, struct mga_i2c_chan *i2c); int mgag200_i2c_init(struct mga_device *mdev, struct mga_i2c_chan *i2c);
......
...@@ -162,6 +162,7 @@ struct mga_device *mgag200_g200_device_create(struct pci_dev *pdev, const struct ...@@ -162,6 +162,7 @@ struct mga_device *mgag200_g200_device_create(struct pci_dev *pdev, const struct
struct mgag200_g200_device *g200; struct mgag200_g200_device *g200;
struct mga_device *mdev; struct mga_device *mdev;
struct drm_device *dev; struct drm_device *dev;
resource_size_t vram_available;
int ret; int ret;
g200 = devm_drm_dev_alloc(&pdev->dev, drv, struct mgag200_g200_device, base.base); g200 = devm_drm_dev_alloc(&pdev->dev, drv, struct mgag200_g200_device, base.base);
...@@ -189,7 +190,9 @@ struct mga_device *mgag200_g200_device_create(struct pci_dev *pdev, const struct ...@@ -189,7 +190,9 @@ struct mga_device *mgag200_g200_device_create(struct pci_dev *pdev, const struct
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
ret = mgag200_modeset_init(mdev); vram_available = mgag200_device_probe_vram(mdev);
ret = mgag200_modeset_init(mdev, vram_available);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
......
...@@ -15,6 +15,7 @@ struct mga_device *mgag200_g200eh_device_create(struct pci_dev *pdev, const stru ...@@ -15,6 +15,7 @@ struct mga_device *mgag200_g200eh_device_create(struct pci_dev *pdev, const stru
{ {
struct mga_device *mdev; struct mga_device *mdev;
struct drm_device *dev; struct drm_device *dev;
resource_size_t vram_available;
int ret; int ret;
mdev = devm_drm_dev_alloc(&pdev->dev, drv, struct mga_device, base); mdev = devm_drm_dev_alloc(&pdev->dev, drv, struct mga_device, base);
...@@ -39,7 +40,9 @@ struct mga_device *mgag200_g200eh_device_create(struct pci_dev *pdev, const stru ...@@ -39,7 +40,9 @@ struct mga_device *mgag200_g200eh_device_create(struct pci_dev *pdev, const stru
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
ret = mgag200_modeset_init(mdev); vram_available = mgag200_device_probe_vram(mdev);
ret = mgag200_modeset_init(mdev, vram_available);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
......
...@@ -16,6 +16,7 @@ struct mga_device *mgag200_g200eh3_device_create(struct pci_dev *pdev, ...@@ -16,6 +16,7 @@ struct mga_device *mgag200_g200eh3_device_create(struct pci_dev *pdev,
{ {
struct mga_device *mdev; struct mga_device *mdev;
struct drm_device *dev; struct drm_device *dev;
resource_size_t vram_available;
int ret; int ret;
mdev = devm_drm_dev_alloc(&pdev->dev, drv, struct mga_device, base); mdev = devm_drm_dev_alloc(&pdev->dev, drv, struct mga_device, base);
...@@ -40,7 +41,9 @@ struct mga_device *mgag200_g200eh3_device_create(struct pci_dev *pdev, ...@@ -40,7 +41,9 @@ struct mga_device *mgag200_g200eh3_device_create(struct pci_dev *pdev,
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
ret = mgag200_modeset_init(mdev); vram_available = mgag200_device_probe_vram(mdev);
ret = mgag200_modeset_init(mdev, vram_available);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
......
...@@ -15,6 +15,7 @@ struct mga_device *mgag200_g200er_device_create(struct pci_dev *pdev, const stru ...@@ -15,6 +15,7 @@ struct mga_device *mgag200_g200er_device_create(struct pci_dev *pdev, const stru
{ {
struct mga_device *mdev; struct mga_device *mdev;
struct drm_device *dev; struct drm_device *dev;
resource_size_t vram_available;
int ret; int ret;
mdev = devm_drm_dev_alloc(&pdev->dev, drv, struct mga_device, base); mdev = devm_drm_dev_alloc(&pdev->dev, drv, struct mga_device, base);
...@@ -35,7 +36,9 @@ struct mga_device *mgag200_g200er_device_create(struct pci_dev *pdev, const stru ...@@ -35,7 +36,9 @@ struct mga_device *mgag200_g200er_device_create(struct pci_dev *pdev, const stru
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
ret = mgag200_modeset_init(mdev); vram_available = mgag200_device_probe_vram(mdev);
ret = mgag200_modeset_init(mdev, vram_available);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
......
...@@ -15,6 +15,7 @@ struct mga_device *mgag200_g200ev_device_create(struct pci_dev *pdev, const stru ...@@ -15,6 +15,7 @@ struct mga_device *mgag200_g200ev_device_create(struct pci_dev *pdev, const stru
{ {
struct mga_device *mdev; struct mga_device *mdev;
struct drm_device *dev; struct drm_device *dev;
resource_size_t vram_available;
int ret; int ret;
mdev = devm_drm_dev_alloc(&pdev->dev, drv, struct mga_device, base); mdev = devm_drm_dev_alloc(&pdev->dev, drv, struct mga_device, base);
...@@ -39,7 +40,9 @@ struct mga_device *mgag200_g200ev_device_create(struct pci_dev *pdev, const stru ...@@ -39,7 +40,9 @@ struct mga_device *mgag200_g200ev_device_create(struct pci_dev *pdev, const stru
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
ret = mgag200_modeset_init(mdev); vram_available = mgag200_device_probe_vram(mdev);
ret = mgag200_modeset_init(mdev, vram_available);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
......
...@@ -10,12 +10,22 @@ ...@@ -10,12 +10,22 @@
* DRM device * DRM device
*/ */
static resource_size_t mgag200_g200ew3_device_probe_vram(struct mga_device *mdev)
{
resource_size_t vram_size = mdev->mc.vram_size;
if (vram_size >= 0x1000000)
vram_size = vram_size - 0x400000;
return mgag200_probe_vram(mdev->vram, vram_size);
}
struct mga_device *mgag200_g200ew3_device_create(struct pci_dev *pdev, struct mga_device *mgag200_g200ew3_device_create(struct pci_dev *pdev,
const struct drm_driver *drv, const struct drm_driver *drv,
enum mga_type type, unsigned long flags) enum mga_type type, unsigned long flags)
{ {
struct mga_device *mdev; struct mga_device *mdev;
struct drm_device *dev; struct drm_device *dev;
resource_size_t vram_available;
int ret; int ret;
mdev = devm_drm_dev_alloc(&pdev->dev, drv, struct mga_device, base); mdev = devm_drm_dev_alloc(&pdev->dev, drv, struct mga_device, base);
...@@ -40,7 +50,9 @@ struct mga_device *mgag200_g200ew3_device_create(struct pci_dev *pdev, ...@@ -40,7 +50,9 @@ struct mga_device *mgag200_g200ew3_device_create(struct pci_dev *pdev,
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
ret = mgag200_modeset_init(mdev); vram_available = mgag200_g200ew3_device_probe_vram(mdev);
ret = mgag200_modeset_init(mdev, vram_available);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
......
...@@ -49,6 +49,7 @@ struct mga_device *mgag200_g200se_device_create(struct pci_dev *pdev, const stru ...@@ -49,6 +49,7 @@ struct mga_device *mgag200_g200se_device_create(struct pci_dev *pdev, const stru
struct mgag200_g200se_device *g200se; struct mgag200_g200se_device *g200se;
struct mga_device *mdev; struct mga_device *mdev;
struct drm_device *dev; struct drm_device *dev;
resource_size_t vram_available;
int ret; int ret;
g200se = devm_drm_dev_alloc(&pdev->dev, drv, struct mgag200_g200se_device, base.base); g200se = devm_drm_dev_alloc(&pdev->dev, drv, struct mgag200_g200se_device, base.base);
...@@ -76,7 +77,9 @@ struct mga_device *mgag200_g200se_device_create(struct pci_dev *pdev, const stru ...@@ -76,7 +77,9 @@ struct mga_device *mgag200_g200se_device_create(struct pci_dev *pdev, const stru
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
ret = mgag200_modeset_init(mdev); vram_available = mgag200_device_probe_vram(mdev);
ret = mgag200_modeset_init(mdev, vram_available);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
......
...@@ -15,6 +15,7 @@ struct mga_device *mgag200_g200wb_device_create(struct pci_dev *pdev, const stru ...@@ -15,6 +15,7 @@ struct mga_device *mgag200_g200wb_device_create(struct pci_dev *pdev, const stru
{ {
struct mga_device *mdev; struct mga_device *mdev;
struct drm_device *dev; struct drm_device *dev;
resource_size_t vram_available;
int ret; int ret;
mdev = devm_drm_dev_alloc(&pdev->dev, drv, struct mga_device, base); mdev = devm_drm_dev_alloc(&pdev->dev, drv, struct mga_device, base);
...@@ -39,7 +40,9 @@ struct mga_device *mgag200_g200wb_device_create(struct pci_dev *pdev, const stru ...@@ -39,7 +40,9 @@ struct mga_device *mgag200_g200wb_device_create(struct pci_dev *pdev, const stru
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
ret = mgag200_modeset_init(mdev); vram_available = mgag200_device_probe_vram(mdev);
ret = mgag200_modeset_init(mdev, vram_available);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
......
...@@ -32,49 +32,6 @@ ...@@ -32,49 +32,6 @@
#include "mgag200_drv.h" #include "mgag200_drv.h"
static size_t mgag200_probe_vram(struct mga_device *mdev, void __iomem *mem,
size_t size)
{
int offset;
int orig;
int test1, test2;
int orig1, orig2;
size_t vram_size;
/* Probe */
orig = ioread16(mem);
iowrite16(0, mem);
vram_size = size;
if ((mdev->type == G200_EW3) && (vram_size >= 0x1000000))
vram_size = vram_size - 0x400000;
for (offset = 0x100000; offset < vram_size; offset += 0x4000) {
orig1 = ioread8(mem + offset);
orig2 = ioread8(mem + offset + 0x100);
iowrite16(0xaa55, mem + offset);
iowrite16(0xaa55, mem + offset + 0x100);
test1 = ioread16(mem + offset);
test2 = ioread16(mem);
iowrite16(orig1, mem + offset);
iowrite16(orig2, mem + offset + 0x100);
if (test1 != 0xaa55)
break;
if (test2)
break;
}
iowrite16(orig, mem);
return offset - 65536;
}
int mgag200_mm_init(struct mga_device *mdev) int mgag200_mm_init(struct mga_device *mdev)
{ {
struct drm_device *dev = &mdev->base; struct drm_device *dev = &mdev->base;
...@@ -106,11 +63,9 @@ int mgag200_mm_init(struct mga_device *mdev) ...@@ -106,11 +63,9 @@ int mgag200_mm_init(struct mga_device *mdev)
if (!mdev->vram) if (!mdev->vram)
return -ENOMEM; return -ENOMEM;
mdev->mc.vram_size = mgag200_probe_vram(mdev, mdev->vram, len); mdev->mc.vram_size = len;
mdev->mc.vram_base = start; mdev->mc.vram_base = start;
mdev->mc.vram_window = len; mdev->mc.vram_window = len;
mdev->vram_fb_available = mdev->mc.vram_size;
return 0; return 0;
} }
...@@ -32,6 +32,11 @@ ...@@ -32,6 +32,11 @@
* This file contains setup code for the CRTC. * This file contains setup code for the CRTC.
*/ */
resource_size_t mgag200_device_probe_vram(struct mga_device *mdev)
{
return mgag200_probe_vram(mdev->vram, mdev->mc.vram_size);
}
static void mgag200_crtc_set_gamma_linear(struct mga_device *mdev, static void mgag200_crtc_set_gamma_linear(struct mga_device *mdev,
const struct drm_format_info *format) const struct drm_format_info *format)
{ {
...@@ -1030,7 +1035,7 @@ static enum drm_mode_status mgag200_mode_config_mode_valid(struct drm_device *de ...@@ -1030,7 +1035,7 @@ static enum drm_mode_status mgag200_mode_config_mode_valid(struct drm_device *de
unsigned long fbsize, fbpages, max_fbpages; unsigned long fbsize, fbpages, max_fbpages;
struct mgag200_g200se_device *g200se; struct mgag200_g200se_device *g200se;
max_fbpages = mdev->vram_fb_available >> PAGE_SHIFT; max_fbpages = mdev->vram_available >> PAGE_SHIFT;
fbsize = mode->hdisplay * mode->vdisplay * max_bpp; fbsize = mode->hdisplay * mode->vdisplay * max_bpp;
fbpages = DIV_ROUND_UP(fbsize, PAGE_SIZE); fbpages = DIV_ROUND_UP(fbsize, PAGE_SIZE);
...@@ -1075,7 +1080,7 @@ static const struct drm_mode_config_funcs mgag200_mode_config_funcs = { ...@@ -1075,7 +1080,7 @@ static const struct drm_mode_config_funcs mgag200_mode_config_funcs = {
.atomic_commit = drm_atomic_helper_commit, .atomic_commit = drm_atomic_helper_commit,
}; };
int mgag200_modeset_init(struct mga_device *mdev) int mgag200_modeset_init(struct mga_device *mdev, resource_size_t vram_available)
{ {
struct drm_device *dev = &mdev->base; struct drm_device *dev = &mdev->base;
struct mga_i2c_chan *i2c = &mdev->i2c; struct mga_i2c_chan *i2c = &mdev->i2c;
...@@ -1086,6 +1091,8 @@ int mgag200_modeset_init(struct mga_device *mdev) ...@@ -1086,6 +1091,8 @@ int mgag200_modeset_init(struct mga_device *mdev)
mgag200_init_regs(mdev); mgag200_init_regs(mdev);
mdev->vram_available = vram_available;
ret = drmm_mode_config_init(dev); ret = drmm_mode_config_init(dev);
if (ret) { if (ret) {
drm_err(dev, "drmm_mode_config_init() failed, error %d\n", drm_err(dev, "drmm_mode_config_init() failed, error %d\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment