Commit 4c5094d8 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/libwr: move create_map to libwr

Now wr_date depends on libwr.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 79959871
......@@ -4,6 +4,9 @@
#include <stdio.h>
#include <inttypes.h>
#include <time.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#define atoidef(str,def) (str)?atoi(str):def
......@@ -18,4 +21,7 @@ time_t get_monotonic_sec(void);
* the SoftPLL */
void strncpy_e(char *d, char *s, int len);
/* Create map */
void *create_map(unsigned long address, unsigned long size);
#endif /* __LIBWR_HW_UTIL_H */
......@@ -85,3 +85,26 @@ void strncpy_e(char *d, char *s, int len)
for (i = 0; i < len_4; i++)
d_i[i] = ntohl(s_i[i]);
}
void *create_map(unsigned long address, unsigned long size)
{
unsigned long ps = getpagesize();
unsigned long offset, fragment, len;
void *mapaddr;
int fd;
fd = open("/dev/mem", O_RDWR | O_SYNC);
if (fd < 0)
return NULL;
offset = address & ~(ps - 1);
fragment = address & (ps - 1);
len = address + size - offset;
mapaddr = mmap(0, len, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, offset);
close(fd);
if (mapaddr == MAP_FAILED)
return NULL;
return mapaddr + fragment;
}
......@@ -28,7 +28,6 @@ SOURCES = \
shmem.c \
dot-config.c \
snmp_shmem.c \
snmp_mmap.c \
util.c \
snmp_msg.c \
wrsScalar.c \
......
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include "snmp_mmap.h"
/* FIXME: this is copied from wr_date, should be librarized */
void *create_map(unsigned long address, unsigned long size)
{
unsigned long ps = getpagesize();
unsigned long offset, fragment, len;
void *mapaddr;
int fd;
fd = open("/dev/mem", O_RDWR | O_SYNC);
if (fd < 0)
return NULL;
offset = address & ~(ps - 1);
fragment = address & (ps - 1);
len = address + size - offset;
mapaddr = mmap(0, len, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, offset);
close(fd);
if (mapaddr == MAP_FAILED)
return NULL;
return mapaddr + fragment;
}
void *create_map(unsigned long address, unsigned long size);
#include "wrsSnmp.h"
#include "snmp_mmap.h"
#include <libwr/util.h>
#include "wrsBootStatusGroup.h"
#define BOOTCOUNT_FILE "/proc/wrs-bootcount"
......
#include "wrsSnmp.h"
#include "wrsCurrentTimeGroup.h"
#include "snmp_mmap.h"
#include <libwr/util.h>
/* defines for nic-hardware.h */
#define WR_SWITCH
......
#include "wrsSnmp.h"
#include <libwr/softpll.h>
#include <libwr/util.h>
#include "wrsSpllStatusGroup.h"
#include "snmp_mmap.h"
static struct spll_stats *spll_stats_p;
......
......@@ -2,7 +2,6 @@
#include "wrsSpllVersionGroup.h"
#include <libwr/softpll.h>
#include <libwr/util.h>
#include "snmp_mmap.h"
static struct spll_stats *spll_stats_p;
......
......@@ -18,6 +18,7 @@
#include <sys/time.h>
#include <sys/timex.h>
#include "../../kernel/wbgen-regs/ppsg-regs.h"
#include <libwr/util.h>
#ifndef MOD_TAI
#define MOD_TAI 0x80
......@@ -53,7 +54,7 @@ char *opt_cfgfile = WRDATE_CFG_FILE;
char *prgname;
/* Check that we actualy are on the wr switch, exit if not */
int wrdate_check_host(int fdmem)
int wrdate_check_host(void)
{
int ret;
......@@ -77,26 +78,6 @@ int wrdate_cfgfile(char *fname)
return 0;
}
/* create a map, that is never goind to be released */
void *create_map(int fdmem, unsigned long address, unsigned long size)
{
unsigned long ps = getpagesize();
unsigned long offset, fragment, len;
void *mapaddr;
offset = address & ~(ps -1);
fragment = address & (ps -1);
len = address + size - offset;
mapaddr = mmap(0, len, PROT_READ | PROT_WRITE,
MAP_SHARED, fdmem, offset);
if (mapaddr == MAP_FAILED) {
fprintf(stderr, "%s: mmap: %s\n", prgname, strerror(errno));
exit(1);
}
return mapaddr + fragment;
}
int wrdate_get(struct PPSG_WB *pps, int tohost)
{
int fix_host_tai(void); /* defined later */
......@@ -324,7 +305,7 @@ int wrdate_set(struct PPSG_WB *pps, char *arg)
int main(int argc, char **argv)
{
int c, fd, tohost = 0;
int c, tohost = 0;
char *cmd;
struct PPSG_WB *pps;
......@@ -353,15 +334,12 @@ int main(int argc, char **argv)
cmd = argv[optind++];
fd = open("/dev/mem", O_RDWR | O_SYNC);
if (fd < 0) {
fprintf(stderr, "%s: /dev/mem: %s\n", argv[0], strerror(errno));
wrdate_check_host();
pps = create_map(FPGA_BASE_PPSG, sizeof(*pps));
if (!pps) {
fprintf(stderr, "%s: mmap: %s\n", prgname, strerror(errno));
exit(1);
}
wrdate_check_host(fd);
pps = create_map(fd, FPGA_BASE_PPSG, sizeof(*pps));
close(fd);
wrdate_cfgfile(opt_cfgfile);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment