Skip to content

Commit f5faba7

Browse files
author
Open XT
committed
Initial commit
0 parents  commit f5faba7

29 files changed

Lines changed: 3856 additions & 0 deletions

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
*.o
2+
*.lo
3+
*.la
4+
*.swp
5+
Makefile.in
6+
Makefile
7+
configure
8+
config.*
9+
libpciemu-config.pc
10+
libpciemu-config.pc.src
11+
src/stamp-h1
12+
version.sed
13+
install-sh
14+
missing
15+
.libs
16+
libpciemu-config
17+
libpciemu-config.src
18+
libpciemu.pc
19+
libpciemu.pc.src
20+
tags
21+
compile
22+
depcomp
23+
app/fake-pci
24+
ltmain.sh
25+
m4
26+
aclocal-copy
27+
aclocal.m4
28+
autom4te.m4
29+
autom4te.cache

AUTHORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Julien Grall <julien.grall@citrix.com>
2+
Julian Pidancet <julian.pidancet@citrix.com>

COPYING

Lines changed: 458 additions & 0 deletions
Large diffs are not rendered by default.

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Change for v1.1.0
2+
- Add a demo application.
3+
Change for v1.2.0
4+
- Prefix all export function/variable/structure... with libpciemu_ to
5+
avoid name clash with the application;
6+
- Export only the needed functions;
7+
- The application need to provide a callback to log message;
8+
- Use a single callback for I/O instead of 3.

Makefile.am

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
# Copyright (c) 2013 Citrix Systems, Inc.
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation; either
7+
# version 2.1 of the License, or (at your option) any later version.
8+
#
9+
# This library is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
# Lesser General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Lesser General Public
15+
# License along with this library; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
#
18+
19+
SUBDIRS = src
20+
EXTRA_DIST = version-major version-minor version-micro version-files version-md5sums
21+
bin_SCRIPTS = libpciemu-config
22+
23+
pkgconfigdir = ${libdir}/pkgconfig
24+
pkgconfig_DATA = libpciemu.pc
25+
libpciemu.pc.src: libpciemu.pc.src.in
26+
libpciemu.pc: libpciemu.pc.src
27+
@SED@ -f version.sed < libpciemu.pc.src > libpciemu.pc || rm -f libpciemu.pc
28+
29+
libpciemu-config.src: libpciemu-config.src.in
30+
libpciemu-config: libpciemu-config.src version.sed
31+
@SED@ -f version.sed < libpciemu-config.src > libpciemu-config || rm -f libpciemu-config
32+
chmod +x $@
33+
34+
VFD = ${srcdir}
35+
VF = ${shell cat ${VFD}/version-files}
36+
VFS = ${VF:%=${VFD}/%}
37+
VCHK = ${shell cat ${VFS} | @MD5SUM@ | @AWK@ '{ print $$1 }' }
38+
VNUM = ${shell @GREP@ ${VCHK} ${VFD}/version-md5sums | @AWK@ '{ print $$2 }' }
39+
VDEF = ${shell echo `cat ${VFD}/version-major`.`cat ${VFD}/version-minor`.`cat ${VFD}/version-micro` }
40+
41+
version.sed: $(VFD)/version-files $(VFD)/version-major \
42+
$(VFD)/version-minor $(VFD)/version-micro \
43+
$(VFD)/version-md5sums ${VFS} Makefile
44+
if [ .${VNUM} = . ]; then \
45+
echo "s/%VERSION%/${VDEF}-E/g" > version.sed; \
46+
else \
47+
echo "s/%VERSION%/${VNUM}/g" > version.sed; \
48+
fi
49+
protos:
50+
make -C src protos

README

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
********** Library PCI Emulation Documentation **************
2+
3+
This library contains helpers to simply create a virtual PCI device.
4+
It's part of device disaggregation and can only be use on the top of XenClient XT
5+
superior to 3.0.0 for the moment.
6+
7+
* Compilation
8+
9+
42sh> ./configure
10+
42sh> make
11+
42sh> make install
12+
13+
* Limitations
14+
15+
For the moment the library is unable to handle:
16+
* 64 bits BARs;
17+
* status register;
18+
* rom;
19+
* capabilities
20+
21+
* Demo application
22+
In order to understand how to use libpciemu, a skeleton was created in app/.
23+
/!\ This app compile buts doesn't work. it miss synchronisation with the manager.
24+
25+
42sh> make -C app

TODO

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ROM
2+
64 bits BAR
3+
capabilities
4+
status register

app/Makefile.am

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# Copyright (c) 2013 Citrix Systems, Inc.
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation; either
7+
# version 2.1 of the License, or (at your option) any later version.
8+
#
9+
# This library is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
# Lesser General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Lesser General Public
15+
# License along with this library; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
#
18+
19+
INCLUDES = -I${top_srcdir}/src ${LIBEVENT_INC}
20+
21+
noinst_PROGRAMS = fake-pci
22+
23+
fake_pci_SOURCES = fake-pci.c
24+
fake_pci_CFLAGS = ${AM_CLAGS} -Wall -Werror ${INCLUDES}
25+
fake_pci_LDFLAGS = -L${top_builddir}/src -lpciemu ${LIBEVENT_LIB} ${LIBXC_LIB}

