Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 1 | #include <stdint.h>
|
| 2 | #include <stdio.h>
|
| 3 | #include <stdlib.h>
|
| 4 | #include <string.h>
|
| 5 | #include <fcntl.h>
|
| 6 | #include <unistd.h>
|
| 7 | #include <sys/stat.h>
|
| 8 | #include <sys/mman.h>
|
| 9 | #include "interfaces/openbmc_intf.h"
|
| 10 | #include "openbmc.h"
|
| 11 | #include "gpio.h"
|
| 12 |
|
| 13 | /* ---------------------------------------------------------------------------------------------------- */
|
| 14 | static const gchar* dbus_object_path = "/org/openbmc/control";
|
| 15 | static const gchar* dbus_name = "org.openbmc.control.Bmc";
|
| 16 |
|
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 17 | //this probably should come from some global SOC config
|
| 18 |
|
| 19 | #define LPC_BASE 0x1e789000
|
| 20 | #define LPC_HICR6 0x80
|
| 21 | #define LPC_HICR7 0x88
|
| 22 | #define LPC_HICR8 0x8c
|
| 23 |
|
| 24 | #define SPI_BASE 0x1e630000
|
| 25 | #define SCU_BASE 0x1e780000
|
| 26 | #define UART_BASE 0x1e783000
|
| 27 | #define COM_BASE 0x1e789000
|
| 28 | #define GPIO_BASE 0x1e6e2000
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 29 |
|
| 30 | static GDBusObjectManagerServer *manager = NULL;
|
| 31 |
|
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 32 | void* memmap(int mem_fd,uint32_t* base)
|
| 33 | {
|
| 34 | void* bmcreg;
|
| 35 | bmcreg = mmap(NULL, getpagesize(),
|
| 36 | PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, base);
|
| 37 |
|
| 38 | if (bmcreg == MAP_FAILED) {
|
| 39 | perror("Unable to map LPC register memory");
|
| 40 | exit(1);
|
| 41 | }
|
| 42 | return bmcreg;
|
| 43 | }
|
| 44 |
|
| 45 | void reg_init()
|
| 46 | {
|
| 47 | g_print("BMC init\n");
|
| 48 | // BMC init done here
|
| 49 |
|
| 50 | void *bmcreg;
|
| 51 | int mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
|
| 52 | if (mem_fd < 0) {
|
| 53 | perror("Unable to open /dev/mem");
|
| 54 | exit(1);
|
| 55 | }
|
| 56 |
|
| 57 | bmcreg = memmap(mem_fd,LPC_BASE);
|
| 58 | devmem(bmcreg+LPC_HICR6,0x00000500); //Enable LPC FWH cycles, Enable LPC to AHB bridge
|
| 59 | devmem(bmcreg+LPC_HICR7,0x30000E00); //32M PNOR
|
| 60 | devmem(bmcreg+LPC_HICR8,0xFE0001FF);
|
| 61 |
|
| 62 | //flash controller
|
| 63 | bmcreg = memmap(mem_fd,SPI_BASE);
|
| 64 | devmem(bmcreg+0x00,0x00000003);
|
| 65 | devmem(bmcreg+0x04,0x00002404);
|
| 66 |
|
| 67 | //UART
|
| 68 |
|
| 69 |
|
| 70 | bmcreg = memmap(mem_fd,UART_BASE);
|
| 71 | devmem(bmcreg+0x00,0x00000000); //Set Baud rate divisor -> 13 (Baud 115200)
|
| 72 | devmem(bmcreg+0x04,0x00000000); //Set Baud rate divisor -> 13 (Baud 115200)
|
| 73 | devmem(bmcreg+0x08,0x000000c1); //Disable Parity, 1 stop bit, 8 bits
|
| 74 | bmcreg = memmap(mem_fd,COM_BASE);
|
| 75 | devmem(bmcreg+0x9C,0x00000000); //Set routing UART1 -> COM 1
|
| 76 |
|
| 77 | bmcreg = memmap(mem_fd,SCU_BASE);
|
| 78 | devmem(bmcreg+0x00,0x13008CE7);
|
| 79 | devmem(bmcreg+0x04,0x0370E677);
|
| 80 | devmem(bmcreg+0x20,0xDF48F7FF);
|
| 81 | devmem(bmcreg+0x24,0xC738F202);
|
| 82 |
|
| 83 |
|
| 84 | //GPIO
|
| 85 | bmcreg = memmap(mem_fd,GPIO_BASE);
|
| 86 | devmem(bmcreg+0x84,0x00fff0c0); //Enable UART1
|
| 87 | devmem(bmcreg+0x70,0x120CE406);
|
| 88 | devmem(bmcreg+0x80,0xCB000000);
|
| 89 | devmem(bmcreg+0x88,0x01C000FF);
|
| 90 | devmem(bmcreg+0x8c,0xC1C000FF);
|
| 91 | devmem(bmcreg+0x90,0x003FA009);
|
| 92 |
|
| 93 |
|
| 94 | close(mem_fd);
|
| 95 | }
|
| 96 |
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 97 | static gboolean
|
| 98 | on_init (Control *control,
|
| 99 | GDBusMethodInvocation *invocation,
|
| 100 | gpointer user_data)
|
| 101 | {
|
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 102 | #ifdef __arm__
|
| 103 | reg_init();
|
| 104 | #endif
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 105 | control_complete_init(control,invocation);
|
| 106 | control_emit_goto_system_state(control,"STANDBY");
|
| 107 |
|
| 108 | return TRUE;
|
| 109 | }
|
| 110 |
|
| 111 | static void
|
| 112 | on_bus_acquired (GDBusConnection *connection,
|
| 113 | const gchar *name,
|
| 114 | gpointer user_data)
|
| 115 | {
|
| 116 | ObjectSkeleton *object;
|
| 117 | //g_print ("Acquired a message bus connection: %s\n",name);
|
| 118 | cmdline *cmd = user_data;
|
| 119 | if (cmd->argc < 2)
|
| 120 | {
|
| 121 | g_print("No objects created. Put object name(s) on command line\n");
|
| 122 | return;
|
| 123 | }
|
| 124 | manager = g_dbus_object_manager_server_new (dbus_object_path);
|
| 125 | int i=0;
|
| 126 | for (i=1;i<cmd->argc;i++)
|
| 127 | {
|
| 128 | gchar *s;
|
| 129 | s = g_strdup_printf ("%s/%s",dbus_object_path,cmd->argv[i]);
|
| 130 | object = object_skeleton_new (s);
|
| 131 | g_free (s);
|
| 132 |
|
| 133 | ControlBmc* control_bmc = control_bmc_skeleton_new ();
|
| 134 | object_skeleton_set_control_bmc (object, control_bmc);
|
| 135 | g_object_unref (control_bmc);
|
| 136 |
|
| 137 | Control* control = control_skeleton_new ();
|
| 138 | object_skeleton_set_control (object, control);
|
| 139 | g_object_unref (control);
|
| 140 |
|
| 141 | EventLog* event_log = event_log_skeleton_new ();
|
| 142 | object_skeleton_set_event_log (object, event_log);
|
| 143 | g_object_unref (event_log);
|
| 144 |
|
| 145 | //define method callbacks here
|
| 146 | g_signal_connect (control,
|
| 147 | "handle-init",
|
| 148 | G_CALLBACK (on_init),
|
| 149 | NULL); /* user_data */
|
| 150 |
|
| 151 | /* Export the object (@manager takes its own reference to @object) */
|
| 152 | g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
|
| 153 | g_object_unref (object);
|
| 154 | }
|
| 155 | /* Export all objects */
|
| 156 | g_dbus_object_manager_server_set_connection (manager, connection);
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 157 | }
|
| 158 |
|
| 159 | static void
|
| 160 | on_name_acquired (GDBusConnection *connection,
|
| 161 | const gchar *name,
|
| 162 | gpointer user_data)
|
| 163 | {
|
| 164 | // g_print ("Acquired the name %s\n", name);
|
| 165 | }
|
| 166 |
|
| 167 | static void
|
| 168 | on_name_lost (GDBusConnection *connection,
|
| 169 | const gchar *name,
|
| 170 | gpointer user_data)
|
| 171 | {
|
| 172 | // g_print ("Lost the name %s\n", name);
|
| 173 | }
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 | /*----------------------------------------------------------------*/
|
| 179 | /* Main Event Loop */
|
| 180 |
|
| 181 | gint
|
| 182 | main (gint argc, gchar *argv[])
|
| 183 | {
|
| 184 | GMainLoop *loop;
|
| 185 | cmdline cmd;
|
| 186 | cmd.argc = argc;
|
| 187 | cmd.argv = argv;
|
| 188 |
|
| 189 | guint id;
|
| 190 | loop = g_main_loop_new (NULL, FALSE);
|
| 191 |
|
| 192 | id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
| 193 | dbus_name,
|
| 194 | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
| 195 | G_BUS_NAME_OWNER_FLAGS_REPLACE,
|
| 196 | on_bus_acquired,
|
| 197 | on_name_acquired,
|
| 198 | on_name_lost,
|
| 199 | &cmd,
|
| 200 | NULL);
|
| 201 |
|
| 202 | g_main_loop_run (loop);
|
| 203 |
|
| 204 | g_bus_unown_name (id);
|
| 205 | g_main_loop_unref (loop);
|
| 206 | return 0;
|
| 207 | }
|