usb: Move driver into library

This raised the opportunity to structure the library more cleanly for each
supported platform.
This commit is contained in:
Sebastian Sumpf 2013-02-20 17:15:29 +01:00 committed by Norman Feske
parent ebc76fc13b
commit 6ef3f0f153
37 changed files with 281 additions and 275 deletions

View File

@ -0,0 +1,6 @@
SRC_C += platform_device.c
SRC_CC += mem.cc
INC_DIR += $(LIB_INC_DIR)/arm
vpath platform_device.c $(LIB_DIR)/arm
vpath mem.cc $(LIB_DIR)/arm

View File

@ -0,0 +1,12 @@
include $(REP_DIR)/lib/mk/usb.inc
include $(REP_DIR)/lib/mk/arm/usb.inc
CC_OPT += -DCONFIG_USB_EHCI_S5P -DCONFIG_USB_EHCI_TT_NEWSCHED
INC_DIR += $(CONTRIB_DIR)/arch/arm/plat-samsung/include
SRC_CC += platform.cc
vpath platform.cc $(LIB_DIR)/arm/platform_arndale

View File

@ -0,0 +1,13 @@
include $(REP_DIR)/lib/mk/usb.inc
include $(REP_DIR)/lib/mk/arm/usb.inc
CC_OPT += -DCONFIG_USB_EHCI_HCD_OMAP -DCONFIG_USB_EHCI_TT_NEWSCHED -DVERBOSE_DEBUG
SRC_C += usbnet.c smsc95xx.c
SRC_CC += platform.cc
vpath platform.cc $(LIB_DIR)/arm/platform_panda
vpath %.c $(CONTRIB_DIR)/drivers/net/usb

101
dde_linux/lib/mk/usb.inc Normal file
View File

