Writing/Accessing I/O port hardware watchdog register linux

1.8k Views Asked by At

I am trying to access/write to the hardware watchdog on the CPU from Linux. This is something I have never done before so my knowledge is very little. The link for the RTD user manual is http://www.rtd.com/NEW_manuals/hardware/cpumodules/CMV34M_BDM610000077A.pdf (see page 64 for watchdog timer information) and my small example program which I found on the internet and edited. I enabled the Watchdog Setup Register in the BIOS, and ran the attached program. The program runs and doesn’t output any errors, but doesn’t seem to actually do anything as my system doesn’t reset(as it should if you don’t “kick the dog”) even though I am enabling watchdog by writing 1s. Was hoping maybe someone would have insight as to what I am doing wrong.

#include <stdio.h>
#include <unistd.h>
#include <sys/io.h>
#include <stdlib.h>

#define BASEPORT 0x985

int main()
{
  /* Get access to the ports */
  if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}

  /* Set the data signals (D0-7) of the port to all high (1) */
  outb(1, BASEPORT);

  /* Sleep for a while (100 ms) */
  usleep(100000);

  /* Read from the status port (BASE+1) and display the result */
  printf("status: %d\n", inb(BASEPORT + 1));

  /* We don't need the ports anymore */
  if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}

  exit(0);
}
3

There are 3 best solutions below

0
On

The doc for ioperm says, If turn_on is nonzero, the calling thread must be privileged (CAP_SYS_RAWIO). You need to ensure this condition is met. Also, your call outb(1, BASEPORT) just sets BASEPORT to 0x01, not "all high" as your comment says. If you want "all high", you need outb(0xFF, BASEPORT).

0
On

Try with iopl(3) before your outb() commands. iopl() is not really a "nice" and portable command, but I used it successfully for a similar watchdog issue.

0
On

If you are thinking of using the watchdog timer, you might want to do it the normal way by writing a driver for that bit of hardware that presents the /dev/watchdog interface, and then using the watchdog daemon that supports several system-wide tests as well as simply keeping the dog fed.

Examples of existing watchdog drivers' code can be found here:

http://tomoyo.sourceforge.jp/cgi-bin/lxr/source/drivers/watchdog/

Information on the watchdog daemon's operation (and my own experimental version) can be found here:

http://www.sat.dundee.ac.uk/~psc/watchdog/Linux-Watchdog.html