2 /*
3 * Copyright (c) 2014, Mentor Graphics Corporation
4 * All rights reserved.
5 *
6 * Copyright (c) 2015 Xilinx, Inc. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * 3. Neither the name of the <ORGANIZATION> nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32 #include <string.h>
33 #include <stdio.h>
34 #include "metal/sys.h"
35 #include "metal/shmem.h"
36 #include "metal/device.h"
37 #include "metal/io.h"
39 #define SHM_DEV_NAME "3ed80000.shm"
40 #define SHM_BUS_NAME "platform"
42 static struct metal_device *shm_dev;
43 static struct metal_generic_shmem shm;
45 void init_system()
46 {
47 int ret;
48 struct metal_io_region *io;
49 struct metal_init_params metal_param = METAL_INIT_DEFAULTS;
51 metal_init(&metal_param);
53 /* Register the UIO shared memory */
54 /* This will be a temporary solution, we should
55 * use DMA memory in fugure.
56 */
57 ret = metal_device_open(SHM_BUS_NAME, SHM_DEV_NAME, &shm_dev);
58 if (ret) {
59 fprintf(stderr, "ERROR: Failed to open shared memory device.\n");
60 return;
61 }
62 io = metal_device_io_region(shm_dev, 0);
63 if (!io) {
64 fprintf(stderr, "ERROR: Failed to get the I/O region of shared memory.\n");
65 return;
66 }
68 memset(&shm, 0, sizeof(struct metal_generic_shmem));
69 shm.name = "shm";
70 memcpy((void *)&shm.io, io, sizeof(struct metal_io_region));
71 ret = metal_shmem_register_generic(&shm);
72 if (ret) {
73 fprintf(stderr, "ERROR: Failed to registered shared memory.\n");
74 return;
75 }
76 return;
77 }
79 void cleanup_system()
80 {
81 if (shm_dev)
82 metal_device_close(shm_dev);
83 metal_finish();
84 }