app/fake-pci.c

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*
2+
* Copyright (c) 2013 Citrix Systems, Inc.
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#include <event.h>
20+
#include <inttypes.h>
21+
#include <libpciemu.h>
22+
#include <signal.h>
23+
#include <stdlib.h>
24+
#include <stdio.h>
25+
#include <string.h>
26+
27+
#define PCI_VENDOR_ID_XEN 0x5853
28+
#define PCI_DEVICE_ID_FAKEPCI 0xc148
29+
30+
static void pci_bar_update (uint8_t region, uint64_t addr, void *priv)
31+
{
32+
(void) priv;
33+
34+
if (addr == PCI_BAR_UNMAPPED)
35+
printf ("Bar %u unmapped\n", region);
36+
else
37+
printf ("Bar %u mapped to 0x%"PRIx64"\n", region, addr);
38+
}
39+
40+
static uint64_t pci_mmio_read (uint64_t addr, uint32_t size, void *priv)
41+
{
42+
(void) priv;
43+
44+
fprintf (stderr, "pci_mmio_read addr=0x%"PRIx64" size=%u\n", addr, size);
45+
46+
return 0x42;
47+
}
48+
49+
static void pci_mmio_write (uint64_t addr, uint64_t data, uint32_t size,
50+
void *priv)
51+
{
52+
(void) priv;
53+
54+
fprintf (stderr, "pci_mmio_write addr=0x%"PRIx64" data=0x%"PRIx64" size=%u\n",
55+
addr, data, size);
56+
}
57+
58+
static libpciemu_io_ops_t pci_mmio_ops = {
59+
.read = pci_mmio_read,
60+
.write = pci_mmio_write,
61+
};
62+
63+
static libpciemu_pci_t pci_init (int domid, libpciemu_handle_t iohandle)
64+
{
65+
libpciemu_pci_info_t info;
66+
libpciemu_pci_t pci;
67+
68+
memset (&info, 0, sizeof (info));
69+
70+
info.vendor_id = PCI_VENDOR_ID_XEN;
71+
info.device_id = PCI_DEVICE_ID_FAKEPCI;
72+
info.subvendor_id = PCI_VENDOR_ID_XEN;
73+
info.subdevice_id = PCI_DEVICE_ID_FAKEPCI;
74+
/* Use 0:08.0 */
75+
info.bus = 0;
76+
info.device = 8;
77+
info.function = 0;
78+
info.bar_update = pci_bar_update;
79+
80+
pci = libpciemu_pci_device_init (&info, NULL);
81+
82+
if (!pci)
83+
return NULL;
84+
85+
libpciemu_pci_register_bar (pci, 0, 1, PCI_BAR_TYPE_PREFETCH, 1024,
86+
&pci_mmio_ops);
87+
88+
if (libpciemu_pci_device_register (iohandle, pci))
89+
{
90+
fprintf (stderr, "Unable to register pci device\n");
91+
libpciemu_pci_device_release (pci);
92+
return NULL;
93+
}
94+
95+
return pci;
96+
}
97+
98+
static void shutdown (int signal)
99+
{
100+
printf("Kill handlepci\n");
101+
/* FIXME: Need some cleanup here */
102+
exit(0);
103+
}
104+
105+
static void usage (const char *prog)
106+
{
107+
fprintf (stderr, "Usage: %s domid\n", prog);
108+
}
109+
110+
static void pci_io (int fd, short event, void *opaque)
111+
{
112+
libpciemu_handle_t iohandle = opaque;
113+
114+
(void) fd;
115+
(void) event;
116+
117+
libpciemu_handle (iohandle);
118+
}
119+
120+
static void fake_pci_logging (libpciemu_loglvl lvl, const char *fmt, ...)
121+
{
122+
va_list ap;
123+
124+
(void) lvl;
125+
126+
va_start(ap, fmt);
127+
vfprintf(stderr, fmt, ap);
128+
va_end(ap);
129+
}
130+
131+
int main (int argc, char **argv)
132+
{
133+
int domid;
134+
libpciemu_handle_t iohandle;
135+
int ret = 1;
136+
libpciemu_pci_t pci;
137+
struct event ioevent;
138+
139+
if (argc != 2)
140+
{
141+
usage (argv[0]);
142+
return 1;
143+
}
144+
145+
domid = atoi (argv[1]);
146+
if (domid <= 0)
147+
return 0;
148+
149+
event_init ();
150+
signal (SIGKILL, shutdown);
151+
signal (SIGINT, shutdown);
152+
153+
libpciemu_init (fake_pci_logging);
154+
155+
if (!(iohandle = libpciemu_handle_create (domid)))
156+
{
157+
fprintf (stderr, "Unable to create iohandle\n");
158+
goto pcicleanup;
159+
}
160+
161+
event_set (&ioevent, libpciemu_handle_get_fd (iohandle),
162+
EV_READ | EV_PERSIST, pci_io, iohandle);
163+
event_add (&ioevent, NULL);
164+
165+
if (!(pci = pci_init (domid, iohandle)))
166+
{
167+
fprintf (stderr, "Unable to create pci\n");
168+
goto iohandlecleanup;
169+
}
170+
171+
event_dispatch ();
172+
173+
iohandlecleanup:
174+
libpciemu_handle_destroy (iohandle);
175+
pcicleanup:
176+
libpciemu_cleanup ();
177+
return ret;
178+
}

0 commit comments

Comments
 (0)