[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210917072226.17357-1-kuohsiang_chou@aspeedtech.com>
Date: Fri, 17 Sep 2021 15:22:26 +0800
From: KuoHsiang Chou <kuohsiang_chou@...eedtech.com>
To: <tzimmermann@...e.de>, <dri-devel@...ts.freedesktop.org>,
<linux-kernel@...r.kernel.org>
CC: <airlied@...hat.com>, <airlied@...ux.ie>, <daniel@...ll.ch>,
<jenmin_yuan@...eedtech.com>, <kuohsiang_chou@...eedtech.com>,
<arc_sung@...eedtech.com>
Subject: [PATCH] drm/ast: Atomic CR/SR reg R/W
1. Avoid IO-index racing
2. IO-index racing happened on resolustion switching
and mouse moving at the same time
3. System hung while IO-index racing occurred.
Signed-off-by: KuoHsiang Chou <kuohsiang_chou@...eedtech.com>
---
drivers/gpu/drm/ast/ast_main.c | 48 +++++++++++++++++++++++++---------
1 file changed, 36 insertions(+), 12 deletions(-)
diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c
index 79a361867..1d8fa70c5 100644
--- a/drivers/gpu/drm/ast/ast_main.c
+++ b/drivers/gpu/drm/ast/ast_main.c
@@ -41,28 +41,52 @@ void ast_set_index_reg_mask(struct ast_private *ast,
uint32_t base, uint8_t index,
uint8_t mask, uint8_t val)
{
- u8 tmp;
- ast_io_write8(ast, base, index);
- tmp = (ast_io_read8(ast, base + 1) & mask) | val;
- ast_set_index_reg(ast, base, index, tmp);
+ uint16_t volatile usData;
+ uint8_t volatile jData;
+
+ do {
+ ast_io_write8(ast, base, index);
+ usData = ast_io_read16(ast, base);
+ } while ((uint8_t)(usData) != index);
+
+ jData = (uint8_t)(usData >> 8);
+ jData &= mask;
+ jData |= val;
+ usData = ((uint16_t) jData << 8) | (uint16_t) index;
+ ast_io_write16(ast, base, usData);
}
uint8_t ast_get_index_reg(struct ast_private *ast,
uint32_t base, uint8_t index)
{
- uint8_t ret;
- ast_io_write8(ast, base, index);
- ret = ast_io_read8(ast, base + 1);
- return ret;
+ uint16_t volatile usData;
+ uint8_t volatile jData;
+
+ do {
+ ast_io_write8(ast, base, index);
+ usData = ast_io_read16(ast, base);
+ } while ((uint8_t)(usData) != index);
+
+ jData = (uint8_t)(usData >> 8);
+
+ return jData;
}
uint8_t ast_get_index_reg_mask(struct ast_private *ast,
uint32_t base, uint8_t index, uint8_t mask)
{
- uint8_t ret;
- ast_io_write8(ast, base, index);
- ret = ast_io_read8(ast, base + 1) & mask;
- return ret;
+ uint16_t volatile usData;
+ uint8_t volatile jData;
+
+ do {
+ ast_io_write8(ast, base, index);
+ usData = ast_io_read16(ast, base);
+ } while ((uint8_t)(usData) != index);
+
+ jData = (uint8_t)(usData >> 8);
+ jData &= mask;
+
+ return jData;
}
static void ast_detect_config_mode(struct drm_device *dev, u32 *scu_rev)
--
2.18.4
Powered by blists - more mailing lists