2
\$\begingroup\$

With microcontrollers it is pretty easy to switch a LED on/off, by writing on a register.

This question is instead an attempt to write to a PCI device register in a desktop computer.

In a similar way, I would like to read/write the registers in the motherboard to control fans (on, off or even speed) or the power or hard disk LEDs, or temperature sensors.

Given - for example - an Asus motherboard and a Linux OS, is it possible? And what kind of datasheet should be readed, if it exists, to obtain the register names in the motherboard? I never found for a consumer motherboard something like the datasheet of a microcontroller.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Take a look at the Intel motherboard chipset datasheets on their website. \$\endgroup\$
    – TonyM
    Jul 7, 2016 at 8:29
  • 1
    \$\begingroup\$ For linux, take a look at "lm-sensors". \$\endgroup\$
    – pjc50
    Jul 7, 2016 at 11:04
  • \$\begingroup\$ Power led, hardwired. HD led, hardwired, fans, only if not hardwired, temperature sensors, read only. None of what you want is typically gpio controlled by most motherboards. \$\endgroup\$
    – Passerby
    Jul 7, 2016 at 17:55
  • \$\begingroup\$ If your looking to talk to the motherboard through a PCI bus you'll need something like this. ics.uci.edu/~harris/ics216/pci/PCI_22.pdf \$\endgroup\$
    – smcmurphy
    Sep 1, 2016 at 1:01

2 Answers 2

2
\$\begingroup\$

The documentation no doubt exists. Not always freely available but it exists.

There is always linux and bsd source code you can read as well if they support these peripherals, there you go (yes I know that is not always an easy read).

If there is already a device driver for this peripheral then learn how to communicate with that device driver. lm-sensors as pjc50 commented is one example.

If not you can often punch through the operating system protection with mmap() and from the application talk to things directly. Depending on what you are trying to do (mother board test equipment, pcie card test equipment, etc) that may suffice. The correct way to do it is modify or write a kernel driver and talk to/through it to get at the peripheral, can be as thin or thick of a driver as you desire but at least the last mile of writes/reads come from the kernel space not application.

Note DOS is still used for motherboard and other testing being one of the best bare metal operating systems (intentional oxymoron), and if you are working closely with a motherboard company they might provide the source or snippets of code from their test programs that blink leds or read the temperature sensor, etc.

Yes motherboard documentation even if you have access is not the same as a microcontroller, the audience is different, it is often only the bios programmers (contractors) and internal test folks that need the documentation, and that is it so it could be scribbles on a whiteboard.

Being a PC what an operating system needs is defined by convention or discoverable, so you dont need documentation, you just programmatically search for things and find what is present. As needed based on what you find then you go to that specific chip vendors site to get the datasheet (which does read like a microcontrollers) for that part. some pcie bridge chip from intel, right there at intels web site. A usb bridge or master, same deal. Video card, well they might not be as open. Hard disk controller, find the datasheet. Ethernet, find the datasheet and read it. lspci is your friend. lsusb is your friend. google is your friend.

\$\endgroup\$
1
  • \$\begingroup\$ Unlike lspci, there might not be existing command line programs that punch through the operating system protection that allow you to poke at anything you want. Depending on what and where it is you might have to write a program and that is where mmap() comes in. \$\endgroup\$
    – old_timer
    Jul 7, 2016 at 11:28
2
\$\begingroup\$

Writing code for Linux is a lot different than writing code for a microcontroller. In a modern operating system, you make calls through the OS, to a driver, which then talks to specific hardware - not doing all of this work directly yourself.

A small microcontroller may have a datasheet 600 pages long... datasheets are not made about an entire computer because it would be ten thousand pages or more, and be different for every single hardware change. Furthermore, some IC's used inside, such as the GPU, contain intellectual property, meaning the vendor doesn't want to share how it works. They create the drivers. But over time, many of the core functions of the computer have standardized at certain addresses, such as COM1 being 0x3F8 and LPT1 being 0x3BC. (UEFI is a whole other story.) In Linux, try these to find device addresses. Keep in mind, the computer's BIOS sets many of these addresses, but modern OS's don't have to use the BIOS at all.

The only way a computer and microcontroller are remotely comparable is at the assembler language level. And even then there are many differences between them, but at least they share physical registers, I/O addresses, and instructions. For linux, programming in assembler would likely be done using NASM. Searching the web turns up a lot, such as Accessing Sound Card Directly in NASM (no OS). Even an entire operating system (MenuetOS) has been written in assembler, however it uses a slightly different syntax (FASM). Still it might be interesting to see how they are accessing things, just out of curiosity. For MS Windows users, see MASM32 and GoASM.

Assembler can still be used today for everything from application programming to OS development, but it's rather antiquated. Expect a very steep learning curve if you pick assembler... not because assembler is inherently difficult, but because you probably want to use an OS, and that adds a huge amount of ambiguity and complication to assembler. Likewise, the MenuetOS developer has been working on their OS since 2005. C and other higher-level languages hide much of this complexity, therefore most people find this preferable.

But it sounds like what you want to do is write a driver. Drivers can access the hardware. Much information can be found by searching for how+to+write+driver+Linux such as this, but what you probably want is more like Writing Device Drivers in Linux. Which is far too long to place here. Suffice it to say, a good (modern) book on writing device drivers in linux would be your best bet.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.