blob: 2068fb9c11502c4b1b315b844c3dda9de2a977e0 [file] [log] [blame]
Andrew Jeffery9fc79232017-04-12 14:26:00 +09301/*
2 * MBox Daemon Test File
3 *
4 * Copyright 2017 IBM
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20#include <linux/types.h>
21#include <mtd/mtd-user.h>
22#include <stdarg.h>
23#include <stdint.h>
24#include <stdio.h>
25#include <string.h>
26#include <sys/mman.h>
27
28#include "linux/aspeed-lpc-ctrl.h"
29
30static struct aspeed_lpc_ctrl_mapping ctrl = {
31};
32
33static struct mtd_info_user mtd = {
34 .type = MTD_NORFLASH,
35 .flags = MTD_WRITEABLE,
36};
37
38void system_set_reserved_size(uint32_t size)
39{
40 ctrl.size = size;
41}
42
43void system_set_mtd_sizes(uint32_t size, uint32_t erasesize)
44{
45 mtd.size = size;
46 mtd.erasesize = erasesize;
47 mtd.writesize = erasesize;
48}
49
50int ioctl(int fd, unsigned long request, ...)
51{
52 int rc = 0;
53 va_list ap;
54
55 switch (request) {
56 case MEMGETINFO:
57 {
58 struct mtd_info_user *info;
59
60 va_start(ap, request);
61 info = va_arg(ap, struct mtd_info_user *);
62 memcpy(info, &mtd, sizeof(mtd));
63 va_end(ap);
64 break;
65 }
66 case MEMERASE:
67 {
68 struct erase_info_user *info;
69 uint8_t *map;
70
71 va_start(ap, request);
72 info = va_arg(ap, struct erase_info_user *);
73
74 if (info->start + info->length > mtd.size)
75 return -1;
76
77 map = mmap(NULL, mtd.size, PROT_WRITE, MAP_SHARED, fd, 0);
78 if (map == MAP_FAILED)
79 return -1;
80
81 memset(&map[info->start], 0xff, info->length);
82 munmap(map, mtd.size);
83
84 va_end(ap);
85 break;
86 }
87 case ASPEED_LPC_CTRL_IOCTL_GET_SIZE:
88 {
89 struct aspeed_lpc_ctrl_mapping *info;
90
91 va_start(ap, request);
92 info = va_arg(ap, struct aspeed_lpc_ctrl_mapping *);
Andrew Jefferyc2c08682018-03-02 10:14:59 +103093 info->size = ctrl.size;
Andrew Jeffery9fc79232017-04-12 14:26:00 +093094 va_end(ap);
95 break;
96 }
97 case ASPEED_LPC_CTRL_IOCTL_MAP:
98 break;
99 default:
100 printf("ioctl() called with unhandled request 0x%08lx\n", request);
101 rc = -1;
102 break;
103 }
104
105 return rc;
106}