在ARM64上为mali450 GPU内核驱动程序移植4.15之前的计时器代码

时间:2018-12-15 19:40:17

标签: linux-kernel driver armbian arm64

我有一个基于Amlogic S905X ARM64 SoC的旧电视盒,即Tanix TX5,该电视盒最初在其上运行Android。我不喜欢被硬件限制,所以我密切关注Armbian项目的进展,最近我安装了5.67版本,该版本基于Linux 4.19.6上的Ubuntu Bionic。 >

一切正常,有适用于以太网,wifi,蓝牙等的驱动程序,但不幸的是,没有包含支持集成mali450 gpu的内核驱动程序。 hdmi输出确实可以工作,但是Xorg在fbdev上运行,并且屏幕更新非常缓慢,无法全屏观看视频。我不太确定这是什么故事,但显然amlogic会将其当前版本的驱动程序保留给自己。但是,通过访问他们的FTP站点,我发现了内核驱动程序(http://openlinux.amlogic.com:8000/download/ARM/gpu/gpu-2016-08-18-fe6d7b1d1b.tar.gz)的旧源代码树。它已经过时了,但是我在将其移植到当前内核方面取得了一些进展,到目前为止,大多数修复都很容易。现在,我可以编译大约一半的源文件了。

我应该澄清我不是一个Linux开发人员,我什至不是C开发人员……我很迷糊,我知道足够危险,而且我很上进。我的日常交易是C#,所以我或多或少地知道自己在做什么。

我当前遇到的问题是与mali / linux / mali_osk_timers.c有关。这是原始代码:

/*
 * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved.
 * 
 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
 * 
 * A copy of the licence is included with the program, and can also be obtained from Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

/**
 * @file mali_osk_timers.c
 * Implementation of the OS abstraction layer for the kernel device driver
 */

#include <linux/timer.h>
#include <linux/slab.h>
#include "mali_osk.h"
#include "mali_kernel_common.h"

struct _mali_osk_timer_t_struct {
    struct timer_list timer;
};

typedef void (*timer_timeout_function_t)(unsigned long);

_mali_osk_timer_t *_mali_osk_timer_init(void)
{
    _mali_osk_timer_t *t = (_mali_osk_timer_t *)kmalloc(sizeof(_mali_osk_timer_t), GFP_KERNEL);
    if (NULL != t) init_timer(&t->timer);
    return t;
}

void _mali_osk_timer_add(_mali_osk_timer_t *tim, unsigned long ticks_to_expire)
{
    MALI_DEBUG_ASSERT_POINTER(tim);
    tim->timer.expires = jiffies + ticks_to_expire;
    add_timer(&(tim->timer));
}

void _mali_osk_timer_mod(_mali_osk_timer_t *tim, unsigned long ticks_to_expire)
{
    MALI_DEBUG_ASSERT_POINTER(tim);
    mod_timer(&(tim->timer), jiffies + ticks_to_expire);
}

void _mali_osk_timer_del(_mali_osk_timer_t *tim)
{
    MALI_DEBUG_ASSERT_POINTER(tim);
    del_timer_sync(&(tim->timer));
}

void _mali_osk_timer_del_async(_mali_osk_timer_t *tim)
{
    MALI_DEBUG_ASSERT_POINTER(tim);
    del_timer(&(tim->timer));
}

mali_bool _mali_osk_timer_pending(_mali_osk_timer_t *tim)
{
    MALI_DEBUG_ASSERT_POINTER(tim);
    return 1 == timer_pending(&(tim->timer));
}

void _mali_osk_timer_setcallback(_mali_osk_timer_t *tim, _mali_osk_timer_callback_t callback, void *data)
{
    MALI_DEBUG_ASSERT_POINTER(tim);
    tim->timer.data = (unsigned long)data;
    tim->timer.function = (timer_timeout_function_t)callback;
}

void _mali_osk_timer_term(_mali_osk_timer_t *tim)
{
    MALI_DEBUG_ASSERT_POINTER(tim);
    kfree(tim);
}

这里的主要问题是这段代码通过很久以前不推荐使用的接口使用计时器,并且在4.15版中将其完全从内核中删除。我能够查找如何移植此代码,并管理了几乎整个文件,但是最后,我对C语法和指针使用规则还不够熟悉,无法弄清楚该如何做。主要的问题是_mali_osk_timer_setcallback()函数。我不太确定如何修改它,同时又保持相同的功能签名。

编辑

这是当前代码,以及编译器的当前输出:

/*
 * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved.
 * 
 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
 * 
 * A copy of the licence is included with the program, and can also be obtained from Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

/**
 * @file mali_osk_timers.c
 * Implementation of the OS abstraction layer for the kernel device driver
 */

#include <linux/timer.h>
#include <linux/slab.h>
#include "mali_osk.h"
#include "mali_kernel_common.h"

#define MALI_TIMER_FLAGS 0

struct _mali_osk_timer_t_struct {
    struct timer_list timer;
    void (*ticked)(unsigned long data);
};

static void tick_trampoline(struct timer_list *t) {
     typedef struct _mali_osk_timer_t_struct Tldr;
     Tldr *m = container_of(t, Tldr, timer);
     m->ticked(t->data);
}

typedef void (*timer_timeout_function_t)(unsigned long);

_mali_osk_timer_t *_mali_osk_timer_init(void)
{
    _mali_osk_timer_t *t = (_mali_osk_timer_t *)kmalloc(sizeof(_mali_osk_timer_t), GFP_KERNEL);
    if (NULL != t) timer_setup(&(t->timer), tick_trampoline, MALI_TIMER_FLAGS);
    return t;
}

void _mali_osk_timer_add(_mali_osk_timer_t *tim, unsigned long ticks_to_expire)
{
    MALI_DEBUG_ASSERT_POINTER(tim);
    tim->timer.expires = jiffies + ticks_to_expire;
    add_timer(&(tim->timer));
}

void _mali_osk_timer_mod(_mali_osk_timer_t *tim, unsigned long ticks_to_expire)
{
    MALI_DEBUG_ASSERT_POINTER(tim);
    mod_timer(&(tim->timer), jiffies + ticks_to_expire);
}

void _mali_osk_timer_del(_mali_osk_timer_t *tim)
{
    MALI_DEBUG_ASSERT_POINTER(tim);
    del_timer_sync(&(tim->timer));
}

void _mali_osk_timer_del_async(_mali_osk_timer_t *tim)
{
    MALI_DEBUG_ASSERT_POINTER(tim);
    del_timer(&(tim->timer));
}

mali_bool _mali_osk_timer_pending(_mali_osk_timer_t *tim)
{
    MALI_DEBUG_ASSERT_POINTER(tim);
    return 1 == timer_pending(&(tim->timer));
}

void _mali_osk_timer_setcallback(_mali_osk_timer_t *tim, _mali_osk_timer_callback_t callback, void *data)
{
    MALI_DEBUG_ASSERT_POINTER(tim);
    &(tim->timer).data = (unsigned long)data;
    tim->ticked = (timer_timeout_function_t)callback; /* Note no cast */
    timer_setup(&(tim->timer), tick_trampoline, MALI_TIMER_FLAGS);
}

void _mali_osk_timer_term(_mali_osk_timer_t *tim)
{
    MALI_DEBUG_ASSERT_POINTER(tim);
    kfree(tim);
}

_

hugo@tx5:/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali$ sudo KDIR=../../kernel/Amlogic_s905-kernel USING_UMP=0 BUILD=release make
make ARCH=arm64 -C ../../kernel/Amlogic_s905-kernel M=/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali modules
make[1]: Entering directory '/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/kernel/Amlogic_s905-kernel'

  WARNING: Symbol version dump ./Module.symvers
           is missing; modules will have no dependencies and modversions.

  CC [M]  /media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali/linux/mali_osk_timers.o
/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali/linux/mali_osk_timers.c: In function ‘tick_trampoline’:
/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali/linux/mali_osk_timers.c:31:17: error: ‘struct timer_list’ has no member named ‘data’
      m->ticked(t->data);
                 ^~
/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali/linux/mali_osk_timers.c: In function ‘_mali_osk_timer_setcallback’:
/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali/linux/mali_osk_timers.c:77:18: error: ‘struct timer_list’ has no member named ‘data’
     &(tim->timer).data = (unsigned long)data;
                  ^
/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali/linux/mali_osk_timers.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-data-time’
scripts/Makefile.build:305: recipe for target '/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali/linux/mali_osk_timers.o' failed
make[2]: *** [/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali/linux/mali_osk_timers.o] Error 1
Makefile:1517: recipe for target '_module_/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali' failed
make[1]: *** [_module_/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali] Error 2
make[1]: Leaving directory '/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/kernel/Amlogic_s905-kernel'
Makefile:192: recipe for target 'all' failed
make: *** [all] Error 2

1 个答案:

答案 0 :(得分:1)

new 计时器接口gasp将上下文值保留在计时器结构内,并传递一个指向该结构的指针。这个想法是 数据的使用将消失,因为常见的成语是数据是指向 包含 timer_list 结构的结构。

由于您可能希望将对马里的更改减至最少,因此此处概述的更改应有所帮助;它只是插入了一个小的协议转换功能以使其看起来像旧方法。

struct _mali_osk_timer_t_struct {
    struct timer_list timer;
    unsigned long data;
    void (*ticked)(unsigned long data);  /* Add this */
};

#define MALI_TIMER_FLAGS 0  /* NB: choose the right bits for this! */

/* This function converts between the “new” and “old” notifications */
static void tick_trampoline(struct timer *t) {
     typedef struct _mali_osk_timer_t_struct Tldr;
     Tldr *m = container_of(t, Tldr, timer);
     m->ticked(m->data);
}
/* change this one: */
void _mali_osk_timer_setcallback(_mali_osk_timer_t *tim, _mali_osk_timer_callback_t callback, void *data)
{
    MALI_DEBUG_ASSERT_POINTER(tim);
    tim->data = (unsigned long)data;
    tim->ticked = callback; /* Note no cast */
    timer_setup(&tim->ticked, tick_trampoline, MALI_TIMER_FLAGS);
}

“不强制使用”是让类型系统执行其任务的请求。