Re: [PATCH v8 2/2] drm: add kms driver for loongson display controller

2023-03-28 Thread Sui Jingfeng



On 2023/3/29 01:06, Nathan Chancellor wrote:

On Tue, Mar 28, 2023 at 11:22:50PM +0800, Sui Jingfeng wrote:

HI,

On 2023/3/28 17:27, kernel test robot wrote:

Hi Sui,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v6.3-rc4 next-20230328]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:
https://lore.kernel.org/r/20230320100131.1277034-3-15330273260%40189.cn
patch subject: [PATCH v8 2/2] drm: add kms driver for loongson display 
controller
config: i386-allyesconfig 
(https://download.01.org/0day-ci/archive/20230328/202303281754.jwi20j2c-...@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project 
f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
  wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
  chmod +x ~/bin/make.cross
  # 
https://github.com/intel-lab-lkp/linux/commit/80b4115f44993f4ebf47b1cb9e8f02953575b977
  git remote add linux-review https://github.com/intel-lab-lkp/linux
  git fetch --no-tags linux-review 
Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408
  git checkout 80b4115f44993f4ebf47b1cb9e8f02953575b977
  # save the config file
  mkdir build_dir && cp config build_dir/.config
  COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 
O=build_dir ARCH=i386 olddefconfig
  COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 
O=build_dir ARCH=i386 SHELL=/bin/bash drivers/accel/ drivers/gpu/drm/loongson/ 
drivers/iio/light/ drivers/media/pci/intel/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot 
| Link: 
https://lore.kernel.org/oe-kbuild-all/202303281754.jwi20j2c-...@intel.com/

All warnings (new ones prefixed by >>):


drivers/gpu/drm/loongson/lsdc_drv.c:232:11: warning: variable 'gpu' is used 
uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

 else if (descp->chip == CHIP_LS7A2000)
  ^~~~
 drivers/gpu/drm/loongson/lsdc_drv.c:235:7: note: uninitialized use occurs 
here
 if (!gpu) {
  ^~~
 drivers/gpu/drm/loongson/lsdc_drv.c:232:7: note: remove the 'if' if its 
condition is always true
 else if (descp->chip == CHIP_LS7A2000)
  ^
 drivers/gpu/drm/loongson/lsdc_drv.c:217:21: note: initialize the variable 
'gpu' to silence this warning
 struct pci_dev *gpu;
^
 = NULL
 1 warning generated.
--

In practice,  either  descp->chip == CHIP_LS7A2000 or descp->chip ==
CHIP_LS7A1000 will be happened at runtime.

the variable 'gpu' is guaranteed to be initialized when code run at
drivers/gpu/drm/loongson/lsdc_drv.c:235

This warnning is almost wrong here.

Clang's semantic analysis happens before optimizations, meaning it does
not perform interprocedural analysis, so it does not have enough
information at this point to tell that. Either just initialize gpu to
NULL and let the existing 'if (!gpu)' handle it or add a separate else
branch that warns about an unhandled chip value so that it is obvious
what needs to be done if someone forgets to update this statement when a
new chip is supported by this driver.


Right,  I overlook the point you mentioned previously.

And I just have a new idea,  using pci_get_domain_bus_and_slot function

to handle this.  the DC and the GPU have the same pci bus number and  
domain number.


The slot number of the dc and gpu is also same(6), only the function 
number is different.



For ls7a1000,  what lspci -t -nnn -vvv show is:

-[:00]-+-00.0  Loongson Technology LLC Hyper Transport Bridge 
Controller [0014:7a00]


   ...

   +-06.0  Loongson Technology LLC Vivante GPU (Graphics 
Processing Unit) [0014:7a15]
   +-06.1  Loongson Technology LLC DC (Display Controller) 
[0014:7a06]


   ...


For ls7a2000, what lspci -t -nnn -vvv show is:

-[:00]-+-00.0  Loongson Technology LLC Hyper Transport Bridge 
Controller [0014:7a00]
   +-00.1  Loongson Technology LLC Hyper Transport Bridge 
Controller [0014:7a10]

   ...
   +-06.0  Loongson Technology LLC LoongGPU Device [0014:7a25]
   +-06.1  Loongs

Re: [PATCH v8 2/2] drm: add kms driver for loongson display controller

2023-03-28 Thread Nathan Chancellor
On Tue, Mar 28, 2023 at 11:22:50PM +0800, Sui Jingfeng wrote:
> HI,
> 
> On 2023/3/28 17:27, kernel test robot wrote:
> > Hi Sui,
> > 
> > Thank you for the patch! Perhaps something to improve:
> > 
> > [auto build test WARNING on drm-misc/drm-misc-next]
> > [also build test WARNING on linus/master v6.3-rc4 next-20230328]
> > [If your patch is applied to the wrong git tree, kindly drop us a note.
> > And when submitting patch, we suggest to use '--base' as documented in
> > https://git-scm.com/docs/git-format-patch#_base_tree_information]
> > 
> > url:
> > https://github.com/intel-lab-lkp/linux/commits/Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408
> > base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
> > patch link:    
> > https://lore.kernel.org/r/20230320100131.1277034-3-15330273260%40189.cn
> > patch subject: [PATCH v8 2/2] drm: add kms driver for loongson display 
> > controller
> > config: i386-allyesconfig 
> > (https://download.01.org/0day-ci/archive/20230328/202303281754.jwi20j2c-...@intel.com/config)
> > compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project 
> > f28c006a5895fc0e329fe15fead81e37457cb1d1)
> > reproduce (this is a W=1 build):
> >  wget 
> > https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
> > ~/bin/make.cross
> >  chmod +x ~/bin/make.cross
> >  # 
> > https://github.com/intel-lab-lkp/linux/commit/80b4115f44993f4ebf47b1cb9e8f02953575b977
> >  git remote add linux-review https://github.com/intel-lab-lkp/linux
> >  git fetch --no-tags linux-review 
> > Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408
> >  git checkout 80b4115f44993f4ebf47b1cb9e8f02953575b977
> >  # save the config file
> >  mkdir build_dir && cp config build_dir/.config
> >  COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 
> > O=build_dir ARCH=i386 olddefconfig
> >  COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 
> > O=build_dir ARCH=i386 SHELL=/bin/bash drivers/accel/ 
> > drivers/gpu/drm/loongson/ drivers/iio/light/ drivers/media/pci/intel/
> > 
> > If you fix the issue, kindly add following tag where applicable
> > | Reported-by: kernel test robot 
> > | Link: 
> > https://lore.kernel.org/oe-kbuild-all/202303281754.jwi20j2c-...@intel.com/
> > 
> > All warnings (new ones prefixed by >>):
> > 
> > > > drivers/gpu/drm/loongson/lsdc_drv.c:232:11: warning: variable 'gpu' is 
> > > > used uninitialized whenever 'if' condition is false 
> > > > [-Wsometimes-uninitialized]
> > else if (descp->chip == CHIP_LS7A2000)
> >  ^~~~
> > drivers/gpu/drm/loongson/lsdc_drv.c:235:7: note: uninitialized use 
> > occurs here
> > if (!gpu) {
> >  ^~~
> > drivers/gpu/drm/loongson/lsdc_drv.c:232:7: note: remove the 'if' if its 
> > condition is always true
> > else if (descp->chip == CHIP_LS7A2000)
> >  ^
> > drivers/gpu/drm/loongson/lsdc_drv.c:217:21: note: initialize the 
> > variable 'gpu' to silence this warning
> > struct pci_dev *gpu;
> >^
> > = NULL
> > 1 warning generated.
> > --
> 
> In practice,  either  descp->chip == CHIP_LS7A2000 or descp->chip ==
> CHIP_LS7A1000 will be happened at runtime.
> 
> the variable 'gpu' is guaranteed to be initialized when code run at 
> drivers/gpu/drm/loongson/lsdc_drv.c:235
> 
> This warnning is almost wrong here.

Clang's semantic analysis happens before optimizations, meaning it does
not perform interprocedural analysis, so it does not have enough
information at this point to tell that. Either just initialize gpu to
NULL and let the existing 'if (!gpu)' handle it or add a separate else
branch that warns about an unhandled chip value so that it is obvious
what needs to be done if someone forgets to update this statement when a
new chip is supported by this driver.

> > > > drivers/gpu/drm/loongson/lsdc_pll.c:188:14: warning: variable 'diff' is 
> > > > used uninitialized whenever 'if' condition is false 
> > > > [-Wsometimes-uninitialized]
> > else if (clock_khz < computed)
> &g

Re: [PATCH v8 2/2] drm: add kms driver for loongson display controller

2023-03-28 Thread Sui Jingfeng

HI,

On 2023/3/28 17:27, kernel test robot wrote:

Hi Sui,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v6.3-rc4 next-20230328]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:
https://lore.kernel.org/r/20230320100131.1277034-3-15330273260%40189.cn
patch subject: [PATCH v8 2/2] drm: add kms driver for loongson display 
controller
config: i386-allyesconfig 
(https://download.01.org/0day-ci/archive/20230328/202303281754.jwi20j2c-...@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project 
f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
 wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
 chmod +x ~/bin/make.cross
 # 
https://github.com/intel-lab-lkp/linux/commit/80b4115f44993f4ebf47b1cb9e8f02953575b977
 git remote add linux-review https://github.com/intel-lab-lkp/linux
 git fetch --no-tags linux-review 
Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408
 git checkout 80b4115f44993f4ebf47b1cb9e8f02953575b977
 # save the config file
 mkdir build_dir && cp config build_dir/.config
 COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 
O=build_dir ARCH=i386 olddefconfig
 COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 
O=build_dir ARCH=i386 SHELL=/bin/bash drivers/accel/ drivers/gpu/drm/loongson/ 
drivers/iio/light/ drivers/media/pci/intel/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot 
| Link: 
https://lore.kernel.org/oe-kbuild-all/202303281754.jwi20j2c-...@intel.com/

All warnings (new ones prefixed by >>):


drivers/gpu/drm/loongson/lsdc_drv.c:232:11: warning: variable 'gpu' is used 
uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

else if (descp->chip == CHIP_LS7A2000)
 ^~~~
drivers/gpu/drm/loongson/lsdc_drv.c:235:7: note: uninitialized use occurs 
here
if (!gpu) {
 ^~~
drivers/gpu/drm/loongson/lsdc_drv.c:232:7: note: remove the 'if' if its 
condition is always true
else if (descp->chip == CHIP_LS7A2000)
 ^
drivers/gpu/drm/loongson/lsdc_drv.c:217:21: note: initialize the variable 
'gpu' to silence this warning
struct pci_dev *gpu;
   ^
= NULL
1 warning generated.
--


In practice,  either  descp->chip == CHIP_LS7A2000 or descp->chip == 
CHIP_LS7A1000 will be happened at runtime.


the variable 'gpu' is guaranteed to be initialized when code run at  
drivers/gpu/drm/loongson/lsdc_drv.c:235


This warnning is almost wrong here.


drivers/gpu/drm/loongson/lsdc_pll.c:188:14: warning: variable 'diff' is used 
uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

else if (clock_khz < computed)
 ^~~~
drivers/gpu/drm/loongson/lsdc_pll.c:191:9: note: uninitialized use occurs 
here
if (diff < min) {
^~~~
drivers/gpu/drm/loongson/lsdc_pll.c:188:10: note: remove the 'if' if its 
condition is always true
else if (clock_khz < computed)
 ^
drivers/gpu/drm/loongson/lsdc_pll.c:177:22: note: initialize the variable 
'diff' to silence this warning
unsigned int diff;
 ^
  = 0
1 warning generated.


Here the robot is also wrong here in practice,

because either  if (clock_khz >= computed) or else if (clock_khz < 
computed) will be happen.


'diff' variable is guaranteed to be initialized.



vim +232 drivers/gpu/drm/loongson/lsdc_drv.c

212 
213 static int lsdc_get_dedicated_vram(struct lsdc_device *ldev,
214const struct lsdc_desc *descp)
215 {
216 struct drm_device *ddev = &ldev->base;
217 struct pci_dev *gpu;
218 resourc

Re: [PATCH v8 2/2] drm: add kms driver for loongson display controller

2023-03-28 Thread Sui Jingfeng

Hi,

Is this all of warnings ?  I'm asking because  I'm afraid it is not all.

If I fix those, it will generate new again next time.


I'm compile this driver with GCC,  it report no warnings

On ls3a4000 mips machine:

  make  -j$(nproc) ARCH=mips CROSS_COMPILE=mips64el-linux-gnuabi64- W=1

On ls3a5000 LoongArch machine:

| make -j$(nproc) ARCH=loongarch 
CROSS_COMPILE=loongarch64-unknown-linux-gnu-|


Build tools can be found link [1]

[1] https://github.com/loongson/build-tools

On x86-64 is also compiled.


Yet, It is easy to fix, is there any other questions or issues?

I will fix them all.


On 2023/3/28 17:27, kernel test robot wrote:

Hi Sui,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v6.3-rc4 next-20230328]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:
https://lore.kernel.org/r/20230320100131.1277034-3-15330273260%40189.cn
patch subject: [PATCH v8 2/2] drm: add kms driver for loongson display 
controller
config: i386-allyesconfig 
(https://download.01.org/0day-ci/archive/20230328/202303281754.jwi20j2c-...@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project 
f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
 wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
 chmod +x ~/bin/make.cross
 # 
https://github.com/intel-lab-lkp/linux/commit/80b4115f44993f4ebf47b1cb9e8f02953575b977
 git remote add linux-review https://github.com/intel-lab-lkp/linux
 git fetch --no-tags linux-review 
Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408
 git checkout 80b4115f44993f4ebf47b1cb9e8f02953575b977
 # save the config file
 mkdir build_dir && cp config build_dir/.config
 COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 
O=build_dir ARCH=i386 olddefconfig
 COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 
O=build_dir ARCH=i386 SHELL=/bin/bash drivers/accel/ drivers/gpu/drm/loongson/ 
drivers/iio/light/ drivers/media/pci/intel/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot 
| Link: 
https://lore.kernel.org/oe-kbuild-all/202303281754.jwi20j2c-...@intel.com/

All warnings (new ones prefixed by >>):


drivers/gpu/drm/loongson/lsdc_drv.c:232:11: warning: variable 'gpu' is used 
uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

else if (descp->chip == CHIP_LS7A2000)
 ^~~~
drivers/gpu/drm/loongson/lsdc_drv.c:235:7: note: uninitialized use occurs 
here
if (!gpu) {
 ^~~
drivers/gpu/drm/loongson/lsdc_drv.c:232:7: note: remove the 'if' if its 
condition is always true
else if (descp->chip == CHIP_LS7A2000)
 ^
drivers/gpu/drm/loongson/lsdc_drv.c:217:21: note: initialize the variable 
'gpu' to silence this warning
struct pci_dev *gpu;
   ^
= NULL
1 warning generated.
--

drivers/gpu/drm/loongson/lsdc_pll.c:188:14: warning: variable 'diff' is used 
uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

else if (clock_khz < computed)
 ^~~~
drivers/gpu/drm/loongson/lsdc_pll.c:191:9: note: uninitialized use occurs 
here
if (diff < min) {
^~~~
drivers/gpu/drm/loongson/lsdc_pll.c:188:10: note: remove the 'if' if its 
condition is always true
else if (clock_khz < computed)
 ^
drivers/gpu/drm/loongson/lsdc_pll.c:177:22: note: initialize the variable 
'diff' to silence this warning
unsigned int diff;
 ^
  = 0
1 warning generated.


vim +232 drivers/gpu/drm/loongson/lsdc_drv.c

212 
213 static int lsdc_get_dedicated_vram(struct lsdc_device *ldev,
214const struct lsdc_desc *descp)
215 {

Re: [PATCH v8 2/2] drm: add kms driver for loongson display controller

2023-03-28 Thread kernel test robot
Hi Sui,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v6.3-rc4 next-20230328]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:
https://lore.kernel.org/r/20230320100131.1277034-3-15330273260%40189.cn
patch subject: [PATCH v8 2/2] drm: add kms driver for loongson display 
controller
config: i386-allyesconfig 
(https://download.01.org/0day-ci/archive/20230328/202303281754.jwi20j2c-...@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project 
f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# 
https://github.com/intel-lab-lkp/linux/commit/80b4115f44993f4ebf47b1cb9e8f02953575b977
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review 
Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408
git checkout 80b4115f44993f4ebf47b1cb9e8f02953575b977
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 
O=build_dir ARCH=i386 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 
O=build_dir ARCH=i386 SHELL=/bin/bash drivers/accel/ drivers/gpu/drm/loongson/ 
drivers/iio/light/ drivers/media/pci/intel/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot 
| Link: 
https://lore.kernel.org/oe-kbuild-all/202303281754.jwi20j2c-...@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/loongson/lsdc_drv.c:232:11: warning: variable 'gpu' is used 
>> uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
   else if (descp->chip == CHIP_LS7A2000)
^~~~
   drivers/gpu/drm/loongson/lsdc_drv.c:235:7: note: uninitialized use occurs 
here
   if (!gpu) {
^~~
   drivers/gpu/drm/loongson/lsdc_drv.c:232:7: note: remove the 'if' if its 
condition is always true
   else if (descp->chip == CHIP_LS7A2000)
^
   drivers/gpu/drm/loongson/lsdc_drv.c:217:21: note: initialize the variable 
'gpu' to silence this warning
   struct pci_dev *gpu;
  ^
   = NULL
   1 warning generated.
--
>> drivers/gpu/drm/loongson/lsdc_pll.c:188:14: warning: variable 'diff' is used 
>> uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
   else if (clock_khz < computed)
^~~~
   drivers/gpu/drm/loongson/lsdc_pll.c:191:9: note: uninitialized use occurs 
here
   if (diff < min) {
   ^~~~
   drivers/gpu/drm/loongson/lsdc_pll.c:188:10: note: remove the 'if' if its 
condition is always true
   else if (clock_khz < computed)
^
   drivers/gpu/drm/loongson/lsdc_pll.c:177:22: note: initialize the variable 
'diff' to silence this warning
   unsigned int diff;
^
 = 0
   1 warning generated.


vim +232 drivers/gpu/drm/loongson/lsdc_drv.c

   212  
   213  static int lsdc_get_dedicated_vram(struct lsdc_device *ldev,
   214 const struct lsdc_desc *descp)
   215  {
   216  struct drm_device *ddev = &ldev->base;
   217  struct pci_dev *gpu;
   218  resource_size_t base, size;
   219  
   220  /*
   221   * The GPU and display controller in LS7A1000/LS7A2000 are 
separated
   222   * PCIE devices, they are two devices not one. The DC does not 
has a
   223   * dedicate VRAM bar, because the BIOS engineer choose to 
assign the
   224   * VRAM to the GPU device. Sadly, after years application, this 
form
   225   * as a convention for loongson integrated graphics. Bar 2 of 
the GPU
   226   * device contain the base address and size of the VRA

Re: [PATCH v8 2/2] drm: add kms driver for loongson display controller

2023-03-28 Thread Sui Jingfeng

Hi,

Welcome review, comments and discussion,

If there are issues in this driver, I will take the responsibility to 
resolve and revise  my driver.



We are maintain three version of this drvier  at downstream world,

target to linux-4.19.190, linux 5.4 kernel and linux 5.10 kernel 
respectively.


Our company product side using linux-4.19.190 debian 10 release, while

kylinos using 5.4, open openEuler using 5.10 kernel version.

We found surprisingly that we will pay more and more time to maintain 
this drivers for different kernel version as time goes,


A few personal developers also want a driver for loongson hardware, they 
may want to play a while occasionally.


Is there anyone willing to help upstream this trivial driver? please help!


On 2023/3/20 18:01, Sui Jingfeng wrote:


From: Sui Jingfeng 

Loongson display controller IP has been integrated in both Loongson
North Bridge chipset(ls7a1000 and ls7a2000) and Loongson SoCs(ls2k1000
and ls2k2000 etc), it even has been included in Loongson BMC products.

This display controller is a PCI device, it has two display pipe. For
the DC in LS7A1000 and LS2K1000 each way has a DVO output interface
which provide RGB888 signals, vertical & horizontal synchronisations,
and the pixel clock. Each CRTC is able to support 1920x1080@60Hz,
the maximum resolution is 2048x2048 according to the hardware spec.

For the DC in LS7A2000, each display pipe is equipped with a built-in
HDMI encoder which is compliant with HDMI 1.4 specification, thus it
support 3840x2160@30Hz. The first display pipe is also equipped with
a transparent vga encoder which is parallel with the HDMI encoder.
The DC in LS7A2000 is more complete, besides above feature, it has
two hardware cursors, two hardware vblank counter and two scanout
position recorders.

  v1 -> v2:
   1) Use hpd status reg when polling for ls7a2000
   2) Fix all warnings emerged when compile with W=1

  v2 -> v3:
   1) Add COMPILE_TEST in Kconfig and make the driver off by default
   2) Alphabetical sorting headers (Thomas)
   3) Untangle register access functions as much as possible (Thomas)
   4) Switch to TTM based memory manager and prefer cached mapping
  for Loongson SoC (Thomas)
   5) Add chip id detection method, now all models are distinguishable.
   6) Revise builtin HDMI phy driver, nearly all main stream mode
  below 4K@30Hz is tested, this driver supported these mode very
  well including clone display mode and extend display mode.

  v3 -> v4:
   1) Quickly fix a small mistake.

  v4 -> v5:
   1) Drop potential support for Loongson 2K series SoC temporary,
  this part should be resend with the DT binding patch in the future.
   2) Add per display pipe debugfs support to the builtin HDMI encoder.
   3) Rewrite atomic_update() for hardware cursors plane(Thomas)
   4) Rewrite encoder and connector initialization part, untangle it
  according to the chip(Thomas).

  v5 -> v6:
   1) Remove stray code which didn't get used, say lsdc_of_get_reserved_ram
   2) Fix all typos I could found, make sentences and code more readable
   3) Untangle lsdc_hdmi*_connector_detect() function according to the pipe
   4) After a serious consideration, we rename this driver as loongson.
  Because we also have drivers toward the LoongGPU IP in LS7A2000 and
  LS2K2000. Besides, there are also drivers about the external encoder,
  HDMI audio driver and vbios support etc. This patch only provide DC
  driver part, my teammate Li Yi believe that loongson will be more
  suitable for loongson graphics than lsdc in the long run.

  loongson.ko = LSDC + LoongGPU + encoders driver + vbios/DT ...

   v6 -> v7:
   1) Add prime support, self-sharing is works. sharing buffer with etnaviv
  is also tested, and its works with limitation.
   2) Implement buffer objects tracking with list_head.
   3) S3(sleep to RAM) is tested on ls3a5000+ls7a2000 evb and it works.
   4) Rewrite lsdc_bo_move, since ttm core stop allocating resources
  during BO creation. Patch V1 ~ V6 of this series no longer works
  on latest kernel. Thus, we send V7 to revival them.

   v7 -> v8:
   1) Zero a compile warnnings on 32-bit platform, compile with W=1
   2) Revise lsdc_bo_gpu_offset() and minor cleanup
   3) Pageflip tested on the virtual terminal with following commands

   modetest -M loongson -s 32:1920x1080 -v
   modetest -M loongson -s 34:1920x1080 -v -F tiles

  It works like a charm, when running pageflip test with dual screnn
  configuration, another two additional bo created by the modetest
  emerged, VRAM usage up to 40+MB, well we have at least 64MB, still
  enough.

  # cat bos

  bo[]: size: 8112kB VRAM
  bo[0001]: size:   16kB VRAM
  bo[0002]: size:   16kB VRAM
  bo[0003]: size:16208kB VRAM
  bo[0004]: size: 8112kB VRAM
  bo[0005]: size: 8112kB VRAM

Signed-off-by: Li Yi 
Signed-off-by: Sui Jingfe

[PATCH v8 2/2] drm: add kms driver for loongson display controller

2023-03-20 Thread Sui Jingfeng
From: Sui Jingfeng 

Loongson display controller IP has been integrated in both Loongson
North Bridge chipset(ls7a1000 and ls7a2000) and Loongson SoCs(ls2k1000
and ls2k2000 etc), it even has been included in Loongson BMC products.

This display controller is a PCI device, it has two display pipe. For
the DC in LS7A1000 and LS2K1000 each way has a DVO output interface
which provide RGB888 signals, vertical & horizontal synchronisations,
and the pixel clock. Each CRTC is able to support 1920x1080@60Hz,
the maximum resolution is 2048x2048 according to the hardware spec.

For the DC in LS7A2000, each display pipe is equipped with a built-in
HDMI encoder which is compliant with HDMI 1.4 specification, thus it
support 3840x2160@30Hz. The first display pipe is also equipped with
a transparent vga encoder which is parallel with the HDMI encoder.
The DC in LS7A2000 is more complete, besides above feature, it has
two hardware cursors, two hardware vblank counter and two scanout
position recorders.

 v1 -> v2:
  1) Use hpd status reg when polling for ls7a2000
  2) Fix all warnings emerged when compile with W=1

 v2 -> v3:
  1) Add COMPILE_TEST in Kconfig and make the driver off by default
  2) Alphabetical sorting headers (Thomas)
  3) Untangle register access functions as much as possible (Thomas)
  4) Switch to TTM based memory manager and prefer cached mapping
 for Loongson SoC (Thomas)
  5) Add chip id detection method, now all models are distinguishable.
  6) Revise builtin HDMI phy driver, nearly all main stream mode
 below 4K@30Hz is tested, this driver supported these mode very
 well including clone display mode and extend display mode.

 v3 -> v4:
  1) Quickly fix a small mistake.

 v4 -> v5:
  1) Drop potential support for Loongson 2K series SoC temporary,
 this part should be resend with the DT binding patch in the future.
  2) Add per display pipe debugfs support to the builtin HDMI encoder.
  3) Rewrite atomic_update() for hardware cursors plane(Thomas)
  4) Rewrite encoder and connector initialization part, untangle it
 according to the chip(Thomas).

 v5 -> v6:
  1) Remove stray code which didn't get used, say lsdc_of_get_reserved_ram
  2) Fix all typos I could found, make sentences and code more readable
  3) Untangle lsdc_hdmi*_connector_detect() function according to the pipe
  4) After a serious consideration, we rename this driver as loongson.
 Because we also have drivers toward the LoongGPU IP in LS7A2000 and
 LS2K2000. Besides, there are also drivers about the external encoder,
 HDMI audio driver and vbios support etc. This patch only provide DC
 driver part, my teammate Li Yi believe that loongson will be more
 suitable for loongson graphics than lsdc in the long run.

 loongson.ko = LSDC + LoongGPU + encoders driver + vbios/DT ...

  v6 -> v7:
  1) Add prime support, self-sharing is works. sharing buffer with etnaviv
 is also tested, and its works with limitation.
  2) Implement buffer objects tracking with list_head.
  3) S3(sleep to RAM) is tested on ls3a5000+ls7a2000 evb and it works.
  4) Rewrite lsdc_bo_move, since ttm core stop allocating resources
 during BO creation. Patch V1 ~ V6 of this series no longer works
 on latest kernel. Thus, we send V7 to revival them.

  v7 -> v8:
  1) Zero a compile warnnings on 32-bit platform, compile with W=1
  2) Revise lsdc_bo_gpu_offset() and minor cleanup
  3) Pageflip tested on the virtual terminal with following commands

  modetest -M loongson -s 32:1920x1080 -v
  modetest -M loongson -s 34:1920x1080 -v -F tiles

 It works like a charm, when running pageflip test with dual screnn
 configuration, another two additional bo created by the modetest
 emerged, VRAM usage up to 40+MB, well we have at least 64MB, still
 enough.

 # cat bos

 bo[]: size: 8112kB VRAM
 bo[0001]: size:   16kB VRAM
 bo[0002]: size:   16kB VRAM
 bo[0003]: size:16208kB VRAM
 bo[0004]: size: 8112kB VRAM
 bo[0005]: size: 8112kB VRAM

Signed-off-by: Li Yi 
Signed-off-by: Sui Jingfeng 
---
 drivers/gpu/drm/Kconfig |   2 +
 drivers/gpu/drm/Makefile|   1 +
 drivers/gpu/drm/loongson/Kconfig|  15 +
 drivers/gpu/drm/loongson/Makefile   |  16 +
 drivers/gpu/drm/loongson/lsdc_crtc.c| 385 
 drivers/gpu/drm/loongson/lsdc_debugfs.c | 261 +++
 drivers/gpu/drm/loongson/lsdc_drv.c | 501 +
 drivers/gpu/drm/loongson/lsdc_drv.h | 318 +
 drivers/gpu/drm/loongson/lsdc_gem.c | 291 
 drivers/gpu/drm/loongson/lsdc_gem.h |  26 ++
 drivers/gpu/drm/loongson/lsdc_i2c.c | 171 +++
 drivers/gpu/drm/loongson/lsdc_irq.c |  88 
 drivers/gpu/drm/loongson/lsdc_irq.h |  11 +
 drivers/gpu/drm/loongson/lsdc_output.c  | 563 
 drivers/gpu/drm/loongson/lsdc_output.h  |  14 +
 drivers/gpu/d