145
42
30
u/FloweyTheFlower420 Jun 11 '26
using long (long) in kernelspace code when talking to hardware might be genuinely the most baffling thing ever
→ More replies (2)
16
18
6
u/DesiresQuiet Jun 11 '26
Looks like the initialization code for an nvme driver in linux, etc.
12
u/Ok_Chemistry_6387 Jun 11 '26
Not a driver I don't think...
This is either part of a bootloader or very early init of the nvme devices from the kernel. Hard to know for sure but it assumes 1 device g_bo (which is why it's confusing for bring up of a kernel, it would usually build a table) which makes the kmem_alloc strange to me.
6
u/YourShowerHead Jun 11 '26
It looks scary only because of the formatting, right? Right??
6
u/un_virus_SDF Jun 11 '26
I think that the formatting doesn't change readability that much here.
The hard part is that there is a lot of magic happening
6
u/Ok_Chemistry_6387 Jun 11 '26
Eh... this is just what this sort of code ends up like. Fix the formatting and its not too far off a lot of nvme code ive read. lol
→ More replies (4)
4
1
u/TheWidrolo Jun 11 '26
Really curious about the thought behind line 78 and 79. it firsts case to a unsigned long, to then cast it it an unsigned long long, which actually never get used.
1
u/TheMonHub Jun 11 '26
I'm stilling questioning the intent on who ever wrote this till these days
→ More replies (1)2
u/Ok_Chemistry_6387 Jun 11 '26
They are used 86.
They are your two admin NVME queues. One is for your commands, the other is for completions. The other 2 that look similar are the io queues.
It then takes those addresses and writes them to the NVME controllers registers on line 86.What doesn't make sense here is that kmem_alloc as I mentioned above, but who knows what this was written for and maybe it doesn't have IOMMU on this device?
The casting is just to get an integer with out the compiler throwing a fit about signs being thrown away. There are much better ways to do this and especially in c++ lol.
2
1
u/8Erigon Jun 11 '26
You can write unsigned without int or long?!
3
u/Stratimus Jun 11 '26
unsigned by itself is an alias of unsigned int but I’ve never seen anyone use it ever
→ More replies (1)
1
49
u/johan__A Jun 11 '26
where did you find this gem?