Writing an open source GPU driver without the hardware
collabora.com
collabora.com
Low level stuff has always been interesting to me, I just have no clue how one would even get started with it, or who would even pay me to work on it.
When it comes to writing firmwares or an OS, nothing can substitute for hands-on experience with actual hardware.
It may be easier if you do some electronics as a hobby since you can create the devices yourself with simple enough protocols. It gives you a good understanding of how the hardware works at a basic level.
There are thousands of tutorials out there on how to get started writing simple drivers, as well as the excellent book "Linux device drivers".
I don't do _complex_ drivers, but I've been able to write simple ones for my DIY electronic devices (keyboards, sensors, ...) and even a reverse engineered one for my BOSS RC5 guitar pedal.
https://github.com/isometimes/rpi4-osdev
There are other courses/projects for other boards. The keyword is usually “baremetal”.
For Linux drivers specifically there are training material from Bootlin etc. They definitely give you a kickstart—the kernel is so complex that most of the device driver knowledge is organizational and cannot be found on YouTube.
Can be for old laptop (T420, etc with Intel GPU/Driver.)
Use FTRACE in kernel.
Setup ebpf trace for GPU acitivies.
Write some doc/blog/medium pages on the process and show off your works.
Understand, document and improve some opensource GPU API related utilities
Understand and document interaction between GPU/GUI App and OpenSource driver.
In term of jobs:
AMD has 289 opening for intern positions: https://jobs.amd.com/go/Internships-&-Co-op-Opportunities/25... A lot of them are graphic related.One keyword is embedded programming. You can start out bare metal basically doing everything in a while(1) loop until you get to a point where different tasks (in the literal way) and peripherals get so much that you will end up doing exactly this, but on a much smaller (and comprehensible) scale.
For example, take something like (1) the simplest AVR microcontroller (the type used in Arduinos, hence there is a ton of third-party documentation and code floating around) and (2) your typical Hitachi HD44780 LED display.
To control the display, one needs to pull certain pins high and low, for specific intervals -- this is all in the HD44780's data sheet. Of course, you don't do this every time you send a character; you abstract this away into functions setchar(x, y, c), clearDisplay(), and so on.
Presto, your first driver!
Then you might think: let's print stuff that we receive via a serial connection. So how do you react to that data? Then you learn about interrupts and interrupt handling.
Then you might think: I could be doing stuff while I wait for I/O. Actually, I'd like to do a lot of stuff, in parallel, but the AVRs are single-core (so to speak). So you do what you've heard other OSes do: take available compute time, divide it into slices, and distribute slices to processes. And thus, you have learned about multi-tasking.
This was relatively simple to do on AVRs, and great fun.
The thing about NetBSD (and I can vouch for OpenBSD being much the same) is that it's so stinking well documented, if you go in knowing C you can learn how to write a simple device driver using just the man pages as your guide. Section 9 of the manual in particular documents every kernel API and most if not all internal types.
It's a great OS to practice developing low-level code with. Linux is a bit harder.
People need to buy your hardware to use your drivers.
Meaning driver development is a cost. The revenue comes from hardware sales. You're usually offering the driver to the public for free on your website anyway. Why not simply open source it?
If you open source your driver, community developers could potentially give you free help -- e.g. porting to Linux, getting into the mainline kernel, fixing bugs.
Sure, sometimes there is special sauce in the drivers too
But mostly it’s just culture. Hardware companies also don’t like cloud software…because they think on prem is safer or whatever
Cloud companies are some of the biggest customers of hardware companies like AMD. Eventually they will come to a point where they negotiate.
It was not an accusation. A risk was articulated.
The sheer quantity of hardware purchased by these companies is relevant when assessing risk/reward.
- driver can reveal internal workings of their “proprietary” hardware
- they use driver features to further differentiate their hardware product
But really it’s just old tradition and paranoia.
Every, somewhat solid, HW engineer from the competition will be able to still grasp those inner workings from a proprietary driver and the HW itself. In the end they cannot just copy (most) things over due to facing potential legal issues, no matter if the driver is foss or proprietary.
> - they use driver features to further differentiate their hardware product > But really it’s just old tradition and paranoia
Agreeing here, albeit AMD and Intel seem to have (somewhat) grasped that it doesn't need to be that way.
Because when you want to depreciate your old hardware and want to push your customers to new one, open source driver that is maintained, or even worse, add features that should be exclusive to your new hardware, you have a problem. Planned obsolescence is the name of the game in modern hardware industry. And even "open source" drivers like mwlwifi show similar pattern, good look fixing their ¢¢^√°^¢^° firmware.
This was all ~10 years ago, though, I think nowadays they just fleece everyone.
Of course this also means there is potential for a competitor to gain competitive advantage when they dont have to rely on GPU for revenue and profits generation. I expect or hope that to be Intel. ( That is ignoring GPU's potential patents issues )
And IME it is the proprietary drivers that usually offer least value and most problems. That sways buying decisions.
Closed source is the norm, no matter if it's a hardware company's driver/companion app or a service company's client app. It's rarely economical, but usually "makes business sense" as in there's one more proprietary thing that you own and that increases your apparent value to investors. Some reasons I've heard:
- opening it would lower the barrier to entry for competitors (as if software is the big barrier) - it could be licensed to other companies in different industries (that almost never happens) - closed source is more secure and therefore less risky (a classic fallacy)
Software: hire 2 junior programmers, give them the hardware and protocol specs, wait 2 months, upload the executable to a website.
The vast majority of "software for hardware" these days is just a GUI sending commands to the firmware over whatever communication channel is available. GPU drivers are pretty much the single example of very complex "software for hardware" in the mainstream market.
Unfortunately, having read this, I feel rather stupid.
Great work from Alyssa and everyone else at Collabora.
https://rosenzweig.io/blog/asahi-gpu-part-1.html https://rosenzweig.io/blog/asahi-gpu-part-2.html https://rosenzweig.io/blog/asahi-gpu-part-3.html https://rosenzweig.io/blog/asahi-gpu-part-4.html
Hopefully that reaches retail quite soon.
Thanks a lot to Alyssa, Collabora and everyone else involved for the amazing work!
Because doing it properly is too expensive for average customer? Also, in capitalism you only need to outrun your competitors, not achieve some kind of perfect driver. So when your competitors are as &'££&-- as you, wasting time on a perfect driver is a waste of time.
IIRC there was a Debian installer for Sun's JDK/JRE that did precisely that.
Also you technically don't agree to a EULA when you download an installer via direct link and unpack it to extract the files required to initialize the thing you own. You never run the installer and never click the "agree" button.
Circumventing the EULA prompt is considered agreement to the EULA terms in the US. If you fight that too much in court, it would then be considered software piracy.
The way things tend to be enforced is that while you own the physical piece of hardware, you do not own or necessarily have any rights to the software on it, or for it.
I guess one way would be to write a driver that does this exact thing this thread suggests, and release it under a license that forbids its distribution into and within the US. And of course never ever host any parts of it on any infrastructure located in the US or owned by a US company.
Alternatively to downloads, I could also make a software that asks the user to supply the NVIDIA installer binary and extracts the firmware out of it.
IANAL, but just because TOS claims something doesn't mean it is enforcable in all jurisdictions, and could potentially fall against certain interoperability or other provisions.
I'll bite. Has anyone traced the initialization of the NVIDIA binary driver and figured out what is so special for reclocking and/or reproduced it without the binary driver? If you do not want to reply publicly email is in profile.
Good luck
From what I understand [1], the chip itself will check if the running firmware has been signed by NVIDIA and refuse to run at higher clock speeds if not.
That way you'd have both high-speed acceleration and an as-far-as-possible open source driver.
Question wrt:
> If Linux doesn’t know a clock or power domain is used by the GPU, it’ll turn off the GPU inadvertently.
If you know the name and ID of the GPU, is there a command from the terminal to tell Linux to turn the thing back on?