@ -0,0 +1,101 @@
LIB_DIR = $(REP_DIR)/src/lib/usb
LIB_INC_DIR = $(LIB_DIR)/include
LIBS += base cxx dde_kit libc-setjmp
SRC_CC += main.cc lx_emul.cc irq.cc timer.cc event.cc storage.cc \
input_component.cc nic.cc
SRC_C += dummies.c scsi.c evdev.c
CONTRIB_DIR := $(REP_DIR)/contrib
DRIVERS_DIR := $(CONTRIB_DIR)/drivers
USB_DIR := $(DRIVERS_DIR)/usb
#
# The order of include-search directories is important, we need to look into
# 'contrib' before falling back to our custom 'lx_emul.h' header.
#
INC_DIR += $(LIB_INC_DIR)
INC_DIR += $(CONTRIB_DIR)/include
CC_OPT += -U__linux__ -D__KERNEL__
CC_OPT += -DCONFIG_USB_DEVICEFS -DCONFIG_HOTPLUG -DDEBUG
CC_WARN = -Wall -Wno-unused-variable -Wno-uninitialized \
-Wno-unused-function \
CC_C_OPT += -Wno-implicit-function-declaration -Wno-unused-but-set-variable \
-Wno-pointer-sign
#
# Suffix of global 'module_init' function
#
MOD_SUFFIX =
CC_OPT += -DMOD_SUFFIX=$(MOD_SUFFIX)
# USB core
SRC_C += $(addprefix usb/core/,$(notdir $(wildcard $(USB_DIR)/core/*.c)))
SRC_C += usb/usb-common.c
# USB host-controller driver
SRC_C += $(addprefix usb/host/, ehci-hcd.c)
# USB hid
SRC_C += $(addprefix hid/usbhid/,hid-core.c hid-quirks.c)
SRC_C += hid/hid-input.c hid/hid-core.c input/evdev.c input/input.c
# USB storage
SRC_C += $(addprefix usb/storage/,scsiglue.c protocol.c transport.c usb.c \
initializers.c option_ms.c sierra_ms.c usual-tables.c)
# SCSI
SRC_C += $(addprefix scsi/,scsi.c constants.c)
#
# Determine the header files included by the contrib code. For each
# of these header files we create a symlink to 'lx_emul.h'.
#
GEN_INCLUDES := $(shell grep -rh "^\#include .*\/" $(CONTRIB_DIR) |\
sed "s/^\#include *[<\"]\(.*\)[>\"].*/\1/" | sort | uniq)
#
# Filter out original Linux headers that exist in the contrib directory
#
NO_GEN_INCLUDES := $(shell cd $(CONTRIB_DIR); find -name "*.h" | sed "s/.\///" | sed "s/.*include\///")
GEN_INCLUDES := $(filter-out $(NO_GEN_INCLUDES),$(GEN_INCLUDES))
#
# Put Linux headers in 'GEN_INC' dir, since some include use "../../" paths use
# three level include hierarchy
#
GEN_INC := $(shell pwd)/include/include/include
$(shell mkdir -p $(GEN_INC))
GEN_INCLUDES := $(addprefix $(GEN_INC)/,$(GEN_INCLUDES))
INC_DIR += $(GEN_INC)
#
# Make sure to create the header symlinks prior building
#
$(SRC_C:.c=.o) $(SRC_CC:.cc=.o): $(GEN_INCLUDES)
#
# Add suffix, since there are two hid-core.c with the same module init function
#
hid/hid-core.o: MOD_SUFFIX="_core"
$(GEN_INCLUDES):
$(VERBOSE)mkdir -p $(dir $@)
$(VERBOSE)ln -s $(LIB_INC_DIR)/lx_emul.h $@
vpath %.c $(DRIVERS_DIR)
vpath %.c $(USB_DIR)/host
vpath %.c $(LIB_DIR)
vpath %.cc $(LIB_DIR)
vpath %.cc $(LIB_DIR)/signal
vpath %.c $(LIB_DIR)/input
vpath %.cc $(LIB_DIR)/input
vpath %.cc $(LIB_DIR)/storage
vpath %.c $(LIB_DIR)/storage
vpath %.cc $(LIB_DIR)/nic

View File

@ -0,0 +1,10 @@
include $(REP_DIR)/lib/mk/usb.inc
CC_OPT += -DCONFIG_PCI
INC_DIR += $(LIB_INC_DIR)/x86
SRC_C += $(addprefix usb/host/,pci-quirks.c uhci-hcd.c)
SRC_CC += pci_driver.cc

View File

@ -1,132 +1,12 @@
/*
* \brief USB driver main program
* \author Norman Feske
* \author Sebastian Sumpf <sebastian.sumpf@genode-labs.com>
* \date 2012-01-29
* \brief Startup USB driver library
* \author Sebastian Sumpf
* \date 2013-02-20
*/
/*
* Copyright (C) 2012-2013 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
/* Genode */
#include <base/rpc_server.h>
#include <base/printf.h>
#include <base/sleep.h>
#include <cap_session/connection.h>
#include <os/config.h>
#include <util/xml_node.h>
#include <nic_session/nic_session.h>
/* Local */
#include "storage/component.h"
#include "routine.h"
#include "signal.h"
extern "C" {
#include <dde_kit/timer.h>
}
using namespace Genode;
extern "C" int subsys_usb_init();
extern "C" void subsys_input_init();
extern "C" void module_evdev_init();
extern "C" void module_hid_init();
extern "C" void module_hid_init_core();
extern "C" void module_usb_stor_init();
extern "C" void start_input_service(void *ep);
Routine *Routine::_current = 0;
Routine *Routine::_dead = 0;
bool Routine::_all = false;
void breakpoint() { PDBG("BREAK"); }
static void init(Services *services)
int main()
{
/* start jiffies */
dde_kit_timer_init(0, 0);
/* USB */
subsys_usb_init();
/* input + HID */
if (services->hid) {
subsys_input_init();
module_evdev_init();
/* HID */
module_hid_init();
}
/* host controller */
platform_hcd_init(services);
/* storage */
if (services->stor)
module_usb_stor_init();
}
int main(int, char **)
{
/*
* Initialize server entry point
*/
enum { STACK_SIZE = 4096 };
static Cap_connection cap;
static Rpc_entrypoint ep_hid(&cap, STACK_SIZE, "usb_hid_ep");
static Signal_receiver recv;
Services services;
try {
config()->xml_node().sub_node("hid");
start_input_service(&ep_hid);
services.hid = true;
} catch (Config::Invalid) {
PDBG("No <config> node found - not starting any USB services");
return 0;
} catch (Xml_node::Nonexistent_sub_node) {
PDBG("No <hid> config node found - not starting the USB HID (Input) service");
}
try {
config()->xml_node().sub_node("storage");
services.stor = true;
} catch (Xml_node::Nonexistent_sub_node) {
PDBG("No <storage> config node found - not starting the USB Storage (Block) service");
}
try {
config()->xml_node().sub_node("nic");
services.nic = true;
} catch (Xml_node::Nonexistent_sub_node) {
PDBG("No <nic> config node found - not starting the USB Nic (Network) service");
}
Timer::init(&recv);
Irq::init(&recv);
Event::init(&recv);
Service_handler::s()->receiver(&recv);
Storage::init(&recv);
Nic::init(&recv);
Routine::add(0, 0, "Main", true);
Routine::current_use_first();
init(&services);
Routine::remove();
/* will never be reached */
sleep_forever();
extern void start_usb_driver();
start_usb_driver();
return 0;
}

View File

@ -1,149 +1,3 @@
TARGET = usb_drv
LIBS = dde_kit libc-setjmp
SRC_CC = main.cc lx_emul.cc irq.cc timer.cc event.cc storage.cc \
input_component.cc nic.cc
SRC_C = dummies.c scsi.c evdev.c
CONTRIB_DIR := $(REP_DIR)/contrib
DRIVERS_DIR := $(CONTRIB_DIR)/drivers
USB_DIR := $(DRIVERS_DIR)/usb
#
# The order of include-search directories is important, we need to look into
# 'contrib' before falling back to our custom 'lx_emul.h' header.
#
INC_DIR += $(PRG_DIR)
INC_DIR += $(CONTRIB_DIR)/include
CC_OPT += -U__linux__ -D__KERNEL__
CC_OPT += -DCONFIG_USB_DEVICEFS -DCONFIG_HOTPLUG -DDEBUG
CC_WARN = -Wall -Wno-unused-variable -Wno-uninitialized \
-Wno-unused-function \
CC_C_OPT += -Wno-implicit-function-declaration -Wno-unused-but-set-variable \
-Wno-pointer-sign
#
# Suffix of global 'module_init' function
#
MOD_SUFFIX =
CC_OPT += -DMOD_SUFFIX=$(MOD_SUFFIX)
# USB core
SRC_C += $(addprefix usb/core/,$(notdir $(wildcard $(USB_DIR)/core/*.c)))
SRC_C += usb/usb-common.c
# USB host-controller driver
SRC_C += $(addprefix usb/host/, ehci-hcd.c)
# USB hid
SRC_C += $(addprefix hid/usbhid/,hid-core.c hid-quirks.c)
SRC_C += hid/hid-input.c hid/hid-core.c input/evdev.c input/input.c
# USB storage
SRC_C += $(addprefix usb/storage/,scsiglue.c protocol.c transport.c usb.c \
initializers.c option_ms.c sierra_ms.c usual-tables.c)
# SCSI
SRC_C += $(addprefix scsi/,scsi.c constants.c)
#
# Determine the header files included by the contrib code. For each
# of these header files we create a symlink to 'lx_emul.h'.
#
GEN_INCLUDES := $(shell grep -rh "^\#include .*\/" $(CONTRIB_DIR) |\
sed "s/^\#include *[<\"]\(.*\)[>\"].*/\1/" | sort | uniq)
#
# Filter out some black-listed headers
#
########################
## Platform specifics ##
########################
SUPPORTED = x86_32 platform_panda
#
# x86_32
#
ifeq ($(filter-out $(SPECS),x86_32),)
INC_DIR += $(PRG_DIR)/x86_32
CC_OPT += -DCONFIG_PCI
SRC_C += $(addprefix usb/host/,pci-quirks.c uhci-hcd.c)
SRC_CC += pci_driver.cc
#
# Panda board
#
else ifeq ($(filter-out $(SPECS),platform_panda),)
CC_OPT += -DCONFIG_USB_EHCI_HCD_OMAP -DCONFIG_USB_EHCI_TT_NEWSCHED -DVERBOSE_DEBUG
INC_DIR += $(PRG_DIR)/arm
SRC_C += platform_device.c usbnet.c smsc95xx.c
SRC_CC += platform.cc mem.cc
vpath %.c $(PRG_DIR)/arm/platform
vpath %.cc $(PRG_DIR)/arm/platform
vpath %.cc $(PRG_DIR)/arm/platform/platform_panda
vpath %.c $(CONTRIB_DIR)/drivers/net/usb
else ifeq ($(filter-out $(SPECS),platform_arndale),)
CC_OPT += -DCONFIG_USB_EHCI_S5P -DCONFIG_USB_EHCI_TT_NEWSCHED
INC_DIR += $(PRG_DIR)/arm
INC_DIR += $(CONTRIB_DIR)/arch/arm/plat-samsung/include
SRC_C += platform_device.c
SRC_CC += platform.cc
vpath %.c $(PRG_DIR)/arm/platform
vpath %.cc $(PRG_DIR)/arm/platform/platform_arndale
#
# Unsupported
#
else
$(error Skip USB because it requires one of the following: $(SUPPORTED))
endif
#
# Filter out original Linux headers that exist in the contrib directory
#
NO_GEN_INCLUDES := $(shell cd $(CONTRIB_DIR)/include; find -name "*.h" | sed "s/.\///")
GEN_INCLUDES := $(filter-out $(NO_GEN_INCLUDES),$(GEN_INCLUDES))
#
# Put Linux headers in 'GEN_INC' dir, since some include use "../../" paths use
# three level include hierarchy
#
GEN_INC := $(shell pwd)/include/include/include
$(shell mkdir -p $(GEN_INC))
GEN_INCLUDES := $(addprefix $(GEN_INC)/,$(GEN_INCLUDES))
INC_DIR += $(GEN_INC)
#
# Make sure to create the header symlinks prior building
#
$(SRC_C:.c=.o) $(SRC_CC:.cc=.o): $(GEN_INCLUDES)
#
# Add suffix, since there are two hid-core.c with the same module init function
#
hid/hid-core.o: MOD_SUFFIX="_core"
$(GEN_INCLUDES):
$(VERBOSE)mkdir -p $(dir $@)
$(VERBOSE)ln -s $(REP_DIR)/src/drivers/usb/lx_emul.h $@
vpath %.c $(DRIVERS_DIR)
vpath %.c $(USB_DIR)/host
vpath %.cc $(PRG_DIR)/signal
vpath %.c $(PRG_DIR)/input
vpath %.cc $(PRG_DIR)/input
vpath %.cc $(PRG_DIR)/storage
vpath %.c $(PRG_DIR)/storage
vpath %.cc $(PRG_DIR)/nic
clean cleanall:
$(VERBOSE) rm -r include
SRC_CC = main.cc
LIBS = usb

View File

@ -0,0 +1,130 @@
/*
* \brief USB driver main program
* \author Norman Feske
* \author Sebastian Sumpf <sebastian.sumpf@genode-labs.com>
* \date 2012-01-29
*/
/*
* Copyright (C) 2012-2013 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
/* Genode */
#include <base/rpc_server.h>
#include <base/printf.h>
#include <base/sleep.h>
#include <cap_session/connection.h>
#include <os/config.h>
#include <util/xml_node.h>
#include <nic_session/nic_session.h>
/* Local */
#include "storage/component.h"
#include "routine.h"
#include "signal.h"
extern "C" {
#include <dde_kit/timer.h>
}
using namespace Genode;
extern "C" int subsys_usb_init();
extern "C" void subsys_input_init();
extern "C" void module_evdev_init();
extern "C" void module_hid_init();
extern "C" void module_hid_init_core();
extern "C" void module_usb_stor_init();
extern "C" void start_input_service(void *ep);
Routine *Routine::_current = 0;
Routine *Routine::_dead = 0;
bool Routine::_all = false;
void breakpoint() { PDBG("BREAK"); }
static void init(Services *services)
{
/* start jiffies */
dde_kit_timer_init(0, 0);
/* USB */
subsys_usb_init();
/* input + HID */
if (services->hid) {
subsys_input_init();
module_evdev_init();
/* HID */
module_hid_init();
}
/* host controller */
platform_hcd_init(services);
/* storage */
if (services->stor)
module_usb_stor_init();
}
void start_usb_driver()
{
/*
* Initialize server entry point
*/
enum { STACK_SIZE = 4096 };
static Cap_connection cap;
static Rpc_entrypoint ep_hid(&cap, STACK_SIZE, "usb_hid_ep");
static Signal_receiver recv;
Services services;
try {
config()->xml_node().sub_node("hid");
start_input_service(&ep_hid);
services.hid = true;
} catch (Config::Invalid) {
PDBG("No <config> node found - not starting any USB services");
return;
} catch (Xml_node::Nonexistent_sub_node) {
PDBG("No <hid> config node found - not starting the USB HID (Input) service");
}
try {
config()->xml_node().sub_node("storage");
services.stor = true;
} catch (Xml_node::Nonexistent_sub_node) {
PDBG("No <storage> config node found - not starting the USB Storage (Block) service");
}
try {
config()->xml_node().sub_node("nic");
services.nic = true;
} catch (Xml_node::Nonexistent_sub_node) {
PDBG("No <nic> config node found - not starting the USB Nic (Network) service");
}
Timer::init(&recv);
Irq::init(&recv);
Event::init(&recv);
Service_handler::s()->receiver(&recv);
Storage::init(&recv);
Nic::init(&recv);
Routine::add(0, 0, "Main", true);
Routine::current_use_first();
init(&services);
Routine::remove();
/* will never be reached */
sleep_forever();
}

View File

@ -36,7 +36,7 @@
#include <lx_emul.h>
#include "scsi.h"
#include <storage/scsi.h>
#define DEBUG_SCSI 0