From 1f939a17869aec385ee65bc85317bad526d1de0f Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Tue, 24 Nov 2009 11:07:23 +0530 Subject: [PATCH 01/18] Added all three UARTs as capability --- config/caps.py | 28 +++++++- config/cml/container_ruleset.template | 95 +++++++++++++++++++++++++++ config/configuration.py | 1 - 3 files changed, 122 insertions(+), 2 deletions(-) diff --git a/config/caps.py b/config/caps.py index 75e8cff..ca80b36 100644 --- a/config/caps.py +++ b/config/caps.py @@ -139,6 +139,18 @@ cap_strings = { 'ipc' : \ \t\t\t\t.size = ${size}, \t\t\t}, ''' +, 'uart' : \ +''' +\t\t\t[${idx}] = { +\t\t\t\t/* For device selection. */ +\t\t\t\t.target = ${cid}, +\t\t\t\t.devid = ${devid}, +\t\t\t\t.type = CAP_DEVTYPE_UART | CAP_TYPE_MAP_PHYSMEM | CAP_RTYPE_CONTAINER, +\t\t\t\t.access = CAP_MAP_READ | CAP_MAP_WRITE | CAP_MAP_EXEC | +\t\t\t\t\tCAP_MAP_CACHED | CAP_MAP_UNCACHED | CAP_MAP_UNMAP | CAP_MAP_UTCB, +\t\t\t\t.start = 0, .end = 0, .size = 0, +\t\t\t}, +''' } @@ -187,7 +199,17 @@ def prepare_typed_capability(cont, param, val): # USE makes us assign the initial cap string with blank fields if 'USE' in params: - cont.caps[captype] = cap_strings[captype] + + # Special case for device + if 'DEVICE' in params: + # Extract device name and number + devnum = captype[-1:] + devname = captype[: -1] + + cont.caps[captype] = cap_strings[devname] + + else: + cont.caps[captype] = cap_strings[captype] # Prepare string template from capability type templ = Template(cont.caps[captype]) @@ -196,6 +218,10 @@ def prepare_typed_capability(cont, param, val): if captype[-len('pool'):] == 'pool': cont.caps[captype] = templ.safe_substitute(cid = cont.id) + # If device, amend current container id and devnum as default + if 'DEVICE' in params: + cont.caps[captype] = templ.safe_substitute(cid = cont.id, devid = devnum) + # Fill in the blank size field elif 'SIZE' in params: # Get reference to capability string template diff --git a/config/cml/container_ruleset.template b/config/cml/container_ruleset.template index 4c177da..b10a997 100644 --- a/config/cml/container_ruleset.template +++ b/config/cml/container_ruleset.template @@ -144,6 +144,7 @@ symbols cont%(cn)d_menu 'Container %(cn)d Parameters' cont%(cn)d_physmem_list 'Container %(cn)d Physical Memory Regions (Capabilities)' cont%(cn)d_virtmem_list 'Container %(cn)d Virtual Memory Regions (Capabilities)' +cont%(cn)d_device_list 'Container %(cn)d Devices (Capabilities)' container%(cn)d_type 'Container %(cn)d Type' container%(cn)d_options 'Container %(cn)d Options' @@ -208,6 +209,99 @@ menu cont%(cn)d_physmem_list CONT%(cn)d_PHYS3_START@ CONT%(cn)d_PHYS3_END@ +# +# Device menu and options per container +# +symbols +cont%(cn)d_device_uart1 'Container %(cn)d UART1 Menu' +cont%(cn)d_device_uart2 'Container %(cn)d UART2 Menu' +cont%(cn)d_device_uart3 'Container %(cn)d UART3 Menu' + +CONT%(cn)d_CAP_UART1_DEVICE_USE 'Container %(cn)d UART1 Enable' +CONT%(cn)d_CAP_UART2_DEVICE_USE 'Container %(cn)d UART2 Enable' +CONT%(cn)d_CAP_UART3_DEVICE_USE 'Container %(cn)d UART3 Enable' + +default CONT%(cn)d_CAP_UART1_DEVICE_USE from n +default CONT%(cn)d_CAP_UART2_DEVICE_USE from n +default CONT%(cn)d_CAP_UART3_DEVICE_USE from n + +# Note: We are suppressing the menu not symbol here, as in future +# we will add new parameters to menu, so suprpressing each symbol +# will be cumbersome +when CONT0_CAP_UART1_DEVICE_USE == y suppress + cont1_device_uart1 + cont2_device_uart1 + cont3_device_uart1 + +when CONT1_CAP_UART1_DEVICE_USE == y suppress + cont0_device_uart1 + cont2_device_uart1 + cont3_device_uart1 + +when CONT2_CAP_UART1_DEVICE_USE == y suppress + cont0_device_uart1 + cont1_device_uart1 + cont3_device_uart1 + +when CONT3_CAP_UART1_DEVICE_USE == y suppress + cont0_device_uart1 + cont1_device_uart1 + cont2_device_uart1 + +when CONT0_CAP_UART2_DEVICE_USE == y suppress + cont1_device_uart2 + cont2_device_uart2 + cont3_device_uart2 + +when CONT1_CAP_UART2_DEVICE_USE == y suppress + cont0_device_uart2 + cont2_device_uart2 + cont3_device_uart2 + +when CONT2_CAP_UART2_DEVICE_USE == y suppress + cont0_device_uart2 + cont1_device_uart2 + cont2_device_uart2 + +when CONT3_CAP_UART2_DEVICE_USE == y suppress + cont0_device_uart2 + cont1_device_uart2 + cont2_device_uart2 + +when CONT0_CAP_UART3_DEVICE_USE == y suppress + cont1_device_uart3 + cont2_device_uart3 + cont3_device_uart3 + +when CONT1_CAP_UART3_DEVICE_USE == y suppress + cont0_device_uart3 + cont2_device_uart3 + cont3_device_uart3 + +when CONT2_CAP_UART3_DEVICE_USE == y suppress + cont0_device_uart3 + cont1_device_uart3 + cont3_device_uart3 + +when CONT3_CAP_UART3_DEVICE_USE == y suppress + cont0_device_uart3 + cont1_device_uart3 + cont2_device_uart3 + +menu cont%(cn)d_device_uart1 + CONT%(cn)d_CAP_UART1_DEVICE_USE + +menu cont%(cn)d_device_uart2 + CONT%(cn)d_CAP_UART2_DEVICE_USE + +menu cont%(cn)d_device_uart3 + CONT%(cn)d_CAP_UART3_DEVICE_USE + +menu cont%(cn)d_device_list + cont%(cn)d_device_uart1 + cont%(cn)d_device_uart2 + cont%(cn)d_device_uart3 + # # Settings for Custom Capabilities # @@ -639,6 +733,7 @@ menu container%(cn)d_options cont%(cn)d_physmem_list cont%(cn)d_virtmem_list cont%(cn)d_capability_list + cont%(cn)d_device_list choices container%(cn)d_type CONT%(cn)d_TYPE_BAREMETAL diff --git a/config/configuration.py b/config/configuration.py index 10d6894..735e281 100644 --- a/config/configuration.py +++ b/config/configuration.py @@ -12,7 +12,6 @@ class Container: self.name = None self.type = None self.id = id - self.src_path = None self.baremetal_id = 0 self.pager_lma = 0 self.pager_vma = 0 From 19a113237d175dbafd424d3a17e88b3123e4bf15 Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Tue, 24 Nov 2009 15:02:49 +0530 Subject: [PATCH 02/18] Default values added for 4 containers, with 4 Physical and 5 Virtual memory regions per container. --- config/cml/container_ruleset.template | 44 +++++++++++++-------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/config/cml/container_ruleset.template b/config/cml/container_ruleset.template index b10a997..5bb7216 100644 --- a/config/cml/container_ruleset.template +++ b/config/cml/container_ruleset.template @@ -40,7 +40,7 @@ CONT%(cn)d_PAGER_TASK_START 'Container %(cn)d Task Address Space Region Start' CONT%(cn)d_PAGER_TASK_END 'Container %(cn)d Task Address Space Region End' CONT%(cn)d_PAGER_UTCB_START 'Container %(cn)d UTCB Mappings Region Start' CONT%(cn)d_PAGER_UTCB_END 'Container %(cn)d UTCB Mappings Region End' -CONT%(cn)d_LINUX_ZRELADDR 'Container %(cn)d Linux ZRELADDR parameter' +CONT%(cn)d_LINUX_ZRELADDR 'Container %(cn)d Linux ZRELADDR Parameter' CONT%(cn)d_LINUX_PAGE_OFFSET 'Container %(cn)d Linux PAGE_OFFSET Parameter' CONT%(cn)d_LINUX_PHYS_OFFSET 'Container %(cn)d Linux PHYS_OFFSET Parameter' CONT%(cn)d_LINUX_ROOTFS_ADDRESS 'Container %(cn)d Linux ROOTFS Address' @@ -106,33 +106,33 @@ require CONT%(cn)d_PHYS3_START >= 0x40000 require CONT%(cn)d_LINUX_ZRELADDR > CONT%(cn)d_LINUX_PHYS_OFFSET + 0x8000 # TODO: Do we want to check if PAGER_LMA/VMA lies in allocated memory regions -default CONT%(cn)d_PHYS0_START from 0x40000 -default CONT%(cn)d_PHYS0_END from 0x1000000 -default CONT%(cn)d_PHYS1_START from 0x1000000 -default CONT%(cn)d_PHYS1_END from 0x1100000 -default CONT%(cn)d_PHYS2_START from 0x1100000 -default CONT%(cn)d_PHYS2_END from 0x1200000 -default CONT%(cn)d_PHYS3_START from 0x1200000 -default CONT%(cn)d_PHYS3_END from 0x1300000 +default CONT%(cn)d_PHYS0_START from (%(cn)d == 0 ? 0x100000 : (0x100000 + %(cn)d * 0x1000000)) +default CONT%(cn)d_PHYS0_END from (CONT%(cn)d_PHYS0_START + 0xD00000) +default CONT%(cn)d_PHYS1_START from CONT%(cn)d_PHYS0_END +default CONT%(cn)d_PHYS1_END from (CONT%(cn)d_PHYS1_START + 0x100000) +default CONT%(cn)d_PHYS2_START from CONT%(cn)d_PHYS1_END +default CONT%(cn)d_PHYS2_END from (CONT%(cn)d_PHYS2_START + 0x100000) +default CONT%(cn)d_PHYS3_START from CONT%(cn)d_PHYS2_END +default CONT%(cn)d_PHYS3_END from (CONT%(cn)d_PHYS3_START + 0x100000) -default CONT%(cn)d_VIRT0_START from 0x90000000 -default CONT%(cn)d_VIRT0_END from 0xa0000000 -default CONT%(cn)d_VIRT1_START from 0x40000000 -default CONT%(cn)d_VIRT1_END from 0x50000000 -default CONT%(cn)d_VIRT2_START from 0x30000000 -default CONT%(cn)d_VIRT2_END from 0x40000000 -default CONT%(cn)d_VIRT3_START from 0xf8100000 -default CONT%(cn)d_VIRT3_END from 0xf8200000 -default CONT%(cn)d_VIRT4_START from 0xd0000000 -default CONT%(cn)d_VIRT4_END from 0xe0000000 +default CONT%(cn)d_VIRT0_START from (%(cn)d == 0 ? 0xa0000000 : (0xa0000000 + %(cn)d * 0x10000000)) +default CONT%(cn)d_VIRT0_END from (CONT%(cn)d_VIRT0_START + 0x10000000) +default CONT%(cn)d_VIRT1_START from (%(cn)d == 0 ? 0x80000000 : (0x80000000 + %(cn)d * 0x8000000)) +default CONT%(cn)d_VIRT1_END from (CONT%(cn)d_VIRT1_START + 0x8000000) +default CONT%(cn)d_VIRT2_START from (%(cn)d == 0 ? 0x40000000 : (0x40000000 + %(cn)d * 0x10000000)) +default CONT%(cn)d_VIRT2_END from (CONT%(cn)d_VIRT2_START + 0x10000000) +default CONT%(cn)d_VIRT3_START from (%(cn)d == 0 ? 0xf8100000 : (0xf8100000 + %(cn)d * 0x100000)) +default CONT%(cn)d_VIRT3_END from (CONT%(cn)d_VIRT3_START + 0x100000) +default CONT%(cn)d_VIRT4_START from (%(cn)d == 0 ? 0x10000000 : (0x10000000 + %(cn)d * 0x10000000)) +default CONT%(cn)d_VIRT4_END from (CONT%(cn)d_VIRT4_START + 0x10000000) default CONT%(cn)d_VIRT5_START from 0xe0000000 default CONT%(cn)d_VIRT5_END from 0xf0000000 default CONT%(cn)d_OPT_NAME from (CONT%(cn)d_TYPE_LINUX==y) ? "linux%(cn)d" : ((CONT%(cn)d_TYPE_BAREMETAL==y) ? "baremetal%(cn)d" : "posix%(cn)d") -when CONT%(cn)d_TYPE_LINUX==y suppress cont%(cn)d_default_pager_params cont%(cn)d_posix_pager_params -when CONT%(cn)d_TYPE_BAREMETAL==y suppress cont%(cn)d_linux_pager_params cont%(cn)d_posix_pager_params -when CONT%(cn)d_TYPE_POSIX==y suppress cont%(cn)d_linux_pager_params +when CONT%(cn)d_TYPE_LINUX==y suppress cont%(cn)d_default_pager_params +unless CONT%(cn)d_TYPE_POSIX==y suppress cont%(cn)d_posix_pager_params +unless CONT%(cn)d_TYPE_LINUX==y suppress cont%(cn)d_linux_pager_params unless CONT%(cn)d_TYPE_BAREMETAL==y suppress cont%(cn)d_baremetal_params # derive symbols, for cinfo.c, depending on the type of container selected From fccc2240a5b1aa3b23961c68a7d38eb576dd127c Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Tue, 24 Nov 2009 20:13:07 +0530 Subject: [PATCH 03/18] Modified uart capability for initial version of uattr, need to merge it to bahadir's repo and hence new version of uattr. --- config/caps.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/caps.py b/config/caps.py index ca80b36..041cddb 100644 --- a/config/caps.py +++ b/config/caps.py @@ -142,10 +142,10 @@ cap_strings = { 'ipc' : \ , 'uart' : \ ''' \t\t\t[${idx}] = { -\t\t\t\t/* For device selection. */ +\t\t\t\t/* For device selection */ \t\t\t\t.target = ${cid}, -\t\t\t\t.devid = ${devid}, -\t\t\t\t.type = CAP_DEVTYPE_UART | CAP_TYPE_MAP_PHYSMEM | CAP_RTYPE_CONTAINER, +\t\t\t\t.uattr = CAP_DEVTYPE_UART | ${devnum}, +\t\t\t\t.type = CAP_TYPE_MAP_PHYSMEM | CAP_RTYPE_CONTAINER, \t\t\t\t.access = CAP_MAP_READ | CAP_MAP_WRITE | CAP_MAP_EXEC | \t\t\t\t\tCAP_MAP_CACHED | CAP_MAP_UNCACHED | CAP_MAP_UNMAP | CAP_MAP_UTCB, \t\t\t\t.start = 0, .end = 0, .size = 0, @@ -203,7 +203,7 @@ def prepare_typed_capability(cont, param, val): # Special case for device if 'DEVICE' in params: # Extract device name and number - devnum = captype[-1:] + devid = captype[-1:] devname = captype[: -1] cont.caps[captype] = cap_strings[devname] @@ -220,7 +220,7 @@ def prepare_typed_capability(cont, param, val): # If device, amend current container id and devnum as default if 'DEVICE' in params: - cont.caps[captype] = templ.safe_substitute(cid = cont.id, devid = devnum) + cont.caps[captype] = templ.safe_substitute(cid = cont.id, devnum = devid) # Fill in the blank size field elif 'SIZE' in params: From a10a77a0a02a3fc167fa86d0555883ec0d086d18 Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Tue, 24 Nov 2009 23:00:42 +0530 Subject: [PATCH 04/18] Added UART service as baremetal4 container --- config/cml/container_ruleset.template | 2 + conts/baremetal/baremetal4/SConstruct | 66 ++++ conts/baremetal/baremetal4/container.c | 21 ++ .../baremetal/baremetal4/include/capability.h | 12 + .../baremetal/baremetal4/include/container.h | 13 + conts/baremetal/baremetal4/include/linker.h | 7 + conts/baremetal/baremetal4/main.c | 349 ++++++++++++++++++ conts/baremetal/baremetal4/src/test.c | 0 scripts/baremetal/files/linker.lds.in | 1 + 9 files changed, 471 insertions(+) create mode 100644 conts/baremetal/baremetal4/SConstruct create mode 100644 conts/baremetal/baremetal4/container.c create mode 100644 conts/baremetal/baremetal4/include/capability.h create mode 100644 conts/baremetal/baremetal4/include/container.h create mode 100644 conts/baremetal/baremetal4/include/linker.h create mode 100644 conts/baremetal/baremetal4/main.c create mode 100644 conts/baremetal/baremetal4/src/test.c diff --git a/config/cml/container_ruleset.template b/config/cml/container_ruleset.template index 5bb7216..4ab0db3 100644 --- a/config/cml/container_ruleset.template +++ b/config/cml/container_ruleset.template @@ -157,12 +157,14 @@ CONT%(cn)d_BAREMETAL_PROJ0 'Empty Project' CONT%(cn)d_BAREMETAL_PROJ1 'Hello World' CONT%(cn)d_BAREMETAL_PROJ2 'Thread Library Demo' CONT%(cn)d_BAREMETAL_PROJ3 'Test Project' +CONT%(cn)d_BAREMETAL_PROJ4 'UART Service' choices cont%(cn)d_baremetal_params CONT%(cn)d_BAREMETAL_PROJ0 CONT%(cn)d_BAREMETAL_PROJ1 CONT%(cn)d_BAREMETAL_PROJ2 CONT%(cn)d_BAREMETAL_PROJ3 + CONT%(cn)d_BAREMETAL_PROJ4 default CONT%(cn)d_BAREMETAL_PROJ0 menu cont%(cn)d_default_pager_params diff --git a/conts/baremetal/baremetal4/SConstruct b/conts/baremetal/baremetal4/SConstruct new file mode 100644 index 0000000..1b32b63 --- /dev/null +++ b/conts/baremetal/baremetal4/SConstruct @@ -0,0 +1,66 @@ +# -*- mode: python; coding: utf-8; -*- +# +# Codezero -- Virtualization microkernel for embedded systems. +# +# Copyright © 2009 B Labs Ltd +# +import os, shelve, sys +from os.path import * + +PROJRELROOT = '../..' + +sys.path.append(PROJRELROOT) + +from config.projpaths import * +from config.configuration import * + +config = configuration_retrieve() +platform = config.platform +arch = config.arch +gcc_cpu_flag = config.gcc_cpu_flag + +LIBL4_RELDIR = 'conts/libl4' +KERNEL_INCLUDE = join(PROJROOT, 'include') +LIBL4_DIR = join(PROJROOT, LIBL4_RELDIR) +LIBL4_INCLUDE = join(LIBL4_DIR, 'include') +LIBL4_LIBPATH = join(BUILDDIR, LIBL4_RELDIR) + +# Locally important paths are here +LIBC_RELDIR = 'conts/libc' +LIBC_DIR = join(PROJROOT, LIBC_RELDIR) +LIBC_LIBPATH = join(BUILDDIR, LIBC_RELDIR) +LIBC_INCLUDE = [join(LIBC_DIR, 'include'), \ + join(LIBC_DIR, 'include/arch' + '/' + arch)] + +LIBDEV_RELDIR = 'conts/libdev' +LIBDEV_DIR = join(PROJROOT, LIBDEV_RELDIR) +LIBDEV_LIBPATH = join(join(BUILDDIR, LIBDEV_RELDIR), 'sys-userspace') +LIBDEV_INCLUDE = [join(LIBDEV_DIR, 'uart/include')] +LIBDEV_CCFLAGS = '-DPLATFORM_' + platform.upper() + +# FIXME: Add these to autogenerated SConstruct !!! +LIBMEM_RELDIR = 'conts/libmem' +LIBMEM_DIR = join(PROJROOT, LIBMEM_RELDIR) +LIBMEM_LIBPATH = join(BUILDDIR, LIBMEM_RELDIR) +LIBMEM_INCLUDE = LIBMEM_DIR + +env = Environment(CC = config.user_toolchain + 'gcc', + # We don't use -nostdinc because sometimes we need standard headers, + # such as stdarg.h e.g. for variable args, as in printk(). + CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', \ + '-Werror', ('-mcpu=' + gcc_cpu_flag), LIBDEV_CCFLAGS], + LINKFLAGS = ['-nostdlib', '-T' + "include/linker.lds", "-u_start"], + ASFLAGS = ['-D__ASSEMBLY__'], \ + PROGSUFFIX = '.elf', # The suffix to use for final executable\ + ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path\ + LIBS = ['gcc', 'libl4', 'libmalloc', 'c-userspace', 'libdev-userspace', 'gcc', 'c-userspace'], # libgcc.a - This is required for division routines. + CPPPATH = ["#include", KERNEL_INCLUDE, LIBL4_INCLUDE, LIBDEV_INCLUDE, LIBC_INCLUDE, LIBMEM_INCLUDE], + LIBPATH = [LIBL4_LIBPATH, LIBDEV_LIBPATH, LIBC_LIBPATH, LIBMEM_LIBPATH], + CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h') + +src = Glob('*.[cS]') +src += Glob('src/*.[cS]') + +objs = env.Object(src) +prog = env.Program('main.elf', objs) +Depends(prog, 'include/linker.lds') diff --git a/conts/baremetal/baremetal4/container.c b/conts/baremetal/baremetal4/container.c new file mode 100644 index 0000000..f570c3d --- /dev/null +++ b/conts/baremetal/baremetal4/container.c @@ -0,0 +1,21 @@ +/* + * Container entry point for pager + * + * Copyright (C) 2007-2009 B Labs Ltd. + */ + +#include +#include + + +extern void main(void); + +void __container_init(void) +{ + /* Generic L4 initialisation */ + __l4_init(); + + /* Entry to main */ + main(); +} + diff --git a/conts/baremetal/baremetal4/include/capability.h b/conts/baremetal/baremetal4/include/capability.h new file mode 100644 index 0000000..5cfce89 --- /dev/null +++ b/conts/baremetal/baremetal4/include/capability.h @@ -0,0 +1,12 @@ +#ifndef __UART_SERVICE_CAPABILITY_H__ +#define __UART_SERVICE_CAPABILITY_H__ + +#include +#include +#include + +void cap_print(struct capability *cap); +void cap_list_print(struct cap_list *cap_list); +int cap_read_all(); + +#endif /* header */ diff --git a/conts/baremetal/baremetal4/include/container.h b/conts/baremetal/baremetal4/include/container.h new file mode 100644 index 0000000..e6eece5 --- /dev/null +++ b/conts/baremetal/baremetal4/include/container.h @@ -0,0 +1,13 @@ +/* + * Autogenerated definitions for this container. + */ +#ifndef __CONTAINER_H__ +#define __CONTAINER_H__ + + +#define __CONTAINER_NAME__ "uart_service" +#define __CONTAINER_ID__ 0 +#define __CONTAINER__ "cont0" + + +#endif /* __CONTAINER_H__ */ diff --git a/conts/baremetal/baremetal4/include/linker.h b/conts/baremetal/baremetal4/include/linker.h new file mode 100644 index 0000000..e39da2f --- /dev/null +++ b/conts/baremetal/baremetal4/include/linker.h @@ -0,0 +1,7 @@ +#ifndef __LINKER_H__ +#define __LINKER_H__ + +extern char vma_start[]; +extern char __end[]; + +#endif /* __LINKER_H__ */ diff --git a/conts/baremetal/baremetal4/main.c b/conts/baremetal/baremetal4/main.c new file mode 100644 index 0000000..859d930 --- /dev/null +++ b/conts/baremetal/baremetal4/main.c @@ -0,0 +1,349 @@ +/* + * UART service for userspace + */ +#include +#include +#include +#include +#include + +#include +#include +#include +#include /* FIXME: Its best if this is */ +#include + +#define UARTS_TOTAL 3 + +static struct capability caparray[32]; +static int total_caps = 0; + +struct capability uart_cap[UARTS_TOTAL]; + +void cap_print(struct capability *cap) +{ + printf("Capability id:\t\t\t%d\n", cap->capid); + printf("Capability resource id:\t\t%d\n", cap->resid); + printf("Capability owner id:\t\t%d\n",cap->owner); + + switch (cap_type(cap)) { + case CAP_TYPE_TCTRL: + printf("Capability type:\t\t%s\n", "Thread Control"); + break; + case CAP_TYPE_EXREGS: + printf("Capability type:\t\t%s\n", "Exchange Registers"); + break; + case CAP_TYPE_MAP_PHYSMEM: + printf("Capability type:\t\t%s\n", "Map/Physmem"); + break; + case CAP_TYPE_MAP_VIRTMEM: + printf("Capability type:\t\t%s\n", "Map/Virtmem"); + break; + case CAP_TYPE_IPC: + printf("Capability type:\t\t%s\n", "Ipc"); + break; + case CAP_TYPE_UMUTEX: + printf("Capability type:\t\t%s\n", "Mutex"); + break; + case CAP_TYPE_QUANTITY: + printf("Capability type:\t\t%s\n", "Quantitative"); + break; + default: + printf("Capability type:\t\t%s\n", "Unknown"); + break; + } + + switch (cap_rtype(cap)) { + case CAP_RTYPE_THREAD: + printf("Capability resource type:\t%s\n", "Thread"); + break; + case CAP_RTYPE_SPACE: + printf("Capability resource type:\t%s\n", "Space"); + break; + case CAP_RTYPE_CONTAINER: + printf("Capability resource type:\t%s\n", "Container"); + break; + case CAP_RTYPE_THREADPOOL: + printf("Capability resource type:\t%s\n", "Thread Pool"); + break; + case CAP_RTYPE_SPACEPOOL: + printf("Capability resource type:\t%s\n", "Space Pool"); + break; + case CAP_RTYPE_MUTEXPOOL: + printf("Capability resource type:\t%s\n", "Mutex Pool"); + break; + case CAP_RTYPE_MAPPOOL: + printf("Capability resource type:\t%s\n", "Map Pool (PMDS)"); + break; + case CAP_RTYPE_CPUPOOL: + printf("Capability resource type:\t%s\n", "Cpu Pool"); + break; + case CAP_RTYPE_CAPPOOL: + printf("Capability resource type:\t%s\n", "Capability Pool"); + break; + default: + printf("Capability resource type:\t%s\n", "Unknown"); + break; + } + printf("\n"); +} + +void cap_array_print() +{ + printf("Capabilities\n" + "~~~~~~~~~~~~\n"); + + for (int i = 0; i < total_caps; i++) + cap_print(&caparray[i]); + + printf("\n"); +} + +int cap_read_all() +{ + int ncaps; + int err; + + /* Read number of capabilities */ + if ((err = l4_capability_control(CAP_CONTROL_NCAPS, + 0, 0, 0, &ncaps)) < 0) { + printf("l4_capability_control() reading # of" + " capabilities failed.\n Could not " + "complete CAP_CONTROL_NCAPS request.\n"); + BUG(); + } + total_caps = ncaps; + + /* Read all capabilities */ + if ((err = l4_capability_control(CAP_CONTROL_READ, + 0, 0, 0, caparray)) < 0) { + printf("l4_capability_control() reading of " + "capabilities failed.\n Could not " + "complete CAP_CONTROL_READ_CAPS request.\n"); + BUG(); + } + + cap_array_print(&caparray); + + return 0; +} + +/* + * Scans for up to UARTS_TOTAL uart devices in capabilities. + */ +int uart_probe_devices(void) +{ + int uarts = 0; + + /* Scan for uart devices */ + for (int i = 0; i < total_caps; i++) { + /* Match device type */ + if (cap_devtype(&caparray[i]) == CAP_DEVTYPE_UART) { + /* Copy to correct device index */ + memcpy(&uart_cap[cap_devnum(&caparray[i]) - 1], + &caparray[i], sizeof(uart_cap[0])); + uarts++; + } + } + + if (uarts != UARTS_TOTAL) { + printf("%s: Error, not all uarts could be found. " + "uarts=%d\n", __CONTAINER_NAME__, uarts); + BUG(); + } + return 0; +} + +static struct pl011_uart uart[UARTS_TOTAL]; + +int uart_setup_devices(void) +{ + BUG(); /* Make sure to have set the device capability size as well */ + + for (int i = 0; i < UARTS_TOTAL; i++) { + /* Map uart to a virtual address region */ + if (IS_ERR(uart[i].base = + l4_map((void *)__pfn_to_addr(uart_cap[i].start), + l4_new_virtual(uart_cap[i].size), + uart_cap[i].size, + MAP_USR_IO_FLAGS, self_tid()))) { + printf("%s: FATAL: Failed to map UART device " + "%d to a virtual address\n", + __CONTAINER_NAME__, + cap_devnum(&uart_cap[i])); + BUG(); + } + + /* Initialize uart */ + pl011_initialise(&uart[i]); + } +} + +static struct address_pool device_vaddr_pool; + +/* + * Initialize a virtual address pool + * for mapping physical devices. + */ +void init_vaddr_pool(void) +{ + for (int i = 0; i < total_caps; i++) { + /* Find the virtual memory region for this process */ + if (cap_type(&caparray[i]) == CAP_TYPE_MAP_VIRTMEM && + __pfn_to_addr(caparray[i].start) == + (unsigned long)vma_start) { + + /* + * Do we have any unused virtual space + * where we run, and do we have enough + * pages of it to map all uarts? + */ + if (__pfn(page_align_up(__end)) + + UARTS_TOTAL <= caparray[i].end) { + /* + * Yes. We initialize the device + * virtual memory pool here. + * + * We may allocate virtual memory + * addresses from this pool. + */ + address_pool_init(&device_vaddr_pool, + (unsigned long)__end, + __pfn_to_addr(caparray[i].end), + UARTS_TOTAL); + return; + } else + goto out_err; + } + } + +out_err: + printf("%s: FATAL: No virtual memory " + "region available to map " + "devices.\n", __CONTAINER_NAME__); + BUG(); +} + +void uart_generic_tx(char c, int devno) +{ + +} + +char uart_generic_rx(int devno) +{ + return 0; +} + + +void handle_requests(void) +{ + l4id_t senderid; + u32 tag; + int ret; + + printf("%s: Initiating ipc.\n", __CONTAINER__); + if ((ret = l4_receive(L4_ANYTHREAD)) < 0) { + printf("%s: %s: IPC Error: %d. Quitting...\n", __CONTAINER__, + __FUNCTION__, ret); + BUG(); + } + + /* Syslib conventional ipc data which uses first few mrs. */ + tag = l4_get_tag(); + senderid = l4_get_sender(); + + /* + * TODO: + * + * Maybe add tags here that handle requests for sharing + * of the requested uart device with the client? + * + * In order to be able to do that, we should have a + * shareable/grantable capability to the device. Also + * the request should (currently) come from a task + * inside the current container + */ + switch (tag) { + case L4_IPC_TAG_UART_SENDCHAR: + uart_generic_tx(0, 0); /*FIXME: Fill in */ + break; + case L4_IPC_TAG_UART_RECVCHAR: + uart_generic_rx(0); /* FIXME: Fill in */ + break; + default: + printf("%s: Error received ipc from 0x%x residing " + "in container %x with an unrecognized tag: " + "0x%x\n", __CONTAINER__, senderid, + __cid(senderid), tag); + } + + /* Reply */ + if ((ret = l4_ipc_return(ret)) < 0) { + printf("%s: IPC return error: %d.\n", __FUNCTION__, ret); + BUG(); + } +} + +/* + * UTCB-size aligned utcb. + * + * BIG WARNING NOTE: This declaration is legal if we are + * running in a disjoint virtual address space, where the + * utcb declaration lies in a unique virtual address in + * the system. + */ +#define DECLARE_UTCB(name) \ + struct utcb name ALIGN(sizeof(struct utcb)) + +DECLARE_UTCB(utcb); + +/* Set up own utcb for ipc */ +int l4_utcb_setup(void *utcb_address) +{ + struct task_ids ids; + struct exregs_data exregs; + int err; + + l4_getid(&ids); + + /* Clear utcb */ + memset(utcb_address, 0, sizeof(struct utcb)); + + /* Setup exregs for utcb request */ + memset(&exregs, 0, sizeof(exregs)); + exregs_set_utcb(&exregs, (unsigned long)utcb_address); + + if ((err = l4_exchange_registers(&exregs, ids.tid)) < 0) + return err; + + return 0; +} + +void main(void) +{ + int err; + + /* Read all capabilities */ + cap_read_all(); + + /* Scan for uart devices in capabilities */ + uart_probe_devices(); + + /* Initialize virtual address pool for uarts */ + init_vaddr_pool(); + + /* Map and initialize uart devices */ + uart_setup_devices(); + + /* Setup own utcb */ + if ((err = l4_utcb_setup(&utcb)) < 0) { + printf("FATAL: Could not set up own utcb. " + "err=%d\n", err); + BUG(); + } + + /* Listen for uart requests */ + while (1) + handle_requests(); +} + diff --git a/conts/baremetal/baremetal4/src/test.c b/conts/baremetal/baremetal4/src/test.c new file mode 100644 index 0000000..e69de29 diff --git a/scripts/baremetal/files/linker.lds.in b/scripts/baremetal/files/linker.lds.in index d9740ab..ce91000 100644 --- a/scripts/baremetal/files/linker.lds.in +++ b/scripts/baremetal/files/linker.lds.in @@ -26,4 +26,5 @@ SECTIONS . = ALIGN(8); __stack = .; } + __end = .; } From b53cc73747fe6700609b9edc8d2d7e1dc10d8d54 Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Wed, 25 Nov 2009 12:24:53 +0530 Subject: [PATCH 05/18] Testing Inter container IPC for UART service --- config/caps.py | 2 +- conts/baremetal/baremetal4/main.c | 22 +++++++++------------- conts/libl4/include/l4lib/addr.h | 2 +- conts/libl4/src/addr.c | 4 ++-- include/l4/generic/cap-types.h | 2 +- src/generic/resource.c | 22 +++++++++++++++------- 6 files changed, 29 insertions(+), 25 deletions(-) diff --git a/config/caps.py b/config/caps.py index 041cddb..ffc00c4 100644 --- a/config/caps.py +++ b/config/caps.py @@ -144,7 +144,7 @@ cap_strings = { 'ipc' : \ \t\t\t[${idx}] = { \t\t\t\t/* For device selection */ \t\t\t\t.target = ${cid}, -\t\t\t\t.uattr = CAP_DEVTYPE_UART | ${devnum}, +\t\t\t\t.uattr = CAP_DEVTYPE_UART | (${devnum} << 16), \t\t\t\t.type = CAP_TYPE_MAP_PHYSMEM | CAP_RTYPE_CONTAINER, \t\t\t\t.access = CAP_MAP_READ | CAP_MAP_WRITE | CAP_MAP_EXEC | \t\t\t\t\tCAP_MAP_CACHED | CAP_MAP_UNCACHED | CAP_MAP_UNMAP | CAP_MAP_UTCB, diff --git a/conts/baremetal/baremetal4/main.c b/conts/baremetal/baremetal4/main.c index 859d930..caf241f 100644 --- a/conts/baremetal/baremetal4/main.c +++ b/conts/baremetal/baremetal4/main.c @@ -122,9 +122,9 @@ int cap_read_all() "complete CAP_CONTROL_READ_CAPS request.\n"); BUG(); } - +#if 0 cap_array_print(&caparray); - +#endif return 0; } @@ -149,7 +149,7 @@ int uart_probe_devices(void) if (uarts != UARTS_TOTAL) { printf("%s: Error, not all uarts could be found. " "uarts=%d\n", __CONTAINER_NAME__, uarts); - BUG(); + return -ENODEV; } return 0; } @@ -158,8 +158,6 @@ static struct pl011_uart uart[UARTS_TOTAL]; int uart_setup_devices(void) { - BUG(); /* Make sure to have set the device capability size as well */ - for (int i = 0; i < UARTS_TOTAL; i++) { /* Map uart to a virtual address region */ if (IS_ERR(uart[i].base = @@ -177,6 +175,7 @@ int uart_setup_devices(void) /* Initialize uart */ pl011_initialise(&uart[i]); } + return 0; } static struct address_pool device_vaddr_pool; @@ -207,10 +206,8 @@ void init_vaddr_pool(void) * We may allocate virtual memory * addresses from this pool. */ - address_pool_init(&device_vaddr_pool, - (unsigned long)__end, - __pfn_to_addr(caparray[i].end), - UARTS_TOTAL); + address_pool_init(&device_vaddr_pool, page_align_up(__end), + __pfn_to_addr(caparray[i].end), UARTS_TOTAL); return; } else goto out_err; @@ -226,7 +223,7 @@ out_err: void uart_generic_tx(char c, int devno) { - + pl011_tx_char(uart[devno].base, *c); } char uart_generic_rx(int devno) @@ -234,7 +231,6 @@ char uart_generic_rx(int devno) return 0; } - void handle_requests(void) { l4id_t senderid; @@ -265,10 +261,10 @@ void handle_requests(void) */ switch (tag) { case L4_IPC_TAG_UART_SENDCHAR: - uart_generic_tx(0, 0); /*FIXME: Fill in */ + uart_generic_tx(0, 1); /*FIXME: Fill in */ break; case L4_IPC_TAG_UART_RECVCHAR: - uart_generic_rx(0); /* FIXME: Fill in */ + uart_generic_rx(1); /* FIXME: Fill in */ break; default: printf("%s: Error received ipc from 0x%x residing " diff --git a/conts/libl4/include/l4lib/addr.h b/conts/libl4/include/l4lib/addr.h index da51119..9f5dce6 100644 --- a/conts/libl4/include/l4lib/addr.h +++ b/conts/libl4/include/l4lib/addr.h @@ -20,7 +20,7 @@ int address_pool_init_with_idpool(struct address_pool *pool, unsigned long start, unsigned long end); int address_pool_init(struct address_pool *pool, unsigned long start, unsigned long end, - int size); + unsigned int size); void *address_new(struct address_pool *pool, int nitems, int size); int address_del(struct address_pool *, void *addr, int nitems, int size); diff --git a/conts/libl4/src/addr.c b/conts/libl4/src/addr.c index d55d081..1b1d047 100644 --- a/conts/libl4/src/addr.c +++ b/conts/libl4/src/addr.c @@ -24,9 +24,9 @@ int address_pool_init_with_idpool(struct address_pool *pool, int address_pool_init(struct address_pool *pool, unsigned long start, unsigned long end, - int size) + unsigned int size) { - if ((pool->idpool = id_pool_new_init((end - start) / size)) < 0) + if ((pool->idpool = id_pool_new_init(__pfn(end - start) / size)) < 0) return (int)pool->idpool; pool->start = start; pool->end = end; diff --git a/include/l4/generic/cap-types.h b/include/l4/generic/cap-types.h index 789cba2..e301450 100644 --- a/include/l4/generic/cap-types.h +++ b/include/l4/generic/cap-types.h @@ -58,7 +58,7 @@ (c)->attr |= CAP_DEVTYPE_MASK & devtype;} #define cap_set_devnum(c, devnum) \ {(c)->attr &= ~CAP_DEVNUM_MASK; \ - (c)->attr |= CAP_DEVNUM_MASK & devnum;} + (c)->attr |= CAP_DEVNUM_MASK & (devnum << CAP_DEVNUM_SHIFT);} #define cap_devnum(c) \ (((c)->attr & CAP_DEVNUM_MASK) >> CAP_DEVNUM_SHIFT) #define cap_devtype(c) ((c)->attr & CAP_DEVTYPE_MASK) diff --git a/src/generic/resource.c b/src/generic/resource.c index 62751e3..dd85b65 100644 --- a/src/generic/resource.c +++ b/src/generic/resource.c @@ -334,13 +334,21 @@ int memcap_request_device(struct cap_list *cap_list, struct capability *cap, *n; list_foreach_removable_struct(cap, n, &cap_list->caps, list) { - if (cap->start == devcap->start && - cap->end == devcap->end && - cap_is_devmem(cap)) { - /* Unlink only. This is boot memory */ - list_remove(&cap->list); - return 0; - } + if (cap->uattr[0] == devcap->uattr[0]) { + + /* + * We dont want the user to provide, start end addresses, + * just selecting the type of device to be used is fine + */ + devcap->start = cap->start; + devcap->end = cap->end; + devcap->size = cap->size; + + /* Unlink only. This is boot memory */ + list_remove(&cap->list); + return 0; + } + } printk("%s: FATAL: Device memory requested " "does not match any available device " From 9f57cb7c67da25ba43c958f52d69fd79ec9659d6 Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Wed, 25 Nov 2009 13:50:24 +0530 Subject: [PATCH 06/18] Timer capability added, Baremetal5 added as Timer Sevice, Code not tested yet. --- config/caps.py | 12 ++ config/cml/container_ruleset.template | 84 +++++++++++++- conts/baremetal/baremetal5/SConstruct | 71 ++++++++++++ conts/baremetal/baremetal5/container.c | 21 ++++ .../baremetal/baremetal5/include/capability.h | 12 ++ .../baremetal/baremetal5/include/container.h | 13 +++ conts/baremetal/baremetal5/include/linker.h | 7 ++ conts/baremetal/baremetal5/include/test.h | 0 conts/baremetal/baremetal5/main.c | 105 ++++++++++++++++++ conts/baremetal/baremetal5/src/test.c | 0 .../libdev/timer/sp804/include/sp804_timer.h | 67 +++++++++++ conts/libdev/timer/sp804/src/sp804_timer.c | 104 +++++++++++++++++ 12 files changed, 495 insertions(+), 1 deletion(-) create mode 100644 conts/baremetal/baremetal5/SConstruct create mode 100644 conts/baremetal/baremetal5/container.c create mode 100644 conts/baremetal/baremetal5/include/capability.h create mode 100644 conts/baremetal/baremetal5/include/container.h create mode 100644 conts/baremetal/baremetal5/include/linker.h create mode 100644 conts/baremetal/baremetal5/include/test.h create mode 100644 conts/baremetal/baremetal5/main.c create mode 100644 conts/baremetal/baremetal5/src/test.c create mode 100644 conts/libdev/timer/sp804/include/sp804_timer.h create mode 100644 conts/libdev/timer/sp804/src/sp804_timer.c diff --git a/config/caps.py b/config/caps.py index ffc00c4..7ca98fe 100644 --- a/config/caps.py +++ b/config/caps.py @@ -151,6 +151,18 @@ cap_strings = { 'ipc' : \ \t\t\t\t.start = 0, .end = 0, .size = 0, \t\t\t}, ''' +, 'timer' : \ +''' +\t\t\t[${idx}] = { +\t\t\t\t/* For device selection */ +\t\t\t\t.target = ${cid}, +\t\t\t\t.uattr = CAP_DEVTYPE_TIMER | (${devnum} << 16), +\t\t\t\t.type = CAP_TYPE_MAP_PHYSMEM | CAP_RTYPE_CONTAINER, +\t\t\t\t.access = CAP_MAP_READ | CAP_MAP_WRITE | CAP_MAP_EXEC | +\t\t\t\t\tCAP_MAP_CACHED | CAP_MAP_UNCACHED | CAP_MAP_UNMAP | CAP_MAP_UTCB, +\t\t\t\t.start = 0, .end = 0, .size = 0, +\t\t\t}, +''' } diff --git a/config/cml/container_ruleset.template b/config/cml/container_ruleset.template index 4ab0db3..d37da7e 100644 --- a/config/cml/container_ruleset.template +++ b/config/cml/container_ruleset.template @@ -158,6 +158,7 @@ CONT%(cn)d_BAREMETAL_PROJ1 'Hello World' CONT%(cn)d_BAREMETAL_PROJ2 'Thread Library Demo' CONT%(cn)d_BAREMETAL_PROJ3 'Test Project' CONT%(cn)d_BAREMETAL_PROJ4 'UART Service' +CONT%(cn)d_BAREMETAL_PROJ5 'Timer Service' choices cont%(cn)d_baremetal_params CONT%(cn)d_BAREMETAL_PROJ0 @@ -165,6 +166,7 @@ choices cont%(cn)d_baremetal_params CONT%(cn)d_BAREMETAL_PROJ2 CONT%(cn)d_BAREMETAL_PROJ3 CONT%(cn)d_BAREMETAL_PROJ4 + CONT%(cn)d_BAREMETAL_PROJ5 default CONT%(cn)d_BAREMETAL_PROJ0 menu cont%(cn)d_default_pager_params @@ -218,14 +220,23 @@ symbols cont%(cn)d_device_uart1 'Container %(cn)d UART1 Menu' cont%(cn)d_device_uart2 'Container %(cn)d UART2 Menu' cont%(cn)d_device_uart3 'Container %(cn)d UART3 Menu' +cont%(cn)d_device_timer1 'Container %(cn)d TIMER1 Menu' +cont%(cn)d_device_timer2 'Container %(cn)d TIMER2 Menu' +cont%(cn)d_device_timer3 'Container %(cn)d TIMER3 Menu' CONT%(cn)d_CAP_UART1_DEVICE_USE 'Container %(cn)d UART1 Enable' CONT%(cn)d_CAP_UART2_DEVICE_USE 'Container %(cn)d UART2 Enable' CONT%(cn)d_CAP_UART3_DEVICE_USE 'Container %(cn)d UART3 Enable' +CONT%(cn)d_CAP_TIMER1_DEVICE_USE 'Container %(cn)d TIMER1 Enable' +CONT%(cn)d_CAP_TIMER2_DEVICE_USE 'Container %(cn)d TIMER2 Enable' +CONT%(cn)d_CAP_TIMER3_DEVICE_USE 'Container %(cn)d TIMER3 Enable' default CONT%(cn)d_CAP_UART1_DEVICE_USE from n default CONT%(cn)d_CAP_UART2_DEVICE_USE from n default CONT%(cn)d_CAP_UART3_DEVICE_USE from n +default CONT%(cn)d_CAP_TIMER1_DEVICE_USE from n +default CONT%(cn)d_CAP_TIMER2_DEVICE_USE from n +default CONT%(cn)d_CAP_TIMER3_DEVICE_USE from n # Note: We are suppressing the menu not symbol here, as in future # we will add new parameters to menu, so suprpressing each symbol @@ -290,6 +301,66 @@ when CONT3_CAP_UART3_DEVICE_USE == y suppress cont1_device_uart3 cont2_device_uart3 +when CONT0_CAP_TIMER1_DEVICE_USE == y suppress + cont1_device_timer1 + cont2_device_timer1 + cont3_device_timer1 + +when CONT1_CAP_TIMER1_DEVICE_USE == y suppress + cont0_device_timer1 + cont2_device_timer1 + cont3_device_timer1 + +when CONT2_CAP_TIMER1_DEVICE_USE == y suppress + cont0_device_timer1 + cont1_device_timer1 + cont3_device_timer1 + +when CONT3_CAP_TIMER1_DEVICE_USE == y suppress + cont0_device_timer1 + cont1_device_timer1 + cont2_device_timer1 + +when CONT0_CAP_TIMER2_DEVICE_USE == y suppress + cont1_device_timer2 + cont2_device_timer2 + cont3_device_timer2 + +when CONT1_CAP_TIMER2_DEVICE_USE == y suppress + cont0_device_timer2 + cont2_device_timer2 + cont3_device_timer2 + +when CONT2_CAP_TIMER2_DEVICE_USE == y suppress + cont0_device_timer2 + cont1_device_timer2 + cont3_device_timer2 + +when CONT3_CAP_TIMER2_DEVICE_USE == y suppress + cont0_device_timer2 + cont1_device_timer2 + cont2_device_timer2 + +when CONT0_CAP_TIMER3_DEVICE_USE == y suppress + cont1_device_timer3 + cont2_device_timer3 + cont3_device_timer3 + +when CONT1_CAP_TIMER3_DEVICE_USE == y suppress + cont0_device_timer3 + cont2_device_timer3 + cont3_device_timer3 + +when CONT2_CAP_TIMER3_DEVICE_USE == y suppress + cont0_device_timer3 + cont1_device_timer3 + cont3_device_timer3 + +when CONT3_CAP_TIMER3_DEVICE_USE == y suppress + cont0_device_timer3 + cont1_device_timer3 + cont2_device_timer3 + menu cont%(cn)d_device_uart1 CONT%(cn)d_CAP_UART1_DEVICE_USE @@ -299,11 +370,22 @@ menu cont%(cn)d_device_uart2 menu cont%(cn)d_device_uart3 CONT%(cn)d_CAP_UART3_DEVICE_USE +menu cont%(cn)d_device_timer1 + CONT%(cn)d_CAP_TIMER1_DEVICE_USE + +menu cont%(cn)d_device_timer2 + CONT%(cn)d_CAP_TIMER2_DEVICE_USE + +menu cont%(cn)d_device_timer3 + CONT%(cn)d_CAP_TIMER3_DEVICE_USE + menu cont%(cn)d_device_list cont%(cn)d_device_uart1 cont%(cn)d_device_uart2 cont%(cn)d_device_uart3 - + cont%(cn)d_device_timer1 + cont%(cn)d_device_timer2 + cont%(cn)d_device_timer3 # # Settings for Custom Capabilities # diff --git a/conts/baremetal/baremetal5/SConstruct b/conts/baremetal/baremetal5/SConstruct new file mode 100644 index 0000000..cc082da --- /dev/null +++ b/conts/baremetal/baremetal5/SConstruct @@ -0,0 +1,71 @@ +# -*- mode: python; coding: utf-8; -*- +# +# Codezero -- Virtualization microkernel for embedded systems. +# +# Copyright © 2009 B Labs Ltd +# +import os, shelve, sys +from os.path import * + +PROJRELROOT = '../..' + +sys.path.append(PROJRELROOT) + +from config.projpaths import * +from config.configuration import * +from configure import * + +config = configuration_retrieve() +arch = config.arch +platform = config.platform +gcc_cpu_flag = config.gcc_cpu_flag + +# Wrapper library for system calls +LIBL4_RELDIR = 'conts/libl4' +KERNEL_INCLUDE = join(PROJROOT, 'include') +LIBL4_DIR = join(PROJROOT, LIBL4_RELDIR) +LIBL4_INCLUDE = join(LIBL4_DIR, 'include') +LIBL4_LIBPATH = join(BUILDDIR, LIBL4_RELDIR) + +# Some user-space libraries +LIBC_RELDIR = 'conts/libc' +LIBC_DIR = join(PROJROOT, LIBC_RELDIR) +LIBC_LIBPATH = join(BUILDDIR, LIBC_RELDIR) +LIBC_INCLUDE = [join(LIBC_DIR, 'include'), \ + join(LIBC_DIR, 'include/arch' + '/' + arch)] + +LIBDEV_RELDIR = 'conts/libdev' +LIBDEV_DIR = join(PROJROOT, LIBDEV_RELDIR) +LIBDEV_LIBPATH = join(join(BUILDDIR, LIBDEV_RELDIR), 'sys-userspace') +LIBDEV_INCLUDE = [join(LIBDEV_DIR, 'uart/include'), + join(LIBDEV_DIR, 'timer/sp804/include')] +LIBDEV_CCFLAGS = '-DPLATFORM_' + platform.upper() + +LIBMEM_RELDIR = 'conts/libmem' +LIBMEM_DIR = join(PROJROOT, LIBMEM_RELDIR) +LIBMEM_LIBPATH = join(BUILDDIR, LIBMEM_RELDIR) +LIBMEM_INCLUDE = LIBMEM_DIR + +env = Environment(CC = config.user_toolchain + 'gcc', + # We don't use -nostdinc because sometimes we need standard headers, + # such as stdarg.h e.g. for variable args, as in printk(). + CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', \ + '-Werror', ('-mcpu=' + gcc_cpu_flag), LIBDEV_CCFLAGS], \ + LINKFLAGS = ['-nostdlib', '-T' + "include/linker.lds", "-u_start"],\ + ASFLAGS = ['-D__ASSEMBLY__'], \ + PROGSUFFIX = '.elf', # The suffix to use for final executable + ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path + LIBS = ['gcc', 'libl4', 'c-userspace', 'libdev-userspace', \ + 'libmm', 'libmc', 'libmalloc', 'gcc', 'c-userspace'], + # libgcc.a - This is required for division routines. + CPPPATH = ["#include", KERNEL_INCLUDE, LIBL4_INCLUDE, LIBDEV_INCLUDE, \ + LIBC_INCLUDE, LIBMEM_INCLUDE], + LIBPATH = [LIBL4_LIBPATH, LIBDEV_LIBPATH, LIBC_LIBPATH, LIBMEM_LIBPATH], + CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h') + +src = Glob('*.[cS]') +src += Glob('src/*.[cS]') + +objs = env.Object(src) +prog = env.Program('main.elf', objs) +Depends(prog, 'include/linker.lds') diff --git a/conts/baremetal/baremetal5/container.c b/conts/baremetal/baremetal5/container.c new file mode 100644 index 0000000..7bcbf9e --- /dev/null +++ b/conts/baremetal/baremetal5/container.c @@ -0,0 +1,21 @@ +/* + * Container entry point for pager + * + * Copyright (C) 2007-2009 B Labs Ltd. + */ + +#include +#include + + +void main(void); + +void __container_init(void) +{ + /* Generic L4 initialisation */ + __l4_init(); + + /* Entry to main */ + main(); +} + diff --git a/conts/baremetal/baremetal5/include/capability.h b/conts/baremetal/baremetal5/include/capability.h new file mode 100644 index 0000000..5cfce89 --- /dev/null +++ b/conts/baremetal/baremetal5/include/capability.h @@ -0,0 +1,12 @@ +#ifndef __UART_SERVICE_CAPABILITY_H__ +#define __UART_SERVICE_CAPABILITY_H__ + +#include +#include +#include + +void cap_print(struct capability *cap); +void cap_list_print(struct cap_list *cap_list); +int cap_read_all(); + +#endif /* header */ diff --git a/conts/baremetal/baremetal5/include/container.h b/conts/baremetal/baremetal5/include/container.h new file mode 100644 index 0000000..8241815 --- /dev/null +++ b/conts/baremetal/baremetal5/include/container.h @@ -0,0 +1,13 @@ +/* + * Autogenerated definitions for this container. + */ +#ifndef __CONTAINER_H__ +#define __CONTAINER_H__ + + +#define __CONTAINER_NAME__ "timer_service" +#define __CONTAINER_ID__ 0 +#define __CONTAINER__ "cont0" + + +#endif /* __CONTAINER_H__ */ diff --git a/conts/baremetal/baremetal5/include/linker.h b/conts/baremetal/baremetal5/include/linker.h new file mode 100644 index 0000000..e39da2f --- /dev/null +++ b/conts/baremetal/baremetal5/include/linker.h @@ -0,0 +1,7 @@ +#ifndef __LINKER_H__ +#define __LINKER_H__ + +extern char vma_start[]; +extern char __end[]; + +#endif /* __LINKER_H__ */ diff --git a/conts/baremetal/baremetal5/include/test.h b/conts/baremetal/baremetal5/include/test.h new file mode 100644 index 0000000..e69de29 diff --git a/conts/baremetal/baremetal5/main.c b/conts/baremetal/baremetal5/main.c new file mode 100644 index 0000000..e4ebacf --- /dev/null +++ b/conts/baremetal/baremetal5/main.c @@ -0,0 +1,105 @@ +/* + * Main function for this container + */ +#include +#include +#include +#include +#include +#include "sp804_timer.h" + +/* + * Address where we want to map timer + * Be sure that we using a valid address, depending upon + * how we make use of this driver. + */ +#define TIMER_VIRT_BASE 0x91000000 + +/* Frequency of timer in MHz */ +#define TIMER_FREQUENCY 1 + +#define __TASKNAME__ "Driver Mapper" + +void handle_request(void) +{ +# if 0 + /* Generic ipc data */ + u32 mr[MR_UNUSED_TOTAL]; + l4id_t senderid; + u32 tag; + int ret; + + if ((ret = l4_receive(L4_ANYTHREAD)) < 0) { + printf("%s: %s: IPC Error: %d. Quitting...\n", __TASKNAME__, + __FUNCTION__, ret); + BUG(); + } + + /* Syslib conventional ipc data which uses first few mrs. */ + tag = l4_get_tag(); + senderid = l4_get_sender(); + + + if (!(sender = find_task(senderid))) { + l4_ipc_return(-ESRCH); + return; + } + + + /* Read mrs not used by syslib */ + for (int i = 0; i < MR_UNUSED_TOTAL; i++) + mr[i] = read_mr(MR_UNUSED_START + i); + + switch(tag) { + case L4_IPC_TAG_GET_TIME: + ret = sp804_read_value(TIMER_VIRT_BASE); + break; + } + + /* Reply */ + if ((ret = l4_ipc_return(ret)) < 0) { + printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, ret); + BUG(); + } +#endif +} + +int main(void) +{ + int ret = 0; + unsigned value = 0; + + /* + * Map Timer 2 to Ram allocated to us + * FIXME: do we need to set the frequency for sp810? + */ + ret = l4_map((void *)TIMER2_PHYS_BASE, (void *)TIMER_VIRT_BASE, 1, \ + MAP_USR_IO_FLAGS, self_tid()); + if (ret) { + printf("Failed to map the requested device\n"); + return ret; + } + + /* Initialise timer */ + sp804_init(TIMER_VIRT_BASE, SP804_TIMER_RUNMODE_FREERUN, \ + SP804_TIMER_WRAPMODE_WRAPPING, SP804_TIMER_WIDTH32BIT, \ + SP804_TIMER_IRQDISABLE); + + sp804_enable(TIMER_VIRT_BASE, 1); + +#if 1 + /* Read Timer value */ + while(1) { + value = sp804_read_value(TIMER_VIRT_BASE); + printf("Read timer with value = %x\n", value); + } +#else + printf("Driver Mapper: Waiting for ipc\n"); + while (1) { + handle_request(); + } +#endif + + return ret; +} + diff --git a/conts/baremetal/baremetal5/src/test.c b/conts/baremetal/baremetal5/src/test.c new file mode 100644 index 0000000..e69de29 diff --git a/conts/libdev/timer/sp804/include/sp804_timer.h b/conts/libdev/timer/sp804/include/sp804_timer.h new file mode 100644 index 0000000..70a5b1a --- /dev/null +++ b/conts/libdev/timer/sp804/include/sp804_timer.h @@ -0,0 +1,67 @@ +/* + * SP804 Primecell Timer offsets + * + * Copyright (C) 2007 Bahadir Balban + * + */ +#ifndef __SP804_TIMER_H__ +#define __SP804_TIMER_H__ + +#define SP804_TIMER2_OFFSET 0x20 + +/* Base address of Timers for differen platforms */ +#if defined(PLATFORM_PB926) +#define TIMER0_PHYS_BASE 0x101E2000 +#define TIMER1_PHYS_BASE (TIMER0_PHYS_BASE + SP804_TIMER2_OFFSET) +#define TIMER2_PHYS_BASE 0x101E3000 +#define TIMER3_PHYS_BASE (TIMER2_PHYS_BASE + SP804_TIMER2_OFFSET) +#elif defined(PLATFORM_EB) +#define TIMER0_PHYS_BASE 0x10011000 +#define TIMER1_PHYS_BASE (TIMER0_PHYS_BASE + SP804_TIMER2_OFFSET) +#define TIMER2_PHYS_BASE 0x10012000 +#define TIMER3_PHYS_BASE (TIMER2_PHYS_BASE + SP804_TIMER2_OFFSET) +#elif defined(PLATFORM_PB11MPCORE) || defined(PLATFORM_PBA8) +#define TIMER0_PHYS_BASE 0x10011000 +#define TIMER1_PHYS_BASE (TIMER0_PHYS_BASE + SP804_TIMER2_OFFSET) +#define TIMER2_PHYS_BASE 0x10012000 +#define TIMER3_PHYS_BASE (TIMER2_PHYS_BASE + SP804_TIMER2_OFFSET) +#define TIMER4_PHYS_BASE 0x10018000 +#define TIMER5_PHYS_BASE (TIMER4_PHYS_BASE + SP804_TIMER2_OFFSET) +#define TIMER6_PHYS_BASE 0x10019000 +#define TIMER7_PHYS_BASE (TIMER6_PHYS_BASE + SP804_TIMER2_OFFSET) +#endif + +/* Run mode of timers */ +#define SP804_TIMER_RUNMODE_FREERUN 0 +#define SP804_TIMER_RUNMODE_PERIODIC 1 + +/* Wrap mode of timers */ +#define SP804_TIMER_WRAPMODE_WRAPPING 0 +#define SP804_TIMER_WRAPMODE_ONESHOT 1 + +/* Operational width of timer */ +#define SP804_TIMER_WIDTH16BIT 0 +#define SP804_TIMER_WIDTH32BIT 1 + +/* Enable/disable irq on timer */ +#define SP804_TIMER_IRQDISABLE 0 +#define SP804_TIMER_IRQENABLE 1 + +/* Register offsets */ +#define SP804_TIMERLOAD 0x0 +#define SP804_TIMERVALUE 0x4 +#define SP804_TIMERCONTROL 0x8 +#define SP804_TIMERINTCLR 0xC +#define SP804_TIMERRIS 0x10 +#define SP804_TIMERMIS 0x14 +#define SP804_TIMERBGLOAD 0x18 + +void sp804_init(unsigned int timer_base, int runmode, int wrapmode, \ + int width, int irq_enable); +void sp804_irq_handler(unsigned int timer_base); +void sp804_enable(unsigned int timer_base, int enable); +void sp804_set_irq(unsigned int timer_base, int enable); + +unsigned int sp804_read_value(unsigned int timer_base); + +#endif /* __SP804_TIMER_H__ */ diff --git a/conts/libdev/timer/sp804/src/sp804_timer.c b/conts/libdev/timer/sp804/src/sp804_timer.c new file mode 100644 index 0000000..cbb8c11 --- /dev/null +++ b/conts/libdev/timer/sp804/src/sp804_timer.c @@ -0,0 +1,104 @@ +/* + * SP804 Primecell Timer driver + * + * Copyright (C) 2007 Bahadir Balban + */ +#include + +#define read(a) *((volatile unsigned int *)(a)) +#define write(v, a) (*((volatile unsigned int *)(a)) = v) +#define setbit(bit, a) write(read(a) | bit, a) +#define clrbit(bit, a) write(read(a) & ~bit, a) + +void sp804_irq_handler(unsigned int timer_base) +{ + /* + * Timer enabled as Periodic/Wrapper only needs irq clearing + * as it automatically reloads and wraps + */ + write(1, (timer_base + SP804_TIMERINTCLR)); +} + +static inline void sp804_control(unsigned int timer_base, int bit, int setclr) +{ + unsigned long addr = (timer_base + SP804_TIMERCONTROL); + setclr ? setbit(bit, addr) : clrbit(bit, addr); +} + +/* + * Sets timer's run mode: + * @periodic: periodic mode = 1, free-running = 0. + */ +#define SP804_PEREN (1 << 6) +static inline void sp804_set_runmode(unsigned int timer_base, int periodic) +{ + sp804_control(timer_base, SP804_PEREN, periodic); +} + +/* + * Sets timer's wrapping mode: + * @oneshot: oneshot = 1, wrapping = 0. + */ +#define SP804_ONESHOT (1 << 0) +static inline void sp804_set_wrapmode(unsigned int timer_base, int oneshot) +{ + sp804_control(timer_base, SP804_ONESHOT, oneshot); +} + +/* + * Sets the operational width of timers. + * In 16bit mode, top halfword is ignored. + * @width: 32bit mode = 1; 16bit mode = 0 + */ +#define SP804_32BIT (1 << 1) +static inline void sp804_set_widthmode(unsigned int timer_base, int width) +{ + sp804_control(timer_base, SP804_32BIT, width); +} + +/* + * Enable/disable timer: + * @enable: enable = 1, disable = 0; + */ +#define SP804_ENABLE (1 << 7) +void sp804_enable(unsigned int timer_base, int enable) +{ + sp804_control(timer_base, SP804_ENABLE, enable); +} + +/* + * Enable/disable local irq register: + * @enable: enable = 1, disable = 0 + */ +#define SP804_IRQEN (1 << 5) +void sp804_set_irq(unsigned int timer_base, int enable) +{ + sp804_control(timer_base, SP804_IRQEN, enable); +} + +/* Loads timer with value in val */ +static inline void sp804_load_value(unsigned int timer_base, unsigned int val) +{ + write(val, (timer_base + SP804_TIMERLOAD)); +} + +/* Returns current timer value */ +unsigned int sp804_read_value(unsigned int timer_base) +{ + return read(timer_base + SP804_TIMERVALUE); +} + +/* TODO: Define macro values for duration */ +void sp804_init(unsigned int timer_base, int run_mode, int wrap_mode, \ + int width, int irq_enable) +{ + /* 1 tick per usec */ + const int duration = 250; + + sp804_set_runmode(timer_base, run_mode); /* Periodic */ + sp804_set_wrapmode(timer_base, wrap_mode); /* Wrapping */ + sp804_set_widthmode(timer_base, width); /* 32 bit */ + sp804_set_irq(timer_base, irq_enable); /* Enable */ + sp804_load_value(timer_base, duration); +} + From 26268a30d2a5444c94d50790308200cc755f2e01 Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Wed, 25 Nov 2009 18:33:19 +0530 Subject: [PATCH 07/18] Testing UART service --- conts/baremetal/baremetal4/main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/conts/baremetal/baremetal4/main.c b/conts/baremetal/baremetal4/main.c index caf241f..2feedec 100644 --- a/conts/baremetal/baremetal4/main.c +++ b/conts/baremetal/baremetal4/main.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -139,6 +140,7 @@ int uart_probe_devices(void) for (int i = 0; i < total_caps; i++) { /* Match device type */ if (cap_devtype(&caparray[i]) == CAP_DEVTYPE_UART) { + printf("got uart\n"); /* Copy to correct device index */ memcpy(&uart_cap[cap_devnum(&caparray[i]) - 1], &caparray[i], sizeof(uart_cap[0])); @@ -221,9 +223,15 @@ out_err: BUG(); } + +void *l4_new_virtual(int size) +{ + return address_new(&device_vaddr_pool, 1, size); +} + void uart_generic_tx(char c, int devno) { - pl011_tx_char(uart[devno].base, *c); + pl011_tx_char(uart[devno].base, c); } char uart_generic_rx(int devno) From d18751fbe86b1044c26fa71e4e64ced5b565d9c3 Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Wed, 25 Nov 2009 22:55:36 +0530 Subject: [PATCH 08/18] UART service tested. --- conts/baremetal/baremetal4/main.c | 26 +++++++++++++++----------- conts/libdev/uart/include/pl011_uart.h | 2 +- src/generic/resource.c | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/conts/baremetal/baremetal4/main.c b/conts/baremetal/baremetal4/main.c index 2feedec..b9b6212 100644 --- a/conts/baremetal/baremetal4/main.c +++ b/conts/baremetal/baremetal4/main.c @@ -140,7 +140,6 @@ int uart_probe_devices(void) for (int i = 0; i < total_caps; i++) { /* Match device type */ if (cap_devtype(&caparray[i]) == CAP_DEVTYPE_UART) { - printf("got uart\n"); /* Copy to correct device index */ memcpy(&uart_cap[cap_devnum(&caparray[i]) - 1], &caparray[i], sizeof(uart_cap[0])); @@ -161,12 +160,13 @@ static struct pl011_uart uart[UARTS_TOTAL]; int uart_setup_devices(void) { for (int i = 0; i < UARTS_TOTAL; i++) { + /* Get one page from address pool */ + uart[i].base = (unsigned long)l4_new_virtual(1); + /* Map uart to a virtual address region */ - if (IS_ERR(uart[i].base = - l4_map((void *)__pfn_to_addr(uart_cap[i].start), - l4_new_virtual(uart_cap[i].size), - uart_cap[i].size, - MAP_USR_IO_FLAGS, self_tid()))) { + if (IS_ERR(l4_map((void *)__pfn_to_addr(uart_cap[i].start), + (void *)uart[i].base, uart_cap[i].size, MAP_USR_IO_FLAGS, + self_tid()))) { printf("%s: FATAL: Failed to map UART device " "%d to a virtual address\n", __CONTAINER_NAME__, @@ -223,10 +223,10 @@ out_err: BUG(); } - -void *l4_new_virtual(int size) +void *l4_new_virtual(int npages) { - return address_new(&device_vaddr_pool, 1, size); + + return address_new(&device_vaddr_pool, npages, PAGE_SIZE); } void uart_generic_tx(char c, int devno) @@ -236,7 +236,11 @@ void uart_generic_tx(char c, int devno) char uart_generic_rx(int devno) { - return 0; + char c; + + pl011_rx_char(uart[devno].base, &c); + + return c; } void handle_requests(void) @@ -255,7 +259,7 @@ void handle_requests(void) /* Syslib conventional ipc data which uses first few mrs. */ tag = l4_get_tag(); senderid = l4_get_sender(); - + /* * TODO: * diff --git a/conts/libdev/uart/include/pl011_uart.h b/conts/libdev/uart/include/pl011_uart.h index aaa2ca0..8dc95d5 100644 --- a/conts/libdev/uart/include/pl011_uart.h +++ b/conts/libdev/uart/include/pl011_uart.h @@ -62,7 +62,7 @@ #define PL011_OEIRQ (1 << 10) struct pl011_uart { - unsigned int base; + unsigned long base; unsigned int frame_errors; unsigned int parity_errors; unsigned int break_errors; diff --git a/src/generic/resource.c b/src/generic/resource.c index dd85b65..76faf1d 100644 --- a/src/generic/resource.c +++ b/src/generic/resource.c @@ -358,7 +358,6 @@ int memcap_request_device(struct cap_list *cap_list, __pfn_to_addr(devcap->end), devcap->attr); BUG(); } - /* * TODO: Evaluate if access bits are needed and add new cap ranges * only if their access bits match. @@ -517,6 +516,7 @@ int copy_pager_info(struct pager *pager, struct pager_info *pinfo) cap->start = cap_info->start; cap->end = cap_info->end; cap->size = cap_info->size; + cap->uattr = cap_info->uattr; cap_list_insert(cap, &pager->cap_list); } From b48f817bd8a3be1762fb9a0837c597e30956ca0a Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Thu, 26 Nov 2009 01:36:28 +0530 Subject: [PATCH 09/18] Timer Code tested --- conts/baremetal/baremetal5/main.c | 412 ++++++++++++++---- conts/libdev/SConscript | 8 +- .../libdev/timer/sp804/include/sp804_timer.h | 4 + conts/libl4/include/l4lib/ipcdefs.h | 4 + include/l4/platform/pb926/platform.h | 2 + src/platform/pb926/platform.c | 26 +- 6 files changed, 372 insertions(+), 84 deletions(-) diff --git a/conts/baremetal/baremetal5/main.c b/conts/baremetal/baremetal5/main.c index e4ebacf..023e732 100644 --- a/conts/baremetal/baremetal5/main.c +++ b/conts/baremetal/baremetal5/main.c @@ -1,105 +1,357 @@ /* - * Main function for this container + * Timer service for userspace */ #include #include -#include +#include +#include #include #include -#include "sp804_timer.h" -/* - * Address where we want to map timer - * Be sure that we using a valid address, depending upon - * how we make use of this driver. - */ -#define TIMER_VIRT_BASE 0x91000000 +#include +#include +#include +#include "sp804_timer.h" +#include + /* Frequency of timer in MHz */ #define TIMER_FREQUENCY 1 -#define __TASKNAME__ "Driver Mapper" +#define TIMERS_TOTAL 3 -void handle_request(void) +static struct capability caparray[32]; +static int total_caps = 0; + +struct capability timer_cap[TIMERS_TOTAL]; + +void cap_print(struct capability *cap) +{ + printf("Capability id:\t\t\t%d\n", cap->capid); + printf("Capability resource id:\t\t%d\n", cap->resid); + printf("Capability owner id:\t\t%d\n",cap->owner); + + switch (cap_type(cap)) { + case CAP_TYPE_TCTRL: + printf("Capability type:\t\t%s\n", "Thread Control"); + break; + case CAP_TYPE_EXREGS: + printf("Capability type:\t\t%s\n", "Exchange Registers"); + break; + case CAP_TYPE_MAP_PHYSMEM: + printf("Capability type:\t\t%s\n", "Map/Physmem"); + break; + case CAP_TYPE_MAP_VIRTMEM: + printf("Capability type:\t\t%s\n", "Map/Virtmem"); + break; + case CAP_TYPE_IPC: + printf("Capability type:\t\t%s\n", "Ipc"); + break; + case CAP_TYPE_UMUTEX: + printf("Capability type:\t\t%s\n", "Mutex"); + break; + case CAP_TYPE_QUANTITY: + printf("Capability type:\t\t%s\n", "Quantitative"); + break; + default: + printf("Capability type:\t\t%s\n", "Unknown"); + break; + } + + switch (cap_rtype(cap)) { + case CAP_RTYPE_THREAD: + printf("Capability resource type:\t%s\n", "Thread"); + break; + case CAP_RTYPE_SPACE: + printf("Capability resource type:\t%s\n", "Space"); + break; + case CAP_RTYPE_CONTAINER: + printf("Capability resource type:\t%s\n", "Container"); + break; + case CAP_RTYPE_THREADPOOL: + printf("Capability resource type:\t%s\n", "Thread Pool"); + break; + case CAP_RTYPE_SPACEPOOL: + printf("Capability resource type:\t%s\n", "Space Pool"); + break; + case CAP_RTYPE_MUTEXPOOL: + printf("Capability resource type:\t%s\n", "Mutex Pool"); + break; + case CAP_RTYPE_MAPPOOL: + printf("Capability resource type:\t%s\n", "Map Pool (PMDS)"); + break; + case CAP_RTYPE_CPUPOOL: + printf("Capability resource type:\t%s\n", "Cpu Pool"); + break; + case CAP_RTYPE_CAPPOOL: + printf("Capability resource type:\t%s\n", "Capability Pool"); + break; + default: + printf("Capability resource type:\t%s\n", "Unknown"); + break; + } + printf("\n"); +} + +void cap_array_print() +{ + printf("Capabilities\n" + "~~~~~~~~~~~~\n"); + + for (int i = 0; i < total_caps; i++) + cap_print(&caparray[i]); + + printf("\n"); +} + +int cap_read_all() +{ + int ncaps; + int err; + + /* Read number of capabilities */ + if ((err = l4_capability_control(CAP_CONTROL_NCAPS, + 0, 0, 0, &ncaps)) < 0) { + printf("l4_capability_control() reading # of" + " capabilities failed.\n Could not " + "complete CAP_CONTROL_NCAPS request.\n"); + BUG(); + } + total_caps = ncaps; + + /* Read all capabilities */ + if ((err = l4_capability_control(CAP_CONTROL_READ, + 0, 0, 0, caparray)) < 0) { + printf("l4_capability_control() reading of " + "capabilities failed.\n Could not " + "complete CAP_CONTROL_READ_CAPS request.\n"); + BUG(); + } +#if 0 + cap_array_print(&caparray); +#endif + return 0; +} + +/* + * Scans for up to TIMERS_TOTAL timer devices in capabilities. + */ +int timer_probe_devices(void) +{ + int timers = 0; + + /* Scan for timer devices */ + for (int i = 0; i < total_caps; i++) { + /* Match device type */ + if (cap_devtype(&caparray[i]) == CAP_DEVTYPE_TIMER) { + /* Copy to correct device index */ + memcpy(&timer_cap[cap_devnum(&caparray[i]) - 1], + &caparray[i], sizeof(timer_cap[0])); + timers++; + } + } + + if (timers != TIMERS_TOTAL) { + printf("%s: Error, not all timers could be found. " + "timers=%d\n", __CONTAINER_NAME__, timers); + return -ENODEV; + } + return 0; +} + +static struct sp804_timer timer[TIMERS_TOTAL]; + +int timer_setup_devices(void) +{ + for (int i = 0; i < TIMERS_TOTAL; i++) { + /* Get one page from address pool */ + timer[i].base = (unsigned long)l4_new_virtual(1); + printf("timer base %x phy %lx\n", timer[i].base, timer_cap[i].start); + + /* Map timers to a virtual address region */ + if (IS_ERR(l4_map((void *)__pfn_to_addr(timer_cap[i].start), + (void *)timer[i].base, timer_cap[i].size, MAP_USR_IO_FLAGS, + self_tid()))) { + printf("%s: FATAL: Failed to map TIMER device " + "%d to a virtual address\n", + __CONTAINER_NAME__, + cap_devnum(&timer_cap[i])); + BUG(); + } + + /* Initialise timer */ + sp804_init(timer[i].base, SP804_TIMER_RUNMODE_FREERUN, \ + SP804_TIMER_WRAPMODE_WRAPPING, SP804_TIMER_WIDTH32BIT, \ + SP804_TIMER_IRQDISABLE); + + /* Enable Timer */ + sp804_enable(timer[i].base, 1); + } + return 0; +} + +static struct address_pool device_vaddr_pool; + +/* + * Initialize a virtual address pool + * for mapping physical devices. + */ +void init_vaddr_pool(void) +{ + for (int i = 0; i < total_caps; i++) { + /* Find the virtual memory region for this process */ + if (cap_type(&caparray[i]) == CAP_TYPE_MAP_VIRTMEM && + __pfn_to_addr(caparray[i].start) == + (unsigned long)vma_start) { + + /* + * Do we have any unused virtual space + * where we run, and do we have enough + * pages of it to map all timers? + */ + if (__pfn(page_align_up(__end)) + + TIMERS_TOTAL <= caparray[i].end) { + /* + * Yes. We initialize the device + * virtual memory pool here. + * + * We may allocate virtual memory + * addresses from this pool. + */ + address_pool_init(&device_vaddr_pool, page_align_up(__end), + __pfn_to_addr(caparray[i].end), TIMERS_TOTAL); + return; + } else + goto out_err; + } + } + +out_err: + printf("%s: FATAL: No virtual memory " + "region available to map " + "devices.\n", __CONTAINER_NAME__); + BUG(); +} + +void *l4_new_virtual(int npages) +{ + + return address_new(&device_vaddr_pool, npages, PAGE_SIZE); +} + +int timer_gettime(int devno) +{ + return sp804_read_value(timer[devno].base); +} + +void handle_requests(void) { -# if 0 - /* Generic ipc data */ - u32 mr[MR_UNUSED_TOTAL]; l4id_t senderid; u32 tag; int ret; - if ((ret = l4_receive(L4_ANYTHREAD)) < 0) { - printf("%s: %s: IPC Error: %d. Quitting...\n", __TASKNAME__, - __FUNCTION__, ret); - BUG(); - } - - /* Syslib conventional ipc data which uses first few mrs. */ - tag = l4_get_tag(); - senderid = l4_get_sender(); - - - if (!(sender = find_task(senderid))) { - l4_ipc_return(-ESRCH); - return; - } - - - /* Read mrs not used by syslib */ - for (int i = 0; i < MR_UNUSED_TOTAL; i++) - mr[i] = read_mr(MR_UNUSED_START + i); - - switch(tag) { - case L4_IPC_TAG_GET_TIME: - ret = sp804_read_value(TIMER_VIRT_BASE); - break; - } - - /* Reply */ - if ((ret = l4_ipc_return(ret)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, ret); - BUG(); - } -#endif -} - -int main(void) -{ - int ret = 0; - unsigned value = 0; + printf("%s: Initiating ipc.\n", __CONTAINER__); + if ((ret = l4_receive(L4_ANYTHREAD)) < 0) { + printf("%s: %s: IPC Error: %d. Quitting...\n", __CONTAINER__, + __FUNCTION__, ret); + BUG(); + } + /* Syslib conventional ipc data which uses first few mrs. */ + tag = l4_get_tag(); + senderid = l4_get_sender(); + /* - * Map Timer 2 to Ram allocated to us - * FIXME: do we need to set the frequency for sp810? + * TODO: + * + * Maybe add tags here that handle requests for sharing + * of the requested timer device with the client? + * + * In order to be able to do that, we should have a + * shareable/grantable capability to the device. Also + * the request should (currently) come from a task + * inside the current container */ - ret = l4_map((void *)TIMER2_PHYS_BASE, (void *)TIMER_VIRT_BASE, 1, \ - MAP_USR_IO_FLAGS, self_tid()); - if (ret) { - printf("Failed to map the requested device\n"); - return ret; + switch (tag) { + case L4_IPC_TAG_TIMER_GETTIME: + timer_gettime(1); + break; + + default: + printf("%s: Error received ipc from 0x%x residing " + "in container %x with an unrecognized tag: " + "0x%x\n", __CONTAINER__, senderid, + __cid(senderid), tag); } - /* Initialise timer */ - sp804_init(TIMER_VIRT_BASE, SP804_TIMER_RUNMODE_FREERUN, \ - SP804_TIMER_WRAPMODE_WRAPPING, SP804_TIMER_WIDTH32BIT, \ - SP804_TIMER_IRQDISABLE); - - sp804_enable(TIMER_VIRT_BASE, 1); - -#if 1 - /* Read Timer value */ - while(1) { - value = sp804_read_value(TIMER_VIRT_BASE); - printf("Read timer with value = %x\n", value); + /* Reply */ + if ((ret = l4_ipc_return(ret)) < 0) { + printf("%s: IPC return error: %d.\n", __FUNCTION__, ret); + BUG(); } -#else - printf("Driver Mapper: Waiting for ipc\n"); - while (1) { - handle_request(); - } -#endif - - return ret; } +/* + * UTCB-size aligned utcb. + * + * BIG WARNING NOTE: This declaration is legal if we are + * running in a disjoint virtual address space, where the + * utcb declaration lies in a unique virtual address in + * the system. + */ +#define DECLARE_UTCB(name) \ + struct utcb name ALIGN(sizeof(struct utcb)) + +DECLARE_UTCB(utcb); + +/* Set up own utcb for ipc */ +int l4_utcb_setup(void *utcb_address) +{ + struct task_ids ids; + struct exregs_data exregs; + int err; + + l4_getid(&ids); + + /* Clear utcb */ + memset(utcb_address, 0, sizeof(struct utcb)); + + /* Setup exregs for utcb request */ + memset(&exregs, 0, sizeof(exregs)); + exregs_set_utcb(&exregs, (unsigned long)utcb_address); + + if ((err = l4_exchange_registers(&exregs, ids.tid)) < 0) + return err; + + return 0; +} + +void main(void) +{ + int err; + + /* Read all capabilities */ + cap_read_all(); + + /* Scan for timer devices in capabilities */ + timer_probe_devices(); + + /* Initialize virtual address pool for timers */ + init_vaddr_pool(); + + /* Map and initialize timer devices */ + timer_setup_devices(); + + /* Setup own utcb */ + if ((err = l4_utcb_setup(&utcb)) < 0) { + printf("FATAL: Could not set up own utcb. " + "err=%d\n", err); + BUG(); + } + + /* Listen for timer requests */ + while (1) + handle_requests(); +} + + diff --git a/conts/libdev/SConscript b/conts/libdev/SConscript index 2ff6bb3..96e5a46 100644 --- a/conts/libdev/SConscript +++ b/conts/libdev/SConscript @@ -21,12 +21,16 @@ variant = type # Path for uart files LIBDEV_UART_PATH = join(PROJROOT, 'conts/libdev/uart') +# Path for timer files +LIBDEV_TIEMR_PATH = join(PROJROOT, 'conts/libdev/timer/sp804') + e = env.Clone() -e.Append(CPPPATH = [LIBDEV_UART_PATH + '/include'], +e.Append(CPPPATH = [LIBDEV_UART_PATH + '/include', LIBDEV_TIEMR_PATH + '/include'], CCFLAGS = ['-nostdinc', '-DVARIANT_' + variant.upper(), '-DPLATFORM_' + platform.upper()]) -source = Glob('uart/src' + '/*.c') +source = Glob('uart/src' + '/*.c') + \ + Glob('timer/sp804/src' + '/*.c') objects = e.StaticObject(source) library = e.StaticLibrary('libdev-' + variant, objects) diff --git a/conts/libdev/timer/sp804/include/sp804_timer.h b/conts/libdev/timer/sp804/include/sp804_timer.h index 70a5b1a..445074b 100644 --- a/conts/libdev/timer/sp804/include/sp804_timer.h +++ b/conts/libdev/timer/sp804/include/sp804_timer.h @@ -56,6 +56,10 @@ #define SP804_TIMERMIS 0x14 #define SP804_TIMERBGLOAD 0x18 +struct sp804_timer { + unsigned int base; +}; + void sp804_init(unsigned int timer_base, int runmode, int wrapmode, \ int width, int irq_enable); void sp804_irq_handler(unsigned int timer_base); diff --git a/conts/libl4/include/l4lib/ipcdefs.h b/conts/libl4/include/l4lib/ipcdefs.h index 6a9be08..bd94f72 100644 --- a/conts/libl4/include/l4lib/ipcdefs.h +++ b/conts/libl4/include/l4lib/ipcdefs.h @@ -72,4 +72,8 @@ extern l4id_t pagerid; #define L4_IPC_TAG_UART_SENDBUF 53 /* Buffered send */ #define L4_IPC_TAG_UART_RECVBUF 54 /* Buffered recv */ +/* For ipc to timer service (TODO: Shared mapping buffers???) */ +#define L4_IPC_TAG_TIMER_GETTIME 55 + + #endif /* __IPCDEFS_H__ */ diff --git a/include/l4/platform/pb926/platform.h b/include/l4/platform/pb926/platform.h index 9cf2ed1..a6db8ee 100644 --- a/include/l4/platform/pb926/platform.h +++ b/include/l4/platform/pb926/platform.h @@ -18,6 +18,8 @@ /* SP804 timer has TIMER1 at TIMER0 + 0x20 address */ #define PLATFORM_TIMER0_BASE PB926_TIMER01_VBASE +#define PLATFORM_TIMER_REL_OFFSET 0x20 + #define PLATFORM_SP810_BASE PB926_SYSCTRL_VBASE #define PLATFORM_IRQCTRL_BASE PB926_VIC_VBASE #define PLATFORM_SIRQCTRL_BASE PB926_SIC_VBASE diff --git a/src/platform/pb926/platform.c b/src/platform/pb926/platform.c index 48e69dc..d6422d6 100644 --- a/src/platform/pb926/platform.c +++ b/src/platform/pb926/platform.c @@ -26,7 +26,7 @@ */ int platform_setup_device_caps(struct kernel_resources *kres) { - struct capability *uart[4], *timer[2]; + struct capability *uart[4], *timer[4]; /* Setup capabilities for userspace uarts and timers */ uart[1] = alloc_bootmem(sizeof(*uart[1]), 0); @@ -58,7 +58,8 @@ int platform_setup_device_caps(struct kernel_resources *kres) /* Setup timer1 capability as free */ timer[1] = alloc_bootmem(sizeof(*timer[1]), 0); - timer[1]->start = __pfn(PB926_TIMER23_BASE); + timer[1]->start = + __pfn(PB926_TIMER01_BASE + PLATFORM_TIMER_REL_OFFSET); timer[1]->end = timer[1]->start + 1; timer[1]->size = timer[1]->end - timer[1]->start; cap_set_devtype(timer[1], CAP_DEVTYPE_TIMER); @@ -66,6 +67,27 @@ int platform_setup_device_caps(struct kernel_resources *kres) link_init(&timer[1]->list); cap_list_insert(timer[1], &kres->devmem_free); + /* Setup timer2 capability as free */ + timer[2] = alloc_bootmem(sizeof(*timer[2]), 0); + timer[2]->start = __pfn(PB926_TIMER23_BASE); + timer[2]->end = timer[2]->start + 1; + timer[2]->size = timer[2]->end - timer[2]->start; + cap_set_devtype(timer[2], CAP_DEVTYPE_TIMER); + cap_set_devnum(timer[2], 2); + link_init(&timer[2]->list); + cap_list_insert(timer[2], &kres->devmem_free); + + /* Setup timer3 capability as free */ + timer[3] = alloc_bootmem(sizeof(*timer[3]), 0); + timer[3]->start = + __pfn(PB926_TIMER23_BASE + PLATFORM_TIMER_REL_OFFSET); + timer[3]->end = timer[3]->start + 1; + timer[3]->size = timer[3]->end - timer[3]->start; + cap_set_devtype(timer[3], CAP_DEVTYPE_TIMER); + cap_set_devnum(timer[3], 3); + link_init(&timer[3]->list); + cap_list_insert(timer[3], &kres->devmem_free); + return 0; } From 1080c9e1225684db4224682453cae66eaab10f3e Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Thu, 26 Nov 2009 11:15:02 +0530 Subject: [PATCH 10/18] Issues due to capability uattr updation resolved --- config/caps.py | 4 ++-- conts/baremetal/baremetal5/main.c | 1 - src/generic/resource.c | 4 +++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/config/caps.py b/config/caps.py index 7ca98fe..db9d5f6 100644 --- a/config/caps.py +++ b/config/caps.py @@ -144,7 +144,7 @@ cap_strings = { 'ipc' : \ \t\t\t[${idx}] = { \t\t\t\t/* For device selection */ \t\t\t\t.target = ${cid}, -\t\t\t\t.uattr = CAP_DEVTYPE_UART | (${devnum} << 16), +\t\t\t\t.uattr[0] = CAP_DEVTYPE_UART | (${devnum} << 16), \t\t\t\t.type = CAP_TYPE_MAP_PHYSMEM | CAP_RTYPE_CONTAINER, \t\t\t\t.access = CAP_MAP_READ | CAP_MAP_WRITE | CAP_MAP_EXEC | \t\t\t\t\tCAP_MAP_CACHED | CAP_MAP_UNCACHED | CAP_MAP_UNMAP | CAP_MAP_UTCB, @@ -156,7 +156,7 @@ cap_strings = { 'ipc' : \ \t\t\t[${idx}] = { \t\t\t\t/* For device selection */ \t\t\t\t.target = ${cid}, -\t\t\t\t.uattr = CAP_DEVTYPE_TIMER | (${devnum} << 16), +\t\t\t\t.uattr[0] = CAP_DEVTYPE_TIMER | (${devnum} << 16), \t\t\t\t.type = CAP_TYPE_MAP_PHYSMEM | CAP_RTYPE_CONTAINER, \t\t\t\t.access = CAP_MAP_READ | CAP_MAP_WRITE | CAP_MAP_EXEC | \t\t\t\t\tCAP_MAP_CACHED | CAP_MAP_UNCACHED | CAP_MAP_UNMAP | CAP_MAP_UTCB, diff --git a/conts/baremetal/baremetal5/main.c b/conts/baremetal/baremetal5/main.c index 023e732..bb743f2 100644 --- a/conts/baremetal/baremetal5/main.c +++ b/conts/baremetal/baremetal5/main.c @@ -166,7 +166,6 @@ int timer_setup_devices(void) for (int i = 0; i < TIMERS_TOTAL; i++) { /* Get one page from address pool */ timer[i].base = (unsigned long)l4_new_virtual(1); - printf("timer base %x phy %lx\n", timer[i].base, timer_cap[i].start); /* Map timers to a virtual address region */ if (IS_ERR(l4_map((void *)__pfn_to_addr(timer_cap[i].start), diff --git a/src/generic/resource.c b/src/generic/resource.c index 76faf1d..6b3fe4a 100644 --- a/src/generic/resource.c +++ b/src/generic/resource.c @@ -516,7 +516,9 @@ int copy_pager_info(struct pager *pager, struct pager_info *pinfo) cap->start = cap_info->start; cap->end = cap_info->end; cap->size = cap_info->size; - cap->uattr = cap_info->uattr; + cap->uattr[0] = cap_info->uattr[0]; + cap->uattr[1] = cap_info->uattr[1]; + cap_list_insert(cap, &pager->cap_list); } From 88da7c2f361794c2ae21cc787adce07606fbc04d Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Thu, 26 Nov 2009 11:52:10 +0530 Subject: [PATCH 11/18] Timer devices removed, based on PAGE granularity mappings. --- config/cml/container_ruleset.template | 59 ++------------------------- conts/baremetal/baremetal5/main.c | 2 +- src/generic/resource.c | 2 +- src/platform/pb926/platform.c | 24 +---------- 4 files changed, 6 insertions(+), 81 deletions(-) diff --git a/config/cml/container_ruleset.template b/config/cml/container_ruleset.template index d37da7e..0a03f4d 100644 --- a/config/cml/container_ruleset.template +++ b/config/cml/container_ruleset.template @@ -220,23 +220,17 @@ symbols cont%(cn)d_device_uart1 'Container %(cn)d UART1 Menu' cont%(cn)d_device_uart2 'Container %(cn)d UART2 Menu' cont%(cn)d_device_uart3 'Container %(cn)d UART3 Menu' -cont%(cn)d_device_timer1 'Container %(cn)d TIMER1 Menu' -cont%(cn)d_device_timer2 'Container %(cn)d TIMER2 Menu' -cont%(cn)d_device_timer3 'Container %(cn)d TIMER3 Menu' +cont%(cn)d_device_timer1 'Container %(cn)d TIMER23 Menu' CONT%(cn)d_CAP_UART1_DEVICE_USE 'Container %(cn)d UART1 Enable' CONT%(cn)d_CAP_UART2_DEVICE_USE 'Container %(cn)d UART2 Enable' CONT%(cn)d_CAP_UART3_DEVICE_USE 'Container %(cn)d UART3 Enable' -CONT%(cn)d_CAP_TIMER1_DEVICE_USE 'Container %(cn)d TIMER1 Enable' -CONT%(cn)d_CAP_TIMER2_DEVICE_USE 'Container %(cn)d TIMER2 Enable' -CONT%(cn)d_CAP_TIMER3_DEVICE_USE 'Container %(cn)d TIMER3 Enable' +CONT%(cn)d_CAP_TIMER1_DEVICE_USE 'Container %(cn)d TIMER23 Enable' default CONT%(cn)d_CAP_UART1_DEVICE_USE from n default CONT%(cn)d_CAP_UART2_DEVICE_USE from n default CONT%(cn)d_CAP_UART3_DEVICE_USE from n default CONT%(cn)d_CAP_TIMER1_DEVICE_USE from n -default CONT%(cn)d_CAP_TIMER2_DEVICE_USE from n -default CONT%(cn)d_CAP_TIMER3_DEVICE_USE from n # Note: We are suppressing the menu not symbol here, as in future # we will add new parameters to menu, so suprpressing each symbol @@ -321,46 +315,6 @@ when CONT3_CAP_TIMER1_DEVICE_USE == y suppress cont1_device_timer1 cont2_device_timer1 -when CONT0_CAP_TIMER2_DEVICE_USE == y suppress - cont1_device_timer2 - cont2_device_timer2 - cont3_device_timer2 - -when CONT1_CAP_TIMER2_DEVICE_USE == y suppress - cont0_device_timer2 - cont2_device_timer2 - cont3_device_timer2 - -when CONT2_CAP_TIMER2_DEVICE_USE == y suppress - cont0_device_timer2 - cont1_device_timer2 - cont3_device_timer2 - -when CONT3_CAP_TIMER2_DEVICE_USE == y suppress - cont0_device_timer2 - cont1_device_timer2 - cont2_device_timer2 - -when CONT0_CAP_TIMER3_DEVICE_USE == y suppress - cont1_device_timer3 - cont2_device_timer3 - cont3_device_timer3 - -when CONT1_CAP_TIMER3_DEVICE_USE == y suppress - cont0_device_timer3 - cont2_device_timer3 - cont3_device_timer3 - -when CONT2_CAP_TIMER3_DEVICE_USE == y suppress - cont0_device_timer3 - cont1_device_timer3 - cont3_device_timer3 - -when CONT3_CAP_TIMER3_DEVICE_USE == y suppress - cont0_device_timer3 - cont1_device_timer3 - cont2_device_timer3 - menu cont%(cn)d_device_uart1 CONT%(cn)d_CAP_UART1_DEVICE_USE @@ -373,19 +327,12 @@ menu cont%(cn)d_device_uart3 menu cont%(cn)d_device_timer1 CONT%(cn)d_CAP_TIMER1_DEVICE_USE -menu cont%(cn)d_device_timer2 - CONT%(cn)d_CAP_TIMER2_DEVICE_USE - -menu cont%(cn)d_device_timer3 - CONT%(cn)d_CAP_TIMER3_DEVICE_USE - menu cont%(cn)d_device_list cont%(cn)d_device_uart1 cont%(cn)d_device_uart2 cont%(cn)d_device_uart3 cont%(cn)d_device_timer1 - cont%(cn)d_device_timer2 - cont%(cn)d_device_timer3 + # # Settings for Custom Capabilities # diff --git a/conts/baremetal/baremetal5/main.c b/conts/baremetal/baremetal5/main.c index bb743f2..ad4c44f 100644 --- a/conts/baremetal/baremetal5/main.c +++ b/conts/baremetal/baremetal5/main.c @@ -18,7 +18,7 @@ /* Frequency of timer in MHz */ #define TIMER_FREQUENCY 1 -#define TIMERS_TOTAL 3 +#define TIMERS_TOTAL 1 static struct capability caparray[32]; static int total_caps = 0; diff --git a/src/generic/resource.c b/src/generic/resource.c index 6b3fe4a..be6e2ff 100644 --- a/src/generic/resource.c +++ b/src/generic/resource.c @@ -343,7 +343,7 @@ int memcap_request_device(struct cap_list *cap_list, devcap->start = cap->start; devcap->end = cap->end; devcap->size = cap->size; - + /* Unlink only. This is boot memory */ list_remove(&cap->list); return 0; diff --git a/src/platform/pb926/platform.c b/src/platform/pb926/platform.c index d6422d6..b242767 100644 --- a/src/platform/pb926/platform.c +++ b/src/platform/pb926/platform.c @@ -58,8 +58,7 @@ int platform_setup_device_caps(struct kernel_resources *kres) /* Setup timer1 capability as free */ timer[1] = alloc_bootmem(sizeof(*timer[1]), 0); - timer[1]->start = - __pfn(PB926_TIMER01_BASE + PLATFORM_TIMER_REL_OFFSET); + timer[1]->start = __pfn(PB926_TIMER23_BASE); timer[1]->end = timer[1]->start + 1; timer[1]->size = timer[1]->end - timer[1]->start; cap_set_devtype(timer[1], CAP_DEVTYPE_TIMER); @@ -67,27 +66,6 @@ int platform_setup_device_caps(struct kernel_resources *kres) link_init(&timer[1]->list); cap_list_insert(timer[1], &kres->devmem_free); - /* Setup timer2 capability as free */ - timer[2] = alloc_bootmem(sizeof(*timer[2]), 0); - timer[2]->start = __pfn(PB926_TIMER23_BASE); - timer[2]->end = timer[2]->start + 1; - timer[2]->size = timer[2]->end - timer[2]->start; - cap_set_devtype(timer[2], CAP_DEVTYPE_TIMER); - cap_set_devnum(timer[2], 2); - link_init(&timer[2]->list); - cap_list_insert(timer[2], &kres->devmem_free); - - /* Setup timer3 capability as free */ - timer[3] = alloc_bootmem(sizeof(*timer[3]), 0); - timer[3]->start = - __pfn(PB926_TIMER23_BASE + PLATFORM_TIMER_REL_OFFSET); - timer[3]->end = timer[3]->start + 1; - timer[3]->size = timer[3]->end - timer[3]->start; - cap_set_devtype(timer[3], CAP_DEVTYPE_TIMER); - cap_set_devnum(timer[3], 3); - link_init(&timer[3]->list); - cap_list_insert(timer[3], &kres->devmem_free); - return 0; } From 41a64fcd236c1d1a3e9b52b19eab9e2bbc08043c Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Thu, 26 Nov 2009 14:21:17 +0530 Subject: [PATCH 12/18] Independent compilation of libl4 and libmem working fine. --- conts/libl4/SConscript | 2 -- conts/libl4/SConstruct | 8 ++++++-- conts/libl4/src/thread.c | 2 ++ conts/libmem/SConstruct | 25 +++++++++++++------------ 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/conts/libl4/SConscript b/conts/libl4/SConscript index e30695c..f2490ba 100644 --- a/conts/libl4/SConscript +++ b/conts/libl4/SConscript @@ -54,8 +54,6 @@ def create_symlinks(arch): print cmd os.system(cmd) -# TODO: There are errors in this code that -Werror gives problems with. - #create_symlinks(arch) objects = env.StaticObject(Glob('src/*.c') + Glob('src/' + arch + '/*.[cS]')) library = env.StaticLibrary('l4', objects) diff --git a/conts/libl4/SConstruct b/conts/libl4/SConstruct index e378e5a..8356194 100644 --- a/conts/libl4/SConstruct +++ b/conts/libl4/SConstruct @@ -16,13 +16,17 @@ from config.configuration import * config = configuration_retrieve() arch = config.arch +LIBMEM_RELDIR = 'conts/libmem' +LIBMEM_DIR = join(PROJROOT, LIBMEM_RELDIR) + env = Environment(CC = config.user_toolchain + 'gcc', - CCFLAGS = ['-std=gnu99', '-g', '-nostdlib', '-ffreestanding'], + CCFLAGS = ['-std=gnu99', '-g', '-nostdlib', '-ffreestanding', '-Werror'], LINKFLAGS = ['-nostdlib'], ASFLAGS = ['-D__ASSEMBLY__'], ENV = {'PATH' : os.environ['PATH']}, LIBS = 'gcc', - CPPPATH = ['#include', '#include/l4lib/arch', join(PROJROOT,'include')]) + CPPPATH = ['#include', '#include/l4lib/arch', join(PROJROOT,'include'), \ + LIBMEM_DIR]) # TODO: There are errors in this code that -Werror gives problems with. diff --git a/conts/libl4/src/thread.c b/conts/libl4/src/thread.c index 78ee0ba..256589d 100644 --- a/conts/libl4/src/thread.c +++ b/conts/libl4/src/thread.c @@ -22,6 +22,8 @@ extern unsigned long lib_utcb_range_size; /* Static variable definitions */ struct l4_mutex lib_mutex; +extern void global_add_task(struct l4lib_tcb *task); + /* Function definitions */ int l4_thread_create(struct task_ids *ids, unsigned int flags, int (*func)(void *), void *arg) diff --git a/conts/libmem/SConstruct b/conts/libmem/SConstruct index f6b5732..7636a63 100644 --- a/conts/libmem/SConstruct +++ b/conts/libmem/SConstruct @@ -2,23 +2,19 @@ # Copyright (C) 2007 Bahadir Balban # -import os -import glob -import sys +import os, glob, sys from os.path import join from string import split -from configure import * +PROJRELROOT = '../..' +sys.path.append(PROJRELROOT) + +from configure import * config = configuration_retrieve() -project_root = "../.." -headers_root = join(project_root, "include/l4") +headers_root = join(PROJRELROOT, "include/l4") config_h = join(headers_root, "config.h") -#libl4 paths -libl4_headers = join(project_root, "tasks/libl4/include") -libl4_libpath = join(project_root, "tasks/libl4") - mm = "mm" kmalloc = "kmalloc" memcache = "memcache" @@ -29,19 +25,24 @@ kmalloc_dir = kmalloc memcache_dir = memcache tests_dir = tests +LIBL4_RELDIR = 'conts/libl4' +LIBL4_DIR = join(PROJROOT, LIBL4_RELDIR) +LIBL4_INCLUDE = join(LIBL4_DIR, 'include') +LIBL4_LIBPATH = join(BUILDDIR, LIBL4_RELDIR) + test_env = Environment(CC = 'gcc -m32', CCFLAGS = ['-g', '-std=gnu99', '-Wall', '-Werror'], ENV = {'PATH' : os.environ['PATH']}, LIBS = ['gcc', 'mm', 'km', 'mc'], LIBPATH = ['#'], - CPPPATH = ['#include', join(project_root, "include"), "#", libl4_headers]) + CPPPATH = ['#include', join(PROJRELROOT, "include"), "#", LIBL4_INCLUDE]) env = Environment(CC = config.user_toolchain + 'gcc', CCFLAGS = ['-g', '-nostdlib', '-Wall', '-Werror', '-ffreestanding', '-std=gnu99'], LINKFLAGS = ['-nostdlib'], ENV = {'PATH' : os.environ['PATH']}, LIBS = 'gcc', - CPPPATH = [join(project_root, "include"), "#", libl4_headers]) + CPPPATH = [join(PROJRELROOT, "include"), "#", LIBL4_INCLUDE]) if os.path.exists(config_h) is False: print "\nThis build requires a valid kernel configuration header." From 0707376a546b139474c1b7068cb55132df41e2d5 Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Thu, 26 Nov 2009 16:17:55 +0530 Subject: [PATCH 13/18] Added start/end/size attributes for devices in caps.py instead of resource.c --- config/caps.py | 12 ++++++++---- include/l4/platform/pb926/platform.h | 20 ++++++++++++++------ scripts/kernel/generate_kernel_cinfo.py | 1 + src/generic/resource.c | 22 +++++++--------------- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/config/caps.py b/config/caps.py index db9d5f6..b447cc2 100644 --- a/config/caps.py +++ b/config/caps.py @@ -148,7 +148,9 @@ cap_strings = { 'ipc' : \ \t\t\t\t.type = CAP_TYPE_MAP_PHYSMEM | CAP_RTYPE_CONTAINER, \t\t\t\t.access = CAP_MAP_READ | CAP_MAP_WRITE | CAP_MAP_EXEC | \t\t\t\t\tCAP_MAP_CACHED | CAP_MAP_UNCACHED | CAP_MAP_UNMAP | CAP_MAP_UTCB, -\t\t\t\t.start = 0, .end = 0, .size = 0, +\t\t\t\t.start = __pfn(PLATFORM_CONSOLE${devnum}_PHY_BASE), +\t\t\t\t.end = __pfn(PLATFORM_CONSOLE${devnum}_PHY_BASE) + 1, +\t\t\t\t.size = 1, \t\t\t}, ''' , 'timer' : \ @@ -160,12 +162,13 @@ cap_strings = { 'ipc' : \ \t\t\t\t.type = CAP_TYPE_MAP_PHYSMEM | CAP_RTYPE_CONTAINER, \t\t\t\t.access = CAP_MAP_READ | CAP_MAP_WRITE | CAP_MAP_EXEC | \t\t\t\t\tCAP_MAP_CACHED | CAP_MAP_UNCACHED | CAP_MAP_UNMAP | CAP_MAP_UTCB, -\t\t\t\t.start = 0, .end = 0, .size = 0, +\t\t\t\t.start = __pfn(PLATFORM_TIMER${devnum}_PHY_BASE), +\t\t\t\t.end = __pfn(PLATFORM_TIMER${devnum}_PHY_BASE) + 1, +\t\t\t\t.size = 1, \t\t\t}, ''' } - # # These are carefully crafted functions, touch with care. # @@ -232,7 +235,8 @@ def prepare_typed_capability(cont, param, val): # If device, amend current container id and devnum as default if 'DEVICE' in params: - cont.caps[captype] = templ.safe_substitute(cid = cont.id, devnum = devid) + cont.caps[captype] = \ + templ.safe_substitute(cid = cont.id, devnum = devid) # Fill in the blank size field elif 'SIZE' in params: diff --git a/include/l4/platform/pb926/platform.h b/include/l4/platform/pb926/platform.h index a6db8ee..7a9b42c 100644 --- a/include/l4/platform/pb926/platform.h +++ b/include/l4/platform/pb926/platform.h @@ -13,16 +13,14 @@ #include #include -#define PLATFORM_CONSOLE0_BASE PB926_UART0_VBASE +#define PLATFORM_CONSOLE0_BASE PB926_UART0_VBASE /* SP804 timer has TIMER1 at TIMER0 + 0x20 address */ -#define PLATFORM_TIMER0_BASE PB926_TIMER01_VBASE - -#define PLATFORM_TIMER_REL_OFFSET 0x20 +#define PLATFORM_TIMER0_BASE PB926_TIMER01_VBASE #define PLATFORM_SP810_BASE PB926_SYSCTRL_VBASE -#define PLATFORM_IRQCTRL_BASE PB926_VIC_VBASE -#define PLATFORM_SIRQCTRL_BASE PB926_SIC_VBASE +#define PLATFORM_IRQCTRL_BASE PB926_VIC_VBASE +#define PLATFORM_SIRQCTRL_BASE PB926_SIC_VBASE /* Total number of timers present in this platform */ #define TOTAL_TIMERS 4 @@ -32,6 +30,16 @@ #define PLATFORM_TIMER2 2 #define PLATFORM_TIMER3 3 +/* Wrapping Plaform specific Physical Device Addresses */ +#define PLATFORM_CONSOLE0_PHY_BASE PB926_UART0_BASE +#define PLATFORM_CONSOLE1_PHY_BASE PB926_UART1_BASE +#define PLATFORM_CONSOLE2_PHY_BASE PB926_UART2_BASE +#define PLATFORM_CONSOLE3_PHY_BASE PB926_UART3_BASE + +#define PLATFORM_TIMER0_PHY_BASE PB926_TIMER01_BASE +#define PLATFORM_TIMER1_PHY_BASE PB926_TIMER23_BASE + + int platform_setup_device_caps(struct kernel_resources *kres); void platform_irq_enable(int irq); void platform_irq_disable(int irq); diff --git a/scripts/kernel/generate_kernel_cinfo.py b/scripts/kernel/generate_kernel_cinfo.py index fb8429e..9faecfb 100755 --- a/scripts/kernel/generate_kernel_cinfo.py +++ b/scripts/kernel/generate_kernel_cinfo.py @@ -29,6 +29,7 @@ cinfo_file_start = \ #include #include #include +#include INC_PLAT(platform.h) %s diff --git a/src/generic/resource.c b/src/generic/resource.c index be6e2ff..7cff3e8 100644 --- a/src/generic/resource.c +++ b/src/generic/resource.c @@ -334,21 +334,13 @@ int memcap_request_device(struct cap_list *cap_list, struct capability *cap, *n; list_foreach_removable_struct(cap, n, &cap_list->caps, list) { - if (cap->uattr[0] == devcap->uattr[0]) { - - /* - * We dont want the user to provide, start end addresses, - * just selecting the type of device to be used is fine - */ - devcap->start = cap->start; - devcap->end = cap->end; - devcap->size = cap->size; - - /* Unlink only. This is boot memory */ - list_remove(&cap->list); - return 0; - } - + if (cap->start == devcap->start && + cap->end == devcap->end && + cap_is_devmem(cap)) { + /* Unlink only. This is boot memory */ + list_remove(&cap->list); + return 0; + } } printk("%s: FATAL: Device memory requested " "does not match any available device " From efdd81330a671ae97f1ea2b2f153cde8e18bf14e Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Thu, 26 Nov 2009 23:45:25 +0530 Subject: [PATCH 14/18] Tagsgen script rewritten in python --- tools/tagsgen/tagsgen_kernel | 22 -------------- tools/tagsgen/tagsgen_kernel.py | 54 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 22 deletions(-) delete mode 100755 tools/tagsgen/tagsgen_kernel create mode 100755 tools/tagsgen/tagsgen_kernel.py diff --git a/tools/tagsgen/tagsgen_kernel b/tools/tagsgen/tagsgen_kernel deleted file mode 100755 index 377eab6..0000000 --- a/tools/tagsgen/tagsgen_kernel +++ /dev/null @@ -1,22 +0,0 @@ - -rm -f cscope.* -rm -f tags -# Put all sources into a file list. -find ./src -name '*.cc' > tagfilelist -find ./src -name '*.c' >> tagfilelist -find ./src -name '*.h' >> tagfilelist -find ./src -name '*.s' >> tagfilelist -find ./src -name '*.S' >> tagfilelist -find ./src -name '*.lds' >> tagfilelist - -find ./include -name '*.h' >> tagfilelist -find ./include -name '*.s' >> tagfilelist -find ./include -name '*.S' >> tagfilelist -find ./include -name '*.lds' >> tagfilelist - -# Use file list to include in tags. -ctags --languages=C,Asm --recurse -Ltagfilelist - -cscope -q -k -R -i tagfilelist -# Remove file list. -rm -f tagfilelist diff --git a/tools/tagsgen/tagsgen_kernel.py b/tools/tagsgen/tagsgen_kernel.py new file mode 100755 index 0000000..a129cae --- /dev/null +++ b/tools/tagsgen/tagsgen_kernel.py @@ -0,0 +1,54 @@ +#! /usr/bin/env python2.6 +# -*- mode: python; coding: utf-8; -*- + +import os, sys + +PROJRELROOT = '../../' +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT))) + +from config.configuration import * +config = configuration_retrieve() + +platform = config.platform +subarch = config.subarch +arch = config.arch + +def main(): + os.system("rm -f cscope.*") + os.system("rm -f tags") + + # Type of files to be included + file_extn = ['*.cc', '*.c', '*.h', '*.s', '*.S', '*.lds'] + + # Kernel directories + src_dir_path = 'src' + include_dir_path = 'include/l4' + + search_folder = \ + ['api', 'arch/'+ arch, 'arch/'+ arch + '/' + subarch, 'drivers', \ + 'generic', 'glue/' + arch, 'lib', 'platform/' + platform] + + # Put all sources into a file list. + for extn in file_extn: + for dir in search_folder: + # Directory depth to be searched + if dir == 'drivers': + depth = 5 + else: + depth = 1 + + os.system("find " + join(src_dir_path, dir) + \ + " -maxdepth " + str(depth) + " -name '" + extn + "' >> tagfilelist") + os.system("find " + join(include_dir_path, dir) + \ + " -maxdepth " + str(depth) + " -name '" + extn + "' >> tagfilelist") + + # Use file list to include in tags. + os.system("ctags --languages=C,Asm --recurse -Ltagfilelist") + os.system("cscope -q -k -R -i tagfilelist") + + # Remove file list. + os.system("rm -f tagfilelist") + +if __name__ == "__main__": + main() + From bc4a233adbac994708703684db67a9674ce111a3 Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Fri, 27 Nov 2009 00:43:53 +0530 Subject: [PATCH 15/18] Removed AB926 platform --- config/cml/arm.ruleset | 5 +- include/l4/platform/ab926/irq.h | 27 ------ include/l4/platform/ab926/offsets.h | 60 -------------- include/l4/platform/ab926/platform.h | 22 ----- include/l4/platform/ab926/printascii.h | 15 ---- include/l4/platform/ab926/uart.h | 20 ----- scripts/linux/build_linux.py | 1 - src/platform/ab926/SConscript | 10 --- src/platform/ab926/irq.c | 57 ------------- src/platform/ab926/platform.c | 62 -------------- src/platform/ab926/printascii.S | 110 ------------------------- src/platform/ab926/timer.c | 28 ------- src/platform/ab926/uart.c | 28 ------- 13 files changed, 1 insertion(+), 444 deletions(-) delete mode 100644 include/l4/platform/ab926/irq.h delete mode 100644 include/l4/platform/ab926/offsets.h delete mode 100644 include/l4/platform/ab926/platform.h delete mode 100644 include/l4/platform/ab926/printascii.h delete mode 100644 include/l4/platform/ab926/uart.h delete mode 100644 src/platform/ab926/SConscript delete mode 100644 src/platform/ab926/irq.c delete mode 100644 src/platform/ab926/platform.c delete mode 100644 src/platform/ab926/printascii.S delete mode 100644 src/platform/ab926/timer.c delete mode 100644 src/platform/ab926/uart.c diff --git a/config/cml/arm.ruleset b/config/cml/arm.ruleset index 6b00220..8251edb 100644 --- a/config/cml/arm.ruleset +++ b/config/cml/arm.ruleset @@ -20,7 +20,6 @@ SUBARCH_V7 'ARM v7 Architecture, To be added' arm_platform_type 'ARM Platform Type' PLATFORM_EB 'Realview EB Platform, Unsupported yet' -PLATFORM_AB926 'Versatile AB926 Platform, Unsupported yet' PLATFORM_PB926 'Versatile PB926 Platform' PLATFORM_PB11MPCORE 'Realview PB11MPCore Platform' PLATFORM_PBA8 'Realview PB-A8 Platform' @@ -56,7 +55,6 @@ choices arm_subarch_type choices arm_platform_type PLATFORM_EB - PLATFORM_AB926 PLATFORM_PB926 PLATFORM_PB11MPCORE PLATFORM_PBA8 @@ -104,7 +102,6 @@ default CONTAINERS from 1 #Platform rules: unless SUBARCH_V5 suppress PLATFORM_PB926 -unless SUBARCH_V5 suppress PLATFORM_AB926 unless SUBARCH_V6 suppress PLATFORM_PB11MPCORE unless SUBARCH_V7 suppress PLATFORM_PBA8 @@ -124,7 +121,7 @@ unless ARCH_ARM suppress arm_menu unless PLATFORM_EB suppress CPU_ARM1136 derive DRIVER_UART_PL011 from SUBARCH_V5 or SUBARCH_V6 or SUBARCH_V7 derive DRIVER_TIMER_SP804 from SUBARCH_V5 or SUBARCH_V6 or SUBARCH_V7 -derive DRIVER_IRQ_PL190 from PLATFORM_PB926 or PLATFORM_AB926 +derive DRIVER_IRQ_PL190 from PLATFORM_PB926 derive DRIVER_IRQ_GIC from PLATFORM_PB11MPCORE or PLATFORM_PBA8 or PLATFORM_EB diff --git a/include/l4/platform/ab926/irq.h b/include/l4/platform/ab926/irq.h deleted file mode 100644 index ecfad92..0000000 --- a/include/l4/platform/ab926/irq.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef __PLATFORM_IRQ_H__ -#define __PLATFORM_IRQ_H__ - -#define IRQ_CHIPS_MAX 2 -#define IRQS_MAX 64 - -/* IRQ indices. */ -#define IRQ_TIMER01 4 -#define IRQ_TIMER23 5 -#define IRQ_RTC 10 -#define IRQ_UART0 12 -#define IRQ_UART1 13 -#define IRQ_UART2 14 -#define IRQ_SIC 31 - -/* Cascading definitions */ - -#define PIC_IRQS_MAX 31 /* Total irqs on PIC */ -/* The local irq line of the dummy peripheral on this chip */ -#define LOCALIRQ_DUMMY 15 -/* The irq index offset of this chip, is the maximum of previous chip + 1 */ -#define SIRQ_CHIP_OFFSET (PIC_IRQS_MAX + 1) -/* The global irq number of dummy is the local irq line + it's chip offset */ -#define IRQ_DUMMY (LOCALIRQ_DUMMY + SIRQ_CHIP_OFFSET) - - -#endif /* __PLATFORM_IRQ_H__ */ diff --git a/include/l4/platform/ab926/offsets.h b/include/l4/platform/ab926/offsets.h deleted file mode 100644 index 4a49729..0000000 --- a/include/l4/platform/ab926/offsets.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Describes physical memory layout of pb926 platform. - * - * Copyright (C) 2007 Bahadir Balban - */ - -#ifndef __PLATFORM_PB926_OFFSETS_H__ -#define __PLATFORM_PB926_OFFSETS_H__ - -/* Physical memory base */ -#define PHYS_MEM_START 0x00000000 /* inclusive */ -#define PHYS_MEM_END 0x08000000 /* 128 MB, exclusive */ - -/* - * These bases taken from where kernel is `physically' linked at, - * also used to calculate virtual-to-physical translation offset. - * See the linker script for their sources. PHYS_ADDR_BASE can't - * use a linker variable because it's referred from assembler. - */ -#define PHYS_ADDR_BASE 0x100000 - -/* Device memory base */ -#define PB926_DEV_PHYS 0x10000000 - -/* Device offsets in physical memory */ -#define PB926_SYSTEM_REGISTERS 0x10000000 /* System registers */ -#define PB926_SYSCTRL_BASE 0x101E0000 /* System controller */ -#define PB926_WATCHDOG_BASE 0x101E1000 /* Watchdog */ -#define PB926_TIMER01_BASE 0x101E2000 /* Timers 0 and 1 */ -#define PB926_TIMER23_BASE 0x101E3000 /* Timers 2 and 3 */ -#define PB926_RTC_BASE 0x101E8000 /* Real Time Clock */ -#define PB926_VIC_BASE 0x10140000 /* Primary Vectored IC */ -#define PB926_SIC_BASE 0x10003000 /* Secondary IC */ -#define PB926_UART0_BASE 0x101F1000 /* Console port (UART0) */ - -/* - * Uart virtual address until a file-based console access - * is available for userspace - */ -#define USERSPACE_UART_BASE 0x500000 - -/* - * Device offsets in virtual memory. They offset to some virtual - * device base address. Each page on this virtual base is consecutively - * allocated to devices. Nice and smooth. - */ -#define PB926_TIMER01_VOFFSET 0x00000000 -#define PB926_UART0_VOFFSET 0x00001000 -#define PB926_VIC_VOFFSET 0x00002000 -#define PB926_SIC_VOFFSET 0x00003000 -#define PB926_SYSREGS_VOFFSET 0x00005000 -#define PB926_SYSCTRL_VOFFSET 0x00006000 - -#define PB926_UART0_VBASE (IO_AREA0_VADDR + PB926_UART0_VOFFSET) -#define PB926_TIMER01_VBASE (IO_AREA0_VADDR + PB926_TIMER01_VOFFSET) -#define PB926_SYSCTRL_VBASE (IO_AREA0_VADDR + PB926_SYSCTRL_VOFFSET) -#define PB926_VIC_VBASE (IO_AREA0_VADDR + PB926_VIC_VOFFSET) -#define PB926_SIC_VBASE (IO_AREA0_VADDR + PB926_SIC_VOFFSET) -#endif /* __PLATFORM_PB926_OFFSETS_H__ */ - diff --git a/include/l4/platform/ab926/platform.h b/include/l4/platform/ab926/platform.h deleted file mode 100644 index dd4f4cb..0000000 --- a/include/l4/platform/ab926/platform.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __PLATFORM_PB926_PLATFORM_H__ -#define __PLATFORM_PB926_PLATFORM_H__ -/* - * Platform specific ties between drivers and generic APIs used by the kernel. - * E.g. system timer and console. - * - * Copyright (C) Bahadir Balban 2007 - */ - -#include INC_PLAT(offsets.h) -#include INC_GLUE(memlayout.h) - -#define PLATFORM_CONSOLE_BASE PB926_UART0_VBASE -#define PLATFORM_TIMER_BASE PB926_TIMER01_VBASE -#define PLATFORM_SP810_BASE PB926_SYSCTRL_VBASE -#define PLATFORM_IRQCTRL_BASE PB926_VIC_VBASE -#define PLATFORM_SIRQCTRL_BASE PB926_SIC_VBASE - -void platform_irq_enable(int irq); -void platform_irq_disable(int irq); -void timer_start(void); -#endif /* __PLATFORM_PB926_PLATFORM_H__ */ diff --git a/include/l4/platform/ab926/printascii.h b/include/l4/platform/ab926/printascii.h deleted file mode 100644 index 0d0be28..0000000 --- a/include/l4/platform/ab926/printascii.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __PLATFORM__PB926__PRINTASCII__H__ -#define __PLATFORM__PB926__PRINTASCII__H__ - -#define dprintk(str, val) \ -{ \ - printascii(str); \ - printascii("0x"); \ - printhex8((val)); \ - printascii("\n"); \ -} - -void printascii(char *str); -void printhex8(unsigned int); - -#endif /* __PLATFORM__PB926__PRINTASCII__H__ */ diff --git a/include/l4/platform/ab926/uart.h b/include/l4/platform/ab926/uart.h deleted file mode 100644 index 366590f..0000000 --- a/include/l4/platform/ab926/uart.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Platform specific ties to generic uart functions that putc expects. - * - * Copyright (C) 2007 Bahadir Balban - * - */ - -#ifndef __PLATFORM_PB926_UART_H__ -#define __PLATFORM_PB926_UART_H__ - -#include INC_PLAT(offsets.h) -#include INC_GLUE(memlayout.h) - -#define PLATFORM_CONSOLE_BASE PB926_UART0_VBASE -#include - -void uart_init(void); -void uart_putc(char c); - -#endif /* __PLATFORM_PB926_UART_H__ */ diff --git a/scripts/linux/build_linux.py b/scripts/linux/build_linux.py index fa0d143..c4cac45 100755 --- a/scripts/linux/build_linux.py +++ b/scripts/linux/build_linux.py @@ -43,7 +43,6 @@ class LinuxUpdateKernel: self.cpuid_list = (['ARM926', '0x41069265'],) # List of ARCHIDs, to be used by linux based on codezero config self.archid_list = (['PB926', '0x183'], - ['AB926', '0x25E'], ['PB1176', '0x5E0'], ['PBA8', '0x769'], ['EB', '0x33B'], diff --git a/src/platform/ab926/SConscript b/src/platform/ab926/SConscript deleted file mode 100644 index cd867bf..0000000 --- a/src/platform/ab926/SConscript +++ /dev/null @@ -1,10 +0,0 @@ - - -# Inherit global environment -Import('env') - -# The set of source files associated with this SConscript file. -src_local = ['printascii.S','platform.c', 'uart.c', 'timer.c', 'irq.c'] - -obj = env.Object(src_local) -Return('obj') diff --git a/src/platform/ab926/irq.c b/src/platform/ab926/irq.c deleted file mode 100644 index 7b63abf..0000000 --- a/src/platform/ab926/irq.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Support for generic irq handling using platform irq controller (PL190) - * - * Copyright (C) 2007 Bahadir Balban - */ -#include -#include -#include -#include INC_PLAT(irq.h) -#include INC_PLAT(platform.h) -#include INC_ARCH(exception.h) -#include -#include - -struct irq_chip irq_chip_array[IRQ_CHIPS_MAX] = { - [0] = { - .name = "Vectored irq controller", - .level = 0, - .cascade = IRQ_SIC, - .offset = 0, - .ops = { - .init = pl190_vic_init, - .read_irq = pl190_read_irq, - .ack_and_mask = pl190_mask_irq, - .unmask = pl190_unmask_irq, - }, - }, - [1] = { - .name = "Secondary irq controller", - .level = 1, - .cascade = IRQ_NIL, - .offset = SIRQ_CHIP_OFFSET, - .ops = { - .init = pl190_sic_init, - .read_irq = pl190_sic_read_irq, - .ack_and_mask = pl190_sic_mask_irq, - .unmask = pl190_sic_unmask_irq, - }, - }, -}; - -static int platform_timer_handler(void) -{ - sp804_irq_handler(); - return do_timer_irq(); -} - -/* Built-in irq handlers initialised at compile time. - * Else register with register_irq() */ -struct irq_desc irq_desc_array[IRQS_MAX] = { - [IRQ_TIMER01] = { - .name = "Timer01", - .chip = &irq_chip_array[0], - .handler = platform_timer_handler, - }, -}; - diff --git a/src/platform/ab926/platform.c b/src/platform/ab926/platform.c deleted file mode 100644 index d59c955..0000000 --- a/src/platform/ab926/platform.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * PB926 platform-specific initialisation and setup - * - * Copyright (C) 2007 Bahadir Balban - */ - -#include -#include -#include -#include INC_ARCH(linker.h) -#include INC_PLAT(printascii.h) -#include INC_SUBARCH(mm.h) -#include INC_SUBARCH(mmu_ops.h) -#include INC_GLUE(memory.h) -#include INC_GLUE(memlayout.h) -#include INC_PLAT(offsets.h) -#include INC_PLAT(platform.h) -#include INC_PLAT(uart.h) -#include INC_PLAT(irq.h) -#include INC_ARCH(asm.h) - -void init_platform_console(void) -{ - add_boot_mapping(PB926_UART0_BASE, PL011_BASE, PAGE_SIZE, - MAP_IO_DEFAULT_FLAGS); - - /* - * Map same UART IO area to userspace so that primitive uart-based - * userspace printf can work. Note, this raw mapping is to be - * removed in the future, when file-based io is implemented. - */ - add_boot_mapping(PB926_UART0_BASE, USERSPACE_UART_BASE, PAGE_SIZE, - MAP_USR_IO_FLAGS); - - uart_init(); -} - -void init_platform_timer(void) -{ - add_boot_mapping(PB926_TIMER01_BASE, PLATFORM_TIMER_BASE, PAGE_SIZE, - MAP_IO_DEFAULT_FLAGS); - add_boot_mapping(PB926_SYSCTRL_BASE, PB926_SYSCTRL_VBASE, PAGE_SIZE, - MAP_IO_DEFAULT_FLAGS); - timer_init(); -} - -void init_platform_irq_controller() -{ - add_boot_mapping(PB926_VIC_BASE, PLATFORM_IRQCTRL_BASE, PAGE_SIZE, - MAP_IO_DEFAULT_FLAGS); - add_boot_mapping(PB926_SIC_BASE, PLATFORM_SIRQCTRL_BASE, PAGE_SIZE, - MAP_IO_DEFAULT_FLAGS); - irq_controllers_init(); -} - -void platform_init(void) -{ - init_platform_console(); - init_platform_timer(); - init_platform_irq_controller(); -} - diff --git a/src/platform/ab926/printascii.S b/src/platform/ab926/printascii.S deleted file mode 100644 index e727537..0000000 --- a/src/platform/ab926/printascii.S +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Basic UART printing. - */ -#include INC_ARCH(asm.h) -#include INC_GLUE(memlayout.h) - -#define UART_DATA_OFFSET 0x0 - - .macro uart_address rx - mrc p15, 0, \rx, c1, c0 - tst \rx, #1 @ MMU enabled? - moveq \rx, #0x10000000 - orreq \rx, \rx, #0x001F0000 - orreq \rx, \rx, #0x00001000 - /* FIXME: This offset is incorrect */ - movne \rx, #0xf9000000 @#IO_AREA0_VADDR - addne \rx, \rx, #PB926_UART0_VOFFSET @ UART0 page offset from - @ virtual io area base. - .endm - - .macro uart_send, ry, rx - strb \ry, [\rx, #UART_DATA_OFFSET] - .endm - - .macro uart_wait, ry, rx -501: - ldr \ry, [\rx, #0x18] - tst \ry, #1 << 5 - bne 501b - .endm - - .macro uart_busy, ry, rx -501: - ldr \ry, [\rx, #0x18] - tst \ry, #1 << 3 - bne 501b - .endm - - .text -/* - * Useful debugging routines - */ -BEGIN_PROC(printhex8) - mov r1, #8 - b printhex - -BEGIN_PROC(printhex4) - mov r1, #4 - b printhex - -BEGIN_PROC(printhex2) - mov r1, #2 -printhex: adr r2, hexbuf -@printhex: ldr r2, =hexbuf - add r3, r2, r1 - mov r1, #0 - strb r1, [r3] -1: and r1, r0, #15 - mov r0, r0, lsr #4 - cmp r1, #10 - addlt r1, r1, #'0' - addge r1, r1, #'a' - 10 - strb r1, [r3, #-1]! - teq r3, r2 - bne 1b - mov r0, r2 - b printascii - - .ltorg - - - .align - - @ vmem-linked image has strings in vmem addresses. This replaces - @ the reference with corresponding physical address. Note this - @ won't work if memory offsets aren't clear cut values for - @ orr'ing and bic'ing. rm = mmu bits rs = string address. - .macro get_straddr rs, rm - mrc p15, 0, \rm, c1, c0 @ Get MMU bits. - tst \rm, #1 @ MMU enabled? - @subeq \rs, \rs, #KERNEL_AREA_START - biceq \rs, \rs, #KERNEL_AREA_START @ Clear Virtual mem offset. - @orreq \rs, \rs, #PHYS_ADDR_BASE @ Add Phy mem offset. - .endm - -BEGIN_PROC(printascii) - get_straddr r0, r1 - uart_address r3 - b 2f -1: uart_wait r2, r3 - uart_send r1, r3 - uart_busy r2, r3 - teq r1, #'\n' - moveq r1, #'\r' - beq 1b -2: teq r0, #0 - ldrneb r1, [r0], #1 - teqne r1, #0 - bne 1b - mov pc, lr -END_PROC(printascii) - -BEGIN_PROC(printch) - uart_address r3 - mov r1, r0 - mov r0, #0 - b 1b - -hexbuf: .space 16 - diff --git a/src/platform/ab926/timer.c b/src/platform/ab926/timer.c deleted file mode 100644 index fc290af..0000000 --- a/src/platform/ab926/timer.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Ties up platform timer with generic timer api - * - * Copyright (C) 2007 Bahadir Balban - * - */ -#include -#include -#include INC_PLAT(platform.h) -#include -#include - -void timer_init(void) -{ - /* Set timer 0 to 1MHz */ - sp810_set_timclk(0, 1); - - /* Initialise timer */ - sp804_init(); -} - -void timer_start(void) -{ - irq_enable(IRQ_TIMER01); - sp804_set_irq(0, 1); /* Enable timer0 irq */ - sp804_enable(0, 1); /* Enable timer0 */ -} - diff --git a/src/platform/ab926/uart.c b/src/platform/ab926/uart.c deleted file mode 100644 index 35d94f5..0000000 --- a/src/platform/ab926/uart.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Ties up platform's uart driver functions with generic API - * - * Copyright (C) 2007 Bahadir Balban - */ -#include -#include INC_PLAT(platform.h) - -#include - -extern struct pl011_uart uart; - -void uart_init() -{ - uart.base = PL011_BASE; - uart.ops.initialise(&uart); -} - -/* Generic uart function that lib/putchar.c expects to see implemented */ -void uart_putc(char c) -{ - int res; - /* Platform specific uart implementation */ - do { - res = uart.ops.tx_char(c); - } while (res < 0); -} - From 16b984510f1c7679af7b241af5309e031ff54483 Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Fri, 27 Nov 2009 00:52:59 +0530 Subject: [PATCH 16/18] PBA8 platform removed --- config/cml/arm.ruleset | 5 +- .../libdev/timer/sp804/include/sp804_timer.h | 2 +- conts/libdev/uart/include/pl011_uart.h | 2 - include/l4/platform/pba8/irq.h | 25 ---- include/l4/platform/pba8/offsets.h | 77 ----------- include/l4/platform/pba8/platform.h | 32 ----- include/l4/platform/pba8/printascii.h | 15 --- include/l4/platform/pba8/uart.h | 20 --- scripts/linux/build_linux.py | 1 - src/platform/pba8/SConscript | 10 -- src/platform/pba8/irq.c | 61 --------- src/platform/pba8/platform.c | 67 ---------- src/platform/pba8/printascii.S | 121 ------------------ src/platform/pba8/timer.c | 30 ----- src/platform/pba8/uart.c | 29 ----- 15 files changed, 2 insertions(+), 495 deletions(-) delete mode 100644 include/l4/platform/pba8/irq.h delete mode 100644 include/l4/platform/pba8/offsets.h delete mode 100644 include/l4/platform/pba8/platform.h delete mode 100644 include/l4/platform/pba8/printascii.h delete mode 100644 include/l4/platform/pba8/uart.h delete mode 100644 src/platform/pba8/SConscript delete mode 100644 src/platform/pba8/irq.c delete mode 100644 src/platform/pba8/platform.c delete mode 100644 src/platform/pba8/printascii.S delete mode 100644 src/platform/pba8/timer.c delete mode 100644 src/platform/pba8/uart.c diff --git a/config/cml/arm.ruleset b/config/cml/arm.ruleset index 8251edb..cc8dfe0 100644 --- a/config/cml/arm.ruleset +++ b/config/cml/arm.ruleset @@ -22,7 +22,6 @@ arm_platform_type 'ARM Platform Type' PLATFORM_EB 'Realview EB Platform, Unsupported yet' PLATFORM_PB926 'Versatile PB926 Platform' PLATFORM_PB11MPCORE 'Realview PB11MPCore Platform' -PLATFORM_PBA8 'Realview PB-A8 Platform' main_menu 'Codezero Microkernel Configurator' arm_menu 'ARM Architecture Configuration' @@ -57,7 +56,6 @@ choices arm_platform_type PLATFORM_EB PLATFORM_PB926 PLATFORM_PB11MPCORE - PLATFORM_PBA8 default PLATFORM_PB926 choices arm_cpu_type @@ -103,7 +101,6 @@ default CONTAINERS from 1 #Platform rules: unless SUBARCH_V5 suppress PLATFORM_PB926 unless SUBARCH_V6 suppress PLATFORM_PB11MPCORE -unless SUBARCH_V7 suppress PLATFORM_PBA8 #CPU rules: unless SUBARCH_V5 suppress CPU_ARM926 @@ -122,7 +119,7 @@ unless PLATFORM_EB suppress CPU_ARM1136 derive DRIVER_UART_PL011 from SUBARCH_V5 or SUBARCH_V6 or SUBARCH_V7 derive DRIVER_TIMER_SP804 from SUBARCH_V5 or SUBARCH_V6 or SUBARCH_V7 derive DRIVER_IRQ_PL190 from PLATFORM_PB926 -derive DRIVER_IRQ_GIC from PLATFORM_PB11MPCORE or PLATFORM_PBA8 or PLATFORM_EB +derive DRIVER_IRQ_GIC from PLATFORM_PB11MPCORE or PLATFORM_EB # Toolchains: diff --git a/conts/libdev/timer/sp804/include/sp804_timer.h b/conts/libdev/timer/sp804/include/sp804_timer.h index 445074b..0da6d15 100644 --- a/conts/libdev/timer/sp804/include/sp804_timer.h +++ b/conts/libdev/timer/sp804/include/sp804_timer.h @@ -20,7 +20,7 @@ #define TIMER1_PHYS_BASE (TIMER0_PHYS_BASE + SP804_TIMER2_OFFSET) #define TIMER2_PHYS_BASE 0x10012000 #define TIMER3_PHYS_BASE (TIMER2_PHYS_BASE + SP804_TIMER2_OFFSET) -#elif defined(PLATFORM_PB11MPCORE) || defined(PLATFORM_PBA8) +#elif defined(PLATFORM_PB11MPCORE) #define TIMER0_PHYS_BASE 0x10011000 #define TIMER1_PHYS_BASE (TIMER0_PHYS_BASE + SP804_TIMER2_OFFSET) #define TIMER2_PHYS_BASE 0x10012000 diff --git a/conts/libdev/uart/include/pl011_uart.h b/conts/libdev/uart/include/pl011_uart.h index 8dc95d5..90596de 100644 --- a/conts/libdev/uart/include/pl011_uart.h +++ b/conts/libdev/uart/include/pl011_uart.h @@ -26,8 +26,6 @@ #define PL011_BASE 0x10009000 #elif defined(PLATFORM_PB11MPCORE) #define PL011_BASE 0x10009000 -#elif defined(PLATFORM_PBA8) -#define PL011_BASE 0x10009000 #endif #endif diff --git a/include/l4/platform/pba8/irq.h b/include/l4/platform/pba8/irq.h deleted file mode 100644 index ac74940..0000000 --- a/include/l4/platform/pba8/irq.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef __PLATFORM_IRQ_H__ -#define __PLATFORM_IRQ_H__ - -/* TODO: Not sure about this, need to check */ -#define IRQ_CHIPS_MAX 4 -#define IRQS_MAX 96 - -/* - * IRQ indices, 32-63 and 72-89 index - * available for external sources - * 0-32: used for SI, provided by - * distributed interrupt controller - */ -#define IRQ_TIMER01 36 -#define IRQ_TIMER23 37 -#define IRQ_TIMER45 73 -#define IRQ_TIMER67 74 -#define IRQ_RTC 42 -#define IRQ_UART0 44 -#define IRQ_UART1 45 -#define IRQ_UART2 46 -#define IRQ_UART3 47 - - -#endif /* __PLATFORM_IRQ_H__ */ diff --git a/include/l4/platform/pba8/offsets.h b/include/l4/platform/pba8/offsets.h deleted file mode 100644 index 483e988..0000000 --- a/include/l4/platform/pba8/offsets.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Describes physical memory layout of pb926 platform. - * - * Copyright (C) 2007 Bahadir Balban - */ - -#ifndef __PLATFORM_PBA8_OFFSETS_H__ -#define __PLATFORM_PBA8_OFFSETS_H__ - -/* Physical memory base */ -#define PHYS_MEM_START 0x00000000 /* inclusive */ -#define PHYS_MEM_END 0x10000000 /* 256 MB, exclusive */ - -/* - * These bases taken from where kernel is `physically' linked at, - * also used to calculate virtual-to-physical translation offset. - * See the linker script for their sources. PHYS_ADDR_BASE can't - * use a linker variable because it's referred from assembler. - */ -#define PHYS_ADDR_BASE 0x100000 - -/* Device memory base */ -#define PBA8_DEV_PHYS 0x10000000 - -/* Device offsets in physical memory */ -#define PBA8_SYSTEM_REGISTERS 0x10000000 /* System registers */ -#define PBA8_SYSCTRL0_BASE 0x10001000 /* System controller 0 */ -#define PBA8_UART0_BASE 0x10009000 /* UART 0 */ -#define PBA8_UART1_BASE 0x1000A000 /* UART 1 */ -#define PBA8_UART2_BASE 0x1000B000 /* UART 2 */ -#define PBA8_UART3_BASE 0x1000C000 /* UART 3 */ -#define PBA8_WATCHDOG0_BASE 0x1000F000 /* WATCHDOG 0 */ -#define PBA8_WATCHDOG1_BASE 0x10010000 /* WATCHDOG 1 */ -#define PBA8_TIMER01_BASE 0x10011000 /* TIMER 0-1 */ -#define PBA8_TIMER23_BASE 0x10012000 /* TIMER 2-3 */ -#define PBA8_RTC_BASE 0x10017000 /* RTC interface */ -#define PBA8_TIMER45_BASE 0x10018000 /* TIMER 4-5 */ -#define PBA8_TIMER67_BASE 0x10019000 /* TIMER 6-7 */ -#define PBA8_SYSCTRL1_BASE 0x1001A000 /* System controller 1 */ -#define PBA8_GIC0_BASE 0x1E000000 /* GIC 0 */ -#define PBA8_GIC1_BASE 0x1E010000 /* GIC 1 */ -#define PBA8_GIC2_BASE 0x1E020000 /* GIC 2 */ -#define PBA8_GIC3_BASE 0x1E030000 /* GIC 3 */ - -/* - * Uart virtual address until a file-based console access - * is available for userspace - */ -#define USERSPACE_UART_BASE 0x500000 - -/* - * Device offsets in virtual memory. They offset to some virtual - * device base address. Each page on this virtual base is consecutively - * allocated to devices. Nice and smooth. - */ -#define PBA8_SYSREGS_VOFFSET 0x00000000 -#define PBA8_SYSCTRL0_VOFFSET 0x00001000 -#define PBA8_SYSCTRL1_VOFFSET 0x00002000 -#define PBA8_UART0_VOFFSET 0x00003000 -#define PBA8_TIMER01_VOFFSET 0x00004000 -#define PBA8_GIC0_VOFFSET 0x00005000 -#define PBA8_GIC1_VOFFSET 0x00006000 -#define PBA8_GIC2_VOFFSET 0x00007000 -#define PBA8_GIC3_VOFFSET 0x00008000 - -#define PBA8_SYSREGS_VBASE (IO_AREA0_VADDR + PBA8_SYSREGS_VOFFSET) -#define PBA8_SYSCTRL0_VBASE (IO_AREA0_VADDR + PBA8_SYSCTRL0_VOFFSET) -#define PBA8_SYSCTRL1_VBASE (IO_AREA0_VADDR + PBA8_SYSCTRL1_VOFFSET) -#define PBA8_UART0_VBASE (IO_AREA0_VADDR + PBA8_UART0_VOFFSET) -#define PBA8_TIMER01_VBASE (IO_AREA0_VADDR + PBA8_TIMER01_VOFFSET) -#define PBA8_GIC0_VBASE (IO_AREA0_VADDR + PBA8_GIC0_VOFFSET) -#define PBA8_GIC1_VBASE (IO_AREA0_VADDR + PBA8_GIC1_VOFFSET) -#define PBA8_GIC2_VBASE (IO_AREA0_VADDR + PBA8_GIC2_VOFFSET) -#define PBA8_GIC3_VBASE (IO_AREA0_VADDR + PBA8_GIC3_VOFFSET) - -#endif /* __PLATFORM_PBA8_OFFSETS_H__ */ - diff --git a/include/l4/platform/pba8/platform.h b/include/l4/platform/pba8/platform.h deleted file mode 100644 index 96242ef..0000000 --- a/include/l4/platform/pba8/platform.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef __PBA8_PLATFORM_H__ -#define __PBA8_PLATFORM_H__ -/* - * Platform specific ties between drivers and generic APIs used by the kernel. - * E.g. system timer and console. - * - * Copyright (C) Bahadir Balban 2007 - */ - -#include INC_PLAT(offsets.h) -#include INC_GLUE(memlayout.h) - -#define PLATFORM_CONSOLE0_BASE PBA8_UART0_VBASE -#define PLATFORM_TIMER0_BASE PBA8_TIMER01_VBASE -#define PLATFORM_SP810_BASE PBA8_SYSCTRL0_VBASE - -/* Total number of timers present in this platform */ -#define TOTAL_TIMERS 8 - -#define PLATFORM_TIMER0 0 -#define PLATFORM_TIMER1 1 -#define PLATFORM_TIMER2 2 -#define PLATFORM_TIMER3 3 -#define PLATFORM_TIMER4 4 -#define PLATFORM_TIMER5 5 -#define PLATFORM_TIMER6 6 -#define PLATFORM_TIMER7 7 - -void platform_irq_enable(int irq); -void platform_irq_disable(int irq); -void timer_start(void); -#endif /* __PBA8_PLATFORM_H__ */ diff --git a/include/l4/platform/pba8/printascii.h b/include/l4/platform/pba8/printascii.h deleted file mode 100644 index d60aacc..0000000 --- a/include/l4/platform/pba8/printascii.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __PLATFORM__PBA8__PRINTASCII__H__ -#define __PLATFORM__PBA8__PRINTASCII__H__ - -#define dprintk(str, val) \ -{ \ - printascii(str); \ - printascii("0x"); \ - printhex8((val)); \ - printascii("\n"); \ -} - -void printascii(char *str); -void printhex8(unsigned int); - -#endif /* __PLATFORM__PBA8__PRINTASCII__H__ */ diff --git a/include/l4/platform/pba8/uart.h b/include/l4/platform/pba8/uart.h deleted file mode 100644 index 3734ddf..0000000 --- a/include/l4/platform/pba8/uart.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Platform specific ties to generic uart functions that putc expects. - * - * Copyright (C) 2007 Bahadir Balban - * - */ - -#ifndef __PLATFORM_PBA8_UART_H__ -#define __PLATFORM_PBA8_UART_H__ - -#include INC_PLAT(offsets.h) -#include INC_GLUE(memlayout.h) - -#define PLATFORM_CONSOLE_BASE PBA8_UART0_VBASE -#include - -void uart_init(void); -void uart_putc(char c); - -#endif /* __PLATFORM_PB926_UART_H__ */ diff --git a/scripts/linux/build_linux.py b/scripts/linux/build_linux.py index c4cac45..1d2d879 100755 --- a/scripts/linux/build_linux.py +++ b/scripts/linux/build_linux.py @@ -44,7 +44,6 @@ class LinuxUpdateKernel: # List of ARCHIDs, to be used by linux based on codezero config self.archid_list = (['PB926', '0x183'], ['PB1176', '0x5E0'], - ['PBA8', '0x769'], ['EB', '0x33B'], ['PB11MPCORE', '0x3D4'],) diff --git a/src/platform/pba8/SConscript b/src/platform/pba8/SConscript deleted file mode 100644 index cd867bf..0000000 --- a/src/platform/pba8/SConscript +++ /dev/null @@ -1,10 +0,0 @@ - - -# Inherit global environment -Import('env') - -# The set of source files associated with this SConscript file. -src_local = ['printascii.S','platform.c', 'uart.c', 'timer.c', 'irq.c'] - -obj = env.Object(src_local) -Return('obj') diff --git a/src/platform/pba8/irq.c b/src/platform/pba8/irq.c deleted file mode 100644 index 6dfba2a..0000000 --- a/src/platform/pba8/irq.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Support for generic irq handling using platform irq controller (PL190) - * - * Copyright (C) 2007 Bahadir Balban - */ -#include -#include -#include -#include INC_PLAT(irq.h) -#include INC_PLAT(platform.h) -#include INC_ARCH(exception.h) -#include -#include - - -struct irq_chip irq_chip_array[IRQ_CHIPS_MAX]; -#if 0 -struct irq_chip irq_chip_array[IRQ_CHIPS_MAX] = { - [0] = { - .name = "Vectored irq controller", - .level = 0, - .cascade = IRQ_SIC, - .offset = 0, - .ops = { - .init = pl190_vic_init, - .read_irq = pl190_read_irq, - .ack_and_mask = pl190_mask_irq, - .unmask = pl190_unmask_irq, - }, - }, - [1] = { - .name = "Secondary irq controller", - .level = 1, - .cascade = IRQ_NIL, - .offset = SIRQ_CHIP_OFFSET, - .ops = { - .init = pl190_sic_init, - .read_irq = pl190_sic_read_irq, - .ack_and_mask = pl190_sic_mask_irq, - .unmask = pl190_sic_unmask_irq, - }, - }, -}; -#endif - -static int platform_timer_handler(void) -{ - sp804_irq_handler(PLATFORM_TIMER0_BASE); - return do_timer_irq(); -} - -/* Built-in irq handlers initialised at compile time. - * Else register with register_irq() */ -struct irq_desc irq_desc_array[IRQS_MAX] = { - [IRQ_TIMER01] = { - .name = "Timer01", - .chip = &irq_chip_array[0], - .handler = platform_timer_handler, - }, -}; - diff --git a/src/platform/pba8/platform.c b/src/platform/pba8/platform.c deleted file mode 100644 index 0dfe378..0000000 --- a/src/platform/pba8/platform.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * PBA8 platform-specific initialisation and setup - * - * Copyright (C) 2007 Bahadir Balban - */ - -#include -#include -#include -#include INC_ARCH(linker.h) -#include INC_PLAT(printascii.h) -#include INC_SUBARCH(mm.h) -#include INC_SUBARCH(mmu_ops.h) -#include INC_GLUE(memory.h) -#include INC_GLUE(memlayout.h) -#include INC_PLAT(offsets.h) -#include INC_PLAT(platform.h) -#include INC_PLAT(uart.h) -#include INC_PLAT(irq.h) -#include INC_ARCH(asm.h) - -void init_platform_console(void) -{ - add_boot_mapping(PBA8_UART0_BASE, PLATFORM_CONSOLE0_BASE, PAGE_SIZE, - MAP_IO_DEFAULT_FLAGS); - - /* - * Map same UART IO area to userspace so that primitive uart-based - * userspace printf can work. Note, this raw mapping is to be - * removed in the future, when file-based io is implemented. - */ - add_boot_mapping(PBA8_UART0_BASE, USERSPACE_UART_BASE, PAGE_SIZE, - MAP_USR_IO_FLAGS); - - uart_init(); -} - -void init_platform_timer(void) -{ - add_boot_mapping(PBA8_TIMER01_BASE, PLATFORM_TIMER0_BASE, PAGE_SIZE, - MAP_IO_DEFAULT_FLAGS); - add_boot_mapping(PBA8_SYSCTRL0_BASE, PBA8_SYSCTRL0_VBASE, PAGE_SIZE, - MAP_IO_DEFAULT_FLAGS); - /* TODO: May need mapping for SYSCTRL1 */ - add_boot_mapping(PBA8_SYSCTRL1_BASE, PBA8_SYSCTRL1_VBASE, PAGE_SIZE, - MAP_IO_DEFAULT_FLAGS); - timer_init(); -} - -void init_platform_irq_controller() -{ -#if 0 - add_boot_mapping(PB926_VIC_BASE, PLATFORM_IRQCTRL_BASE, PAGE_SIZE, - MAP_IO_DEFAULT_FLAGS); - add_boot_mapping(PB926_SIC_BASE, PLATFORM_SIRQCTRL_BASE, PAGE_SIZE, - MAP_IO_DEFAULT_FLAGS); - irq_controllers_init(); -#endif -} - -void platform_init(void) -{ - init_platform_console(); - init_platform_timer(); - init_platform_irq_controller(); -} - diff --git a/src/platform/pba8/printascii.S b/src/platform/pba8/printascii.S deleted file mode 100644 index 0d60078..0000000 --- a/src/platform/pba8/printascii.S +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Basic UART printing. - */ -#include INC_ARCH(asm.h) -#include INC_GLUE(memlayout.h) -#include INC_PLAT(offsets.h) -#include INC_SUBARCH(mm.h) - -#define UART_DATA_OFFSET 0x0 - -#define UART0_PHYS_BASE PBA8_UART0_BASE -#define UART0_PHYS_BYTE1 (UART0_PHYS_BASE & 0xFF000000) -#define UART0_PHYS_BYTE2 (UART0_PHYS_BASE & 0x00FF0000) -#define UART0_PHYS_BYTE3_4 (UART0_PHYS_BASE & 0x0000FFFF) - -#define UART0_VIRT_BASE PBA8_UART0_VBASE -#define UART0_VIRT_BYTE1 (UART0_VIRT_BASE & 0xFF000000) -#define UART0_VIRT_BYTE2 (UART0_VIRT_BASE & 0x00FF0000) -#define UART0_VIRT_BYTE3_4 (UART0_VIRT_BASE & 0x0000FFFF) - - .macro uart_address rx - mrc p15, 0, \rx, c1, c0 - tst \rx, #1 @ MMU enabled? - moveq \rx, #UART0_PHYS_BYTE1 - orreq \rx, #UART0_PHYS_BYTE2 - orreq \rx, #UART0_PHYS_BYTE3_4 - movne \rx, #UART0_VIRT_BYTE1 - orrne \rx, #UART0_VIRT_BYTE2 - orrne \rx, #UART0_VIRT_BYTE3_4 - .endm - - .macro uart_send, ry, rx - strb \ry, [\rx, #UART_DATA_OFFSET] - .endm - - .macro uart_wait, ry, rx -501: - ldr \ry, [\rx, #0x18] - tst \ry, #1 << 5 - bne 501b - .endm - - .macro uart_busy, ry, rx -501: - ldr \ry, [\rx, #0x18] - tst \ry, #1 << 3 - bne 501b - .endm - - .text -/* - * Useful debugging routines - */ -BEGIN_PROC(printhex8) - mov r1, #8 - b printhex - -BEGIN_PROC(printhex4) - mov r1, #4 - b printhex - -BEGIN_PROC(printhex2) - mov r1, #2 -printhex: adr r2, hexbuf -@printhex: ldr r2, =hexbuf - add r3, r2, r1 - mov r1, #0 - strb r1, [r3] -1: and r1, r0, #15 - mov r0, r0, lsr #4 - cmp r1, #10 - addlt r1, r1, #'0' - addge r1, r1, #'a' - 10 - strb r1, [r3, #-1]! - teq r3, r2 - bne 1b - mov r0, r2 - b printascii - - .ltorg - - - .align - - @ vmem-linked image has strings in vmem addresses. This replaces - @ the reference with corresponding physical address. Note this - @ won't work if memory offsets aren't clear cut values for - @ orr'ing and bic'ing. rm = mmu bits rs = string address. - .macro get_straddr rs, rm - mrc p15, 0, \rm, c1, c0 @ Get MMU bits. - tst \rm, #1 @ MMU enabled? - @subeq \rs, \rs, #KERNEL_AREA_START - biceq \rs, \rs, #KERNEL_AREA_START @ Clear Virtual mem offset. - @orreq \rs, \rs, #PHYS_ADDR_BASE @ Add Phy mem offset. - .endm - -BEGIN_PROC(printascii) - get_straddr r0, r1 - uart_address r3 - b 2f -1: uart_wait r2, r3 - uart_send r1, r3 - uart_busy r2, r3 - teq r1, #'\n' - moveq r1, #'\r' - beq 1b -2: teq r0, #0 - ldrneb r1, [r0], #1 - teqne r1, #0 - bne 1b - mov pc, lr -END_PROC(printascii) - -BEGIN_PROC(printch) - uart_address r3 - mov r1, r0 - mov r0, #0 - b 1b - -hexbuf: .space 16 - diff --git a/src/platform/pba8/timer.c b/src/platform/pba8/timer.c deleted file mode 100644 index 0ec384b..0000000 --- a/src/platform/pba8/timer.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Ties up platform timer with generic timer api - * - * Copyright (C) 2007 Bahadir Balban - * - */ -#include -#include -#include INC_PLAT(platform.h) -#include -#include - -void timer_init(void) -{ - /* Set timer 0 to 1MHz */ - sp810_set_timclk(PLATFORM_TIMER0, 1); - - /* Initialise timer */ - sp804_init(PLATFORM_TIMER0_BASE, SP804_TIMER_RUNMODE_PERIODIC, \ - SP804_TIMER_WRAPMODE_WRAPPING, SP804_TIMER_WIDTH32BIT, \ - SP804_TIMER_IRQENABLE); - -} - -void timer_start(void) -{ - irq_enable(IRQ_TIMER01); - sp804_enable(PLATFORM_TIMER0, 1); /* Enable timer0 */ -} - diff --git a/src/platform/pba8/uart.c b/src/platform/pba8/uart.c deleted file mode 100644 index ae1fd76..0000000 --- a/src/platform/pba8/uart.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Ties up platform's uart driver functions with generic API - * - * Copyright (C) 2007 Bahadir Balban - */ -#include -#include INC_PLAT(platform.h) - -#include - -extern struct pl011_uart uart; - -void uart_init() -{ - /* We are using UART0 for kernel */ - uart.base = PLATFORM_CONSOLE0_BASE; - pl011_initialise_device(&uart); -} - -/* Generic uart function that lib/putchar.c expects to see implemented */ -void uart_putc(char c) -{ - int res; - /* Platform specific uart implementation */ - do { - res = pl011_tx_char(uart.base, c); - } while (res < 0); -} - From 846635f5822820ff82a9894ad90bf4717028f707 Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Fri, 27 Nov 2009 14:16:40 +0530 Subject: [PATCH 17/18] Edited linux scripts to generate elf from vmlinux, to be used by codezero --- scripts/linux/build_linux.py | 38 +++++++++--------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/scripts/linux/build_linux.py b/scripts/linux/build_linux.py index 1d2d879..dd13533 100755 --- a/scripts/linux/build_linux.py +++ b/scripts/linux/build_linux.py @@ -163,21 +163,11 @@ class LinuxBuilder: self.LINUX_KERNEL_BUILDDIR = \ source_to_builddir(LINUX_KERNELDIR, container.id) - self.linux_lds_in = join(self.LINUX_KERNELDIR, "linux.lds.in") - self.linux_lds_out = join(self.LINUX_KERNEL_BUILDDIR, "linux.lds") - self.linux_S_in = join(self.LINUX_KERNELDIR, "linux.S.in") - self.linux_S_out = join(self.LINUX_KERNEL_BUILDDIR, "linux.S") - - self.linux_h_in = join(self.LINUX_KERNELDIR, "linux.h.in") - self.linux_h_out = join(self.LINUX_KERNEL_BUILDDIR, "linux.h") - - self.linux_elf_out = join(self.LINUX_KERNEL_BUILDDIR, "linux.elf") - self.container = container self.kernel_binary_image = \ join(os.path.relpath(self.LINUX_KERNEL_BUILDDIR, LINUX_KERNELDIR), \ - "arch/arm/boot/Image") - self.kernel_image = None + "vmlinux") + self.kernel_image = join(self.LINUX_KERNEL_BUILDDIR, "linux.elf") self.kernel_updater = LinuxUpdateKernel(self.container) def build_linux(self, config): @@ -195,24 +185,14 @@ class LinuxBuilder: "CROSS_COMPILE=" + config.user_toolchain + " O=" + \ self.LINUX_KERNEL_BUILDDIR) - with open(self.linux_h_out, 'w+') as output: - with open(self.linux_h_in, 'r') as input: - output.write(input.read() % {'cn' : self.container.id}) - - with open(self.linux_S_in, 'r') as input: - with open(self.linux_S_out, 'w+') as output: - content = input.read() % self.kernel_binary_image - output.write(content) - - os.system(config.user_toolchain + "cpp -I%s -P %s > %s" % \ - (self.LINUX_KERNEL_BUILDDIR, self.linux_lds_in, \ - self.linux_lds_out)) - os.system(config.user_toolchain + "gcc -nostdlib -o %s -T%s %s" % \ - (self.linux_elf_out, self.linux_lds_out, self.linux_S_out)) - - # Get the kernel image path - self.kernel_image = self.linux_elf_out + # Generate kernel_image, elf to be used by codezero + linux_elf_gen_cmd = ("arm-none-linux-gnueabi-objcopy -R .note \ + -R .note.gnu.build-id -R .comment -S --change-addresses " + \ + str(conv_hex(-self.container.linux_page_offset + self.container.linux_phys_offset)) + \ + " " + self.kernel_binary_image + " " + self.kernel_image) + #print cmd + os.system(linux_elf_gen_cmd) print 'Done...' def clean(self): From 41c87d9c8cc26f3804e695732bf702e309e51b47 Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Sun, 29 Nov 2009 12:16:51 +0530 Subject: [PATCH 18/18] Errors due to rebasing corrected. Still not done, ahve some problem in IRQ patches added. --- config/caps.py | 4 ++-- conts/baremetal/baremetal5/main.c | 1 + src/generic/capability.c | 2 +- src/generic/resource.c | 4 +--- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/config/caps.py b/config/caps.py index b447cc2..96dba55 100644 --- a/config/caps.py +++ b/config/caps.py @@ -144,7 +144,7 @@ cap_strings = { 'ipc' : \ \t\t\t[${idx}] = { \t\t\t\t/* For device selection */ \t\t\t\t.target = ${cid}, -\t\t\t\t.uattr[0] = CAP_DEVTYPE_UART | (${devnum} << 16), +\t\t\t\t.attr = CAP_DEVTYPE_UART | (${devnum} << 16), \t\t\t\t.type = CAP_TYPE_MAP_PHYSMEM | CAP_RTYPE_CONTAINER, \t\t\t\t.access = CAP_MAP_READ | CAP_MAP_WRITE | CAP_MAP_EXEC | \t\t\t\t\tCAP_MAP_CACHED | CAP_MAP_UNCACHED | CAP_MAP_UNMAP | CAP_MAP_UTCB, @@ -158,7 +158,7 @@ cap_strings = { 'ipc' : \ \t\t\t[${idx}] = { \t\t\t\t/* For device selection */ \t\t\t\t.target = ${cid}, -\t\t\t\t.uattr[0] = CAP_DEVTYPE_TIMER | (${devnum} << 16), +\t\t\t\t.attr = CAP_DEVTYPE_TIMER | (${devnum} << 16), \t\t\t\t.type = CAP_TYPE_MAP_PHYSMEM | CAP_RTYPE_CONTAINER, \t\t\t\t.access = CAP_MAP_READ | CAP_MAP_WRITE | CAP_MAP_EXEC | \t\t\t\t\tCAP_MAP_CACHED | CAP_MAP_UNCACHED | CAP_MAP_UNMAP | CAP_MAP_UTCB, diff --git a/conts/baremetal/baremetal5/main.c b/conts/baremetal/baremetal5/main.c index ad4c44f..311f76d 100644 --- a/conts/baremetal/baremetal5/main.c +++ b/conts/baremetal/baremetal5/main.c @@ -194,6 +194,7 @@ static struct address_pool device_vaddr_pool; /* * Initialize a virtual address pool * for mapping physical devices. + */ void init_vaddr_pool(void) { diff --git a/src/generic/capability.c b/src/generic/capability.c index 360131b..58542f3 100644 --- a/src/generic/capability.c +++ b/src/generic/capability.c @@ -15,7 +15,7 @@ #include #include #include -#include +//#include #include INC_GLUE(message.h) #include INC_GLUE(ipc.h) diff --git a/src/generic/resource.c b/src/generic/resource.c index 7cff3e8..74c5c50 100644 --- a/src/generic/resource.c +++ b/src/generic/resource.c @@ -508,9 +508,7 @@ int copy_pager_info(struct pager *pager, struct pager_info *pinfo) cap->start = cap_info->start; cap->end = cap_info->end; cap->size = cap_info->size; - cap->uattr[0] = cap_info->uattr[0]; - cap->uattr[1] = cap_info->uattr[1]; - + cap->attr = cap_info->attr; cap_list_insert(cap, &pager->cap_list); }