blob: 9ceaf9b034d0e317aacd435dbbfadf8970ecd07d [file] [log] [blame]
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include "interfaces/openbmc_intf.h"
#include "openbmc.h"
#include "gpio.h"
/* ---------------------------------------------------------------------------------------------------- */
static const gchar* dbus_object_path = "/org/openbmc/control";
static const gchar* dbus_name = "org.openbmc.control.Bmc";
//this probably should come from some global SOC config
#define LPC_BASE 0x1e789000
#define LPC_HICR6 0x80
#define LPC_HICR7 0x88
#define LPC_HICR8 0x8c
#define SPI_BASE 0x1e630000
#define SCU_BASE 0x1e780000
#define UART_BASE 0x1e783000
#define COM_BASE 0x1e789000
#define GPIO_BASE 0x1e6e2000
static GDBusObjectManagerServer *manager = NULL;
void* memmap(int mem_fd,uint32_t* base)
{
void* bmcreg;
bmcreg = mmap(NULL, getpagesize(),
PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, base);
if (bmcreg == MAP_FAILED) {
perror("Unable to map LPC register memory");
exit(1);
}
return bmcreg;
}
void reg_init()
{
g_print("BMC init\n");
// BMC init done here
void *bmcreg;
int mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
if (mem_fd < 0) {
perror("Unable to open /dev/mem");
exit(1);
}
bmcreg = memmap(mem_fd,LPC_BASE);
devmem(bmcreg+LPC_HICR6,0x00000500); //Enable LPC FWH cycles, Enable LPC to AHB bridge
devmem(bmcreg+LPC_HICR7,0x30000E00); //32M PNOR
devmem(bmcreg+LPC_HICR8,0xFE0001FF);
//flash controller
bmcreg = memmap(mem_fd,SPI_BASE);
devmem(bmcreg+0x00,0x00000003);
devmem(bmcreg+0x04,0x00002404);
//UART
bmcreg = memmap(mem_fd,UART_BASE);
devmem(bmcreg+0x00,0x00000000); //Set Baud rate divisor -> 13 (Baud 115200)
devmem(bmcreg+0x04,0x00000000); //Set Baud rate divisor -> 13 (Baud 115200)
devmem(bmcreg+0x08,0x000000c1); //Disable Parity, 1 stop bit, 8 bits
bmcreg = memmap(mem_fd,COM_BASE);
devmem(bmcreg+0x9C,0x00000000); //Set routing UART1 -> COM 1
bmcreg = memmap(mem_fd,SCU_BASE);
devmem(bmcreg+0x00,0x13008CE7);
devmem(bmcreg+0x04,0x0370E677);
devmem(bmcreg+0x20,0xDF48F7FF);
devmem(bmcreg+0x24,0xC738F202);
//GPIO
bmcreg = memmap(mem_fd,GPIO_BASE);
devmem(bmcreg+0x84,0x00fff0c0); //Enable UART1
devmem(bmcreg+0x70,0x120CE406);
devmem(bmcreg+0x80,0xCB000000);
devmem(bmcreg+0x88,0x01C000FF);
devmem(bmcreg+0x8c,0xC1C000FF);
devmem(bmcreg+0x90,0x003FA009);
close(mem_fd);
}
static gboolean
on_init (Control *control,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
#ifdef __arm__
reg_init();
#endif
control_complete_init(control,invocation);
control_emit_goto_system_state(control,"STANDBY");
return TRUE;
}
static void
on_bus_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
ObjectSkeleton *object;
//g_print ("Acquired a message bus connection: %s\n",name);
cmdline *cmd = user_data;
if (cmd->argc < 2)
{
g_print("No objects created. Put object name(s) on command line\n");
return;
}
manager = g_dbus_object_manager_server_new (dbus_object_path);
int i=0;
for (i=1;i<cmd->argc;i++)
{
gchar *s;
s = g_strdup_printf ("%s/%s",dbus_object_path,cmd->argv[i]);
object = object_skeleton_new (s);
g_free (s);
ControlBmc* control_bmc = control_bmc_skeleton_new ();
object_skeleton_set_control_bmc (object, control_bmc);
g_object_unref (control_bmc);
Control* control = control_skeleton_new ();
object_skeleton_set_control (object, control);
g_object_unref (control);
EventLog* event_log = event_log_skeleton_new ();
object_skeleton_set_event_log (object, event_log);
g_object_unref (event_log);
//define method callbacks here
g_signal_connect (control,
"handle-init",
G_CALLBACK (on_init),
NULL); /* user_data */
/* Export the object (@manager takes its own reference to @object) */
g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
g_object_unref (object);
}
/* Export all objects */
g_dbus_object_manager_server_set_connection (manager, connection);
}
static void
on_name_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
// g_print ("Acquired the name %s\n", name);
}
static void
on_name_lost (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
// g_print ("Lost the name %s\n", name);
}
/*----------------------------------------------------------------*/
/* Main Event Loop */
gint
main (gint argc, gchar *argv[])
{
GMainLoop *loop;
cmdline cmd;
cmd.argc = argc;
cmd.argv = argv;
guint id;
loop = g_main_loop_new (NULL, FALSE);
id = g_bus_own_name (G_BUS_TYPE_SESSION,
dbus_name,
G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
G_BUS_NAME_OWNER_FLAGS_REPLACE,
on_bus_acquired,
on_name_acquired,
on_name_lost,
&cmd,
NULL);
g_main_loop_run (loop);
g_bus_unown_name (id);
g_main_loop_unref (loop);
return 0;
}