nouveau: cooking an open source nvidia drivermarcheu/fosdem08-nouveau.pdfall nvidia cards use a mini...

33
Nouveau: Cooking an Open Source Nvidia driver Stéphane Marchesin <[email protected]>

Upload: others

Post on 31-Jul-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

Nouveau: Cooking an Open Source Nvidia driver

Stéphane Marchesin <[email protected]­strasbg.fr>

Page 2: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 2

Talk outline

Introduction

Nvidia hardware primer

Reverse engineering

Current 2D developments

Current 3D developments

Future works

Conclusion/demo

Page 3: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 3

Introduction

Coding drivers is like eating sane food

Good cooking keeps you fit

Good drivers keep you fit, too

But only the open source ones

Page 4: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 4

Introduction

Two years ago

Project introduction at Fosdem

Initial reverse engineering

Last year

Some EXA

Most specs reverse engineered

glxgears

This year ?

Page 5: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 5

Introduction

Community

Bi­weekly news updates (TiNDC)

Associate with news sites

Gather more developers

Currently

Half a dozen developersAll spare­time

Heavy use of IRC

Unwritten policiesBroken code is better than no code

Page 6: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 6

Nvidia hardware primer

Page 7: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 7

Nvidia hardware primer

10­year timeframe:

NV04 (1998)

NV50 (2008)

Similarities between the cards

Fifo handling

Some registers

Differences

3D handling

Page 8: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 8

Nvidia hardware primer

Multiple hardware contexts

A hardware context = a fifo + a graphics state

Full hardware context switching

Each context gets a time slice

Once the time slice is up, the hardware switches the context

Save/Restore the graphics state

Hardware speaks OpenGL almost natively

Hardware uses OpenGL values (e.g. for blending)

Few fallbacks when implementing OpenGL

Page 9: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 9

Nvidia hardware primer

NV4(TNT/TNT2)

NV10(GeForce 1/2/4MX)

NV20(GeForce 3/4Ti)

NV30(GeForce5x00)

NV40(GeForce 6x00/7x00)

NV50(GeForce 8x00)

Cardspecific

Vertex Texture Video Dual head

No

Fixed

VtxProg  1

VtxProg 2

Unified vtx/frag prog

Env.Comb

Reg.Comb

Tex.Shad

FragProg

Overlay

No

Fulldualhead

Page 10: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 10

Reverse engineering

Page 11: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 11

Reverse engineering

Mmio­trace

In­kernel tracingTrap ioremap calls, remove the mapping

Next access to the mapping triggers a page fault

Map the page

Step the instruction

Remove the page again

Used by other projects

Broken in recent kernels

Aiming for mainline kernel inclusion (2.6.26 ?)

Page 12: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 12

Reverse engineering

Valgrind­mmt

Similar to mmio trace

But in user space

Usable on X.Org

Page 13: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 13

Reverse engineering

Renouveau

Old dog (released 2 years ago at Fosdem)User space OpenGL application

Nvidia maps the fifo to user space

Find the fifo mapping

Run a simple OpenGL code

Look for changes in the fifo, print them

New tricks (regularly updated OpenGL tests)

Page 14: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 14

2D support

Page 15: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 15

EXA

Simple EXA

NV4 and NV50NV4 can't do more

NV50 is not widely spread among devs yet

Full XRENDER

NV10/NV20/NV30/NV40

Accelerates all the operations that common desktop environments and toolkits need

Leftover issues

Some are in core EXA

Performance glitch from synchronous uploads

Page 16: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 16

Xv

High performance

Better than the binary driver

Overlaps data upload and rendering

High quality

Bicubic filtering

Implements Matthias Hopf's last year Fosdem talk

Page 17: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 17

Bios Parsing

All nvidia cards use a mini language for the bios

Bytecode

Similar to assembly

The interpreter was written early on

Adated from a cold booting application and from the BeOS/Haiku driver

Slept for a long time, but was recently picked up

Required for cold booting

Required for modesetting/Randr 1.2

Page 18: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 18

Randr 1.2

Dual head support

NV17 ­> NV50 should work

Older dual head is more difficult

Dynamic reconfiguration

Static front buffer allocation issue

Page 19: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 19

3D support

Page 20: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 20

Gallium 3D

Old DRI model:

Most OpenGL functions must be implemented in the driver

Lots of work in the driver

Each driver implements most of the OpenGL pipeline

OpenGL/Mesa

Nvidia Driver

ATI Driver

Intel Driver

Page 21: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 21

Nvidia Driver

ATI Driver

Gallium 3D

Gallium 3D model:

Front ends implement different APIs (OpenGL, DirectX, OpenGL 3.0, GPGPU, OpenVG, Coffee maker) by converting all fixed pipe into shaders

Intermediate layer optimizing the shaders

Back ends turn the intermediate language into card­specific code 

Intel DriverDirectXIntermediate

Representation

OpenGL

GPGPU

Page 22: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 22

Gallium 3D: what about older cards ?

Older cards do not have shaders

The previous model does not work

Unless...

Page 23: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 23

Gallium 3D: what about older cards ?

Additional intermediate language instructions

These new instructions represent the old multitexture/texture combiners/texture extensions of NV4/NV10/NV20

Old cards can be supported with the same architecture

Page 24: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 24

Gallium 3D

Current developments

NV40 driver somehow working

NV10, NV30 under development

Page 25: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 25

Future cooking ?

Page 26: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 26

TTM

More than just memory management

The kernel is in charge of placing/moving pieces of memory

Similar to kernel memory allocation and swapping

User space code does not need to track memory addresses itself

Kernel “relocates” command buffers

"Superioctl"

(not that super in our case)

Page 27: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 27

DRI2

Still in the air

Try to remove the big lock (we don't have one)

Remove the SAREA (we don't have one)

Remove shared back buffers (we don't have those)

Page 28: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 28

Kernel modesetting

Wait for Randr 1.2 stabilization

Developing Randr 1.2 in user space is easier

Move Randr 1.2 into the kernel

Requires moving the bios parser into the kernel as well

«Hi Linus, can we put that bytecode interpreter into the kernel ?»

Page 29: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 29

Suspend/Resume

Work in progress

Requires a fully working bios parser

Requires saving & restoring the card state

Better with kernel modesetting in place

Not as obvious as it seems

Page 30: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 30

Releases ?

We get asked a lot about releases 

Stabilize DRM interface

Not yet the case

Lots of changes left before this happens

Stabilizing too early = burden of maintenance later

Page 31: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 31

Conclusions

Mostly finished 2D support

3D is largely underway

NV50 is still the bad boy

Eating fruits is good

Page 32: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 32

Conclusions

http://nouveau.freedesktop.org

irc: #nouveau on freenode

Page 33: Nouveau: Cooking an Open Source Nvidia drivermarcheu/fosdem08-nouveau.pdfAll nvidia cards use a mini language for the bios Bytecode Similar to assembly The interpreter was written

2/23/08 /home/marchesi/presentation_fosdem_2008_02_23/fosdem.odp page 33

Demo