EXTENSION class Pic
{
public:
- static int irq_pending();
- static void eat(unsigned);
- static void set_owner(int);
- static unsigned int map_irq_to_gate(unsigned);
- static bool setup_irq_prov (unsigned irq,
- const char * const path,
- void (*bootstrap_func)());
- static void irq_prov_shutdown();
- static unsigned int get_pid_for_irq_prov(unsigned);
- static bool get_ipi_gate(unsigned irq, unsigned long &gate);
-
- enum {
- IRQ_TIMER = Config::Scheduling_irq,
- IRQ_CON = 1,
- IRQ_NET = 2,
+ static int irq_pending();
+ static void eat(unsigned);
+ static void set_owner(int);
+ static unsigned int map_irq_to_gate(unsigned);
+ static bool setup_irq_prov(unsigned irq, const char * const path,
+ void (*bootstrap_func)());
+ static void irq_prov_shutdown();
+ static unsigned int get_pid_for_irq_prov(unsigned);
+ static bool get_ipi_gate(unsigned irq, unsigned long &gate);
+
+ enum
+ {
+ Irq_timer = 0,
+ Irq_con = 1,
+ Irq_net = 2,
Num_dev_irqs = 4,
- IRQ_IPI_base = 4,
+ Irq_ipi_base = 4,
Num_irqs = 4 + Config::Max_num_cpus,
};
private:
- static unsigned int highest_irq;
- static unsigned int pids[Pic::Num_irqs];
- static struct pollfd pfd[Pic::Num_irqs];
+ static unsigned int highest_irq;
+ static unsigned int pids[Pic::Num_irqs];
+ static struct pollfd pfd[Pic::Num_irqs];
};
// ------------------------------------------------------------------------
EXTENSION class Pic
{
public:
- static void send_ipi(unsigned _cpu, unsigned char data);
- static bool setup_ipi(unsigned _cpu, int _tid);
+ static void send_ipi(Cpu_number _cpu, unsigned char data);
+ static bool setup_ipi(Cpu_number _cpu, int _tid);
private:
- static unsigned int ipi_fds[Config::Max_num_cpus];
+ typedef Per_cpu_array<unsigned> Fd_array;
+ static Fd_array ipi_fds;
};
// ------------------------------------------------------------------------
#include "emulation.h"
#include "initcalls.h"
-unsigned int Pic::highest_irq;
-unsigned int Pic::pids[Num_irqs];
-struct pollfd Pic::pfd[Num_irqs];
+unsigned int Pic::highest_irq;
+unsigned int Pic::pids[Num_irqs];
+struct pollfd Pic::pfd[Num_irqs];
PUBLIC static inline
unsigned
{
struct termios tt;
- if (openpty (&sockets[0], &sockets[1], NULL, NULL, NULL))
+ if (openpty(&sockets[0], &sockets[1], NULL, NULL, NULL))
{
- perror ("openpty");
+ perror("openpty");
return false;
}
- if (tcgetattr (sockets[0], &tt) < 0)
+ if (tcgetattr(sockets[0], &tt) < 0)
{
- perror ("tcgetattr");
+ perror("tcgetattr");
return false;
}
- cfmakeraw (&tt);
+ cfmakeraw(&tt);
- if (tcsetattr (sockets[0], TCSADRAIN, &tt) < 0)
+ if (tcsetattr(sockets[0], TCSADRAIN, &tt) < 0)
{
- perror ("tcsetattr");
+ perror("tcsetattr");
return false;
}
- fflush (NULL);
+ fflush(NULL);
return true;
}
IMPLEMENT
bool
-Pic::setup_irq_prov (unsigned irq, const char * const path,
- void (*bootstrap_func)())
+Pic::setup_irq_prov(unsigned irq, const char * const path,
+ void (*bootstrap_func)())
{
int sockets[2];
- if (access (path, X_OK | F_OK))
+ if (access(path, X_OK | F_OK))
{
- perror (path);
+ perror(path);
return false;
}
break;
default:
- close (sockets[1]);
- fcntl (sockets[0], F_SETFD, FD_CLOEXEC);
+ close(sockets[1]);
+ fcntl(sockets[0], F_SETFD, FD_CLOEXEC);
pfd[irq].fd = sockets[0];
return true;
}
// Unblock all signals except SIGINT, we enter jdb with it and don't want
// the irq providers to die
sigset_t mask;
- sigemptyset (&mask);
- sigaddset (&mask, SIGINT);
- sigprocmask (SIG_SETMASK, &mask, NULL);
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGINT);
+ sigprocmask(SIG_SETMASK, &mask, NULL);
- fclose (stdin);
- fclose (stdout);
- fclose (stderr);
+ fclose(stdin);
+ fclose(stdout);
+ fclose(stderr);
- dup2 (sockets[1], 0);
- close (sockets[0]);
- close (sockets[1]);
+ dup2(sockets[1], 0);
+ close(sockets[0]);
+ close(sockets[1]);
bootstrap_func();
- _exit (EXIT_FAILURE);
+ _exit(EXIT_FAILURE);
}
IMPLEMENT
IMPLEMENT inline NEEDS [<cassert>, <csignal>, <fcntl.h>, "boot_info.h"]
void
-Pic::enable_locked (unsigned irq, unsigned /*prio*/)
+Pic::enable_locked(unsigned irq, unsigned /*prio*/)
{
int flags;
// If fd is zero, someone tried to activate an IRQ without provider
assert (pfd[irq].fd);
- if ((flags = fcntl (pfd[irq].fd, F_GETFL)) < 0 ||
- fcntl (pfd[irq].fd, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0 ||
- fcntl (pfd[irq].fd, F_SETSIG, SIGIO) < 0 ||
- fcntl (pfd[irq].fd, F_SETOWN, Boot_info::pid()) < 0)
+ if ((flags = fcntl(pfd[irq].fd, F_GETFL)) < 0 ||
+ fcntl(pfd[irq].fd, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0 ||
+ fcntl(pfd[irq].fd, F_SETSIG, SIGIO) < 0 ||
+ fcntl(pfd[irq].fd, F_SETOWN, Boot_info::pid()) < 0)
return;
pfd[irq].events = POLLIN;
IMPLEMENT inline
void
-Pic::disable_locked (unsigned)
+Pic::disable_locked(unsigned)
{}
IMPLEMENT inline
void
-Pic::acknowledge_locked (unsigned)
+Pic::acknowledge_locked(unsigned)
{}
IMPLEMENT inline
void
-Pic::block_locked (unsigned)
+Pic::block_locked(unsigned)
{}
IMPLEMENT
for (i = 0; i < highest_irq; i++)
pfd[i].revents = 0;
- if (poll (pfd, highest_irq, 0) > 0)
+ if (poll(pfd, highest_irq, 0) > 0)
for (i = 0; i < highest_irq; i++)
if (pfd[i].revents & POLLIN)
{
IMPLEMENT inline NEEDS [<cassert>, <unistd.h>]
void
-Pic::eat (unsigned irq)
+Pic::eat(unsigned irq)
{
char buffer[8];
assert (pfd[irq].events & POLLIN);
- while (read (pfd[irq].fd, buffer, sizeof (buffer)) > 0)
+ while (read(pfd[irq].fd, buffer, sizeof (buffer)) > 0)
;
}
*/
IMPLEMENT inline
void
-Pic::set_owner (int pid)
+Pic::set_owner(int pid)
{
for (unsigned int i = 0; i < highest_irq; i++)
if (pfd[i].events & POLLIN)
- fcntl (pfd[i].fd, F_SETOWN, pid);
+ fcntl(pfd[i].fd, F_SETOWN, pid);
}
IMPLEMENT inline
unsigned int
-Pic::map_irq_to_gate (unsigned irq)
+Pic::map_irq_to_gate(unsigned irq)
{
return 0x20 + irq;
}
#include "ipi.h"
-unsigned int Pic::ipi_fds[Config::Max_num_cpus];
+Pic::Fd_array Pic::ipi_fds;
IMPLEMENT
void
-Pic::set_cpu(unsigned irq_num, unsigned cpu)
+Pic::set_cpu(unsigned irq_num, Cpu_number cpu)
{
printf("Pic::set_cpu(%d, %d)\n", irq_num, cpu);
}
IMPLEMENT static
bool
-Pic::setup_ipi(unsigned _cpu, int _tid)
+Pic::setup_ipi(Cpu_number _cpu, int _tid)
{
int sockets[2], flags;
if (prepare_irq(sockets) == false)
return false;
- unsigned i = IRQ_IPI_base + _cpu;
+ unsigned i = Irq_ipi_base + _cpu;
pfd[i].fd = sockets[0];
ipi_fds[_cpu] = sockets[1];
- if ((flags = fcntl (pfd[i].fd, F_GETFL)) < 0 ||
- fcntl (pfd[i].fd, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0 ||
- fcntl (pfd[i].fd, F_SETSIG, SIGIO) < 0 ||
- fcntl (pfd[i].fd, F_SETOWN, _tid) < 0)
+ if ((flags = fcntl(pfd[i].fd, F_GETFL)) < 0 ||
+ fcntl(pfd[i].fd, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0 ||
+ fcntl(pfd[i].fd, F_SETSIG, SIGIO) < 0 ||
+ fcntl(pfd[i].fd, F_SETOWN, _tid) < 0)
return false;
pfd[i].events = POLLIN;
IMPLEMENT
void
-Pic::send_ipi(unsigned _cpu, unsigned char data)
+Pic::send_ipi(Cpu_number _cpu, unsigned char data)
{
if (ipi_fds[_cpu])
if (write(ipi_fds[_cpu], &data, sizeof(data)) != sizeof(data))
bool
Pic::get_ipi_gate(unsigned irq, unsigned long &gate)
{
- if (irq < IRQ_IPI_base)
+ if (irq < Irq_ipi_base)
return false;
// XXX check if irq is the irq for our current context/cpu
unsigned char b;
- if (read (pfd[irq].fd, &b, sizeof(b)) < 1)
+ if (read(pfd[irq].fd, &b, sizeof(b)) < 1)
{
printf("read failure\n");
return false;