Changeset 45e9cc6 in mainline


Ignore:
Timestamp:
2010-12-04T20:37:19Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b5ec347
Parents:
4144630 (diff), 35537a7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge with mainline

Files:
7 added
30 edited
1 moved

Legend:

Unmodified
Added
Removed
  • .bzrignore

    r4144630 r45e9cc6  
    9494./uspace/dist/drv/rootia32/
    9595./uspace/dist/drv/uhci/
     96./uspace/dist/drv/usbhub/
    9697./uspace/dist/drv/usbkbd/
    9798./uspace/dist/drv/vhc/
     
    130131./uspace/drv/rootia32/rootia32
    131132./uspace/drv/uhci/uhci
     133./uspace/drv/usbhub/usbhub
    132134./uspace/drv/usbkbd/usbkbd
    133135./uspace/drv/vhc/vhc
  • boot/arch/amd64/Makefile.inc

    r4144630 r45e9cc6  
    4242        ns8250 \
    4343        uhci \
     44        usbhub \
    4445        usbkbd
    4546       
  • boot/arch/mips32/include/arch.h

    r4144630 r45e9cc6  
    4040
    4141#define MSIM_VIDEORAM_ADDRESS  0xb0000000
    42 #define MSIM_DORDER_ADDRESS    0xb0000004
     42#define MSIM_DORDER_ADDRESS    0xb0000100
    4343
    4444#ifndef __ASM__
  • contrib/conf/msim.conf

    r4144630 r45e9cc6  
    1616add dprinter printer 0x10000000
    1717add dkeyboard keyboard 0x10000000 2
    18 add dorder order 0x10000004 5
     18add dorder order 0x10000100 5
  • kernel/arch/mips32/src/exception.c

    r4144630 r45e9cc6  
    7474void istate_decode(istate_t *istate)
    7575{
    76         printf("epc=%p\tsta=%#0" PRIx32 "\t"
    77             "lo =%#0" PRIx32 "\thi =%#0" PRIx32 "\n",
     76        printf("epc=%p\tsta=%#010" PRIx32 "\t"
     77            "lo =%#010" PRIx32 "\thi =%#010" PRIx32 "\n",
    7878            (void *) istate->epc, istate->status,
    7979            istate->lo, istate->hi);
    8080       
    81         printf("a0 =%#0" PRIx32 "\ta1 =%#0" PRIx32 "\t"
    82             "a2 =%#0" PRIx32 "\ta3 =%#0" PRIx32 "\n",
     81        printf("a0 =%#010" PRIx32 "\ta1 =%#010" PRIx32 "\t"
     82            "a2 =%#010" PRIx32 "\ta3 =%#010" PRIx32 "\n",
    8383            istate->a0, istate->a1, istate->a2, istate->a3);
    8484       
    85         printf("t0 =%#0" PRIx32 "\tt1 =%#0" PRIx32 "\t"
    86             "t2 =%#0" PRIx32 "\tt3 =%#0" PRIx32 "\n",
     85        printf("t0 =%#010" PRIx32 "\tt1 =%#010" PRIx32 "\t"
     86            "t2 =%#010" PRIx32 "\tt3 =%#010" PRIx32 "\n",
    8787            istate->t0, istate->t1, istate->t2, istate->t3);
    8888       
    89         printf("t4 =%#0" PRIx32 "\tt5 =%#0" PRIx32 "\t"
    90             "t6 =%#0" PRIx32 "\tt7 =%#0" PRIx32 "\n",
     89        printf("t4 =%#010" PRIx32 "\tt5 =%#010" PRIx32 "\t"
     90            "t6 =%#010" PRIx32 "\tt7 =%#010" PRIx32 "\n",
    9191            istate->t4, istate->t5, istate->t6, istate->t7);
    9292       
    93         printf("t8 =%#0" PRIx32 "\tt9 =%#0" PRIx32 "\t"
    94             "v0 =%#0" PRIx32 "\tv1 =%#0" PRIx32 "\n",
     93        printf("t8 =%#010" PRIx32 "\tt9 =%#010" PRIx32 "\t"
     94            "v0 =%#010" PRIx32 "\tv1 =%#010" PRIx32 "\n",
    9595            istate->t8, istate->t9, istate->v0, istate->v1);
    9696       
    97         printf("s0 =%#0" PRIx32 "\ts1 =%#0" PRIx32 "\t"
    98             "s2 =%#0" PRIx32 "\ts3 =%#0" PRIx32 "\n",
     97        printf("s0 =%#010" PRIx32 "\ts1 =%#010" PRIx32 "\t"
     98            "s2 =%#010" PRIx32 "\ts3 =%#010" PRIx32 "\n",
    9999            istate->s0, istate->s1, istate->s2, istate->s3);
    100100       
    101         printf("s4 =%#0" PRIx32 "\ts5 =%#0" PRIx32 "\t"
    102             "s6 =%#0" PRIx32 "\ts7 =%#0" PRIx32 "\n",
     101        printf("s4 =%#010" PRIx32 "\ts5 =%#010" PRIx32 "\t"
     102            "s6 =%#010" PRIx32 "\ts7 =%#010" PRIx32 "\n",
    103103            istate->s4, istate->s5, istate->s6, istate->s7);
    104104       
    105         printf("s8 =%#0" PRIx32 "\tat =%#0" PRIx32 "\t"
    106             "kt0=%#0" PRIx32 "\tkt1=%#0" PRIx32 "\n",
     105        printf("s8 =%#010" PRIx32 "\tat =%#010" PRIx32 "\t"
     106            "kt0=%#010" PRIx32 "\tkt1=%#010" PRIx32 "\n",
    107107            istate->s8, istate->at, istate->kt0, istate->kt1);
    108108       
  • kernel/arch/mips32/src/smp/dorder.c

    r4144630 r45e9cc6  
    3737#include <arch/smp/dorder.h>
    3838
    39 #define MSIM_DORDER_ADDRESS  0xB0000004
     39#define MSIM_DORDER_ADDRESS  0xB0000100
    4040
    4141#ifdef CONFIG_SMP
  • kernel/generic/include/ipc/ipc.h

    r4144630 r45e9cc6  
    4545/** Maximum active async calls per thread */
    4646#ifdef CONFIG_DEBUG
    47         #define IPC_MAX_ASYNC_CALLS  4
     47        #define IPC_MAX_ASYNC_CALLS  16
    4848#else
    4949        #define IPC_MAX_ASYNC_CALLS  4000
  • tools/config.py

    r4144630 r45e9cc6  
    33# Copyright (c) 2006 Ondrej Palkovsky
    44# Copyright (c) 2009 Martin Decky
     5# Copyright (c) 2010 Jiri Svoboda
    56# All rights reserved.
    67#
     
    4041import xtui
    4142
    42 INPUT = sys.argv[1]
     43RULES_FILE = sys.argv[1]
    4344MAKEFILE = 'Makefile.config'
    4445MACROS = 'config.h'
    45 PRECONF = 'defaults'
    46 
    47 def read_defaults(fname, defaults):
     46PRESETS_DIR = 'defaults'
     47
     48def read_config(fname, config):
    4849        "Read saved values from last configuration run"
    4950       
     
    5253        for line in inf:
    5354                res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
    54                 if (res):
    55                         defaults[res.group(1)] = res.group(2)
     55                if res:
     56                        config[res.group(1)] = res.group(2)
    5657       
    5758        inf.close()
    5859
    59 def check_condition(text, defaults, ask_names):
     60def check_condition(text, config, rules):
    6061        "Check that the condition specified on input line is True (only CNF and DNF is supported)"
    6162       
    6263        ctype = 'cnf'
    6364       
    64         if ((')|' in text) or ('|(' in text)):
     65        if (')|' in text) or ('|(' in text):
    6566                ctype = 'dnf'
    6667       
    67         if (ctype == 'cnf'):
     68        if ctype == 'cnf':
    6869                conds = text.split('&')
    6970        else:
     
    7172       
    7273        for cond in conds:
    73                 if (cond.startswith('(')) and (cond.endswith(')')):
     74                if cond.startswith('(') and cond.endswith(')'):
    7475                        cond = cond[1:-1]
    7576               
    76                 inside = check_inside(cond, defaults, ctype)
     77                inside = check_inside(cond, config, ctype)
    7778               
    7879                if (ctype == 'cnf') and (not inside):
    7980                        return False
    8081               
    81                 if (ctype == 'dnf') and (inside):
     82                if (ctype == 'dnf') and inside:
    8283                        return True
    8384       
    84         if (ctype == 'cnf'):
     85        if ctype == 'cnf':
    8586                return True
    8687        return False
    8788
    88 def check_inside(text, defaults, ctype):
     89def check_inside(text, config, ctype):
    8990        "Check for condition"
    9091       
    91         if (ctype == 'cnf'):
     92        if ctype == 'cnf':
    9293                conds = text.split('|')
    9394        else:
     
    9697        for cond in conds:
    9798                res = re.match(r'^(.*?)(!?=)(.*)$', cond)
    98                 if (not res):
     99                if not res:
    99100                        raise RuntimeError("Invalid condition: %s" % cond)
    100101               
     
    103104                condval = res.group(3)
    104105               
    105                 if (not condname in defaults):
     106                if not condname in config:
    106107                        varval = ''
    107108                else:
    108                         varval = defaults[condname]
     109                        varval = config[condname]
    109110                        if (varval == '*'):
    110111                                varval = 'y'
    111112               
    112                 if (ctype == 'cnf'):
     113                if ctype == 'cnf':
    113114                        if (oper == '=') and (condval == varval):
    114115                                return True
     
    123124                                return False
    124125       
    125         if (ctype == 'cnf'):
     126        if ctype == 'cnf':
    126127                return False
    127128       
    128129        return True
    129130
    130 def parse_config(fname, ask_names):
    131         "Parse configuration file"
     131def parse_rules(fname, rules):
     132        "Parse rules file"
    132133       
    133134        inf = open(fname, 'r')
     
    138139        for line in inf:
    139140               
    140                 if (line.startswith('!')):
     141                if line.startswith('!'):
    141142                        # Ask a question
    142143                        res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line)
    143144                       
    144                         if (not res):
     145                        if not res:
    145146                                raise RuntimeError("Weird line: %s" % line)
    146147                       
     
    149150                        vartype = res.group(3)
    150151                       
    151                         ask_names.append((varname, vartype, name, choices, cond))
     152                        rules.append((varname, vartype, name, choices, cond))
    152153                        name = ''
    153154                        choices = []
    154155                        continue
    155156               
    156                 if (line.startswith('@')):
     157                if line.startswith('@'):
    157158                        # Add new line into the 'choices' array
    158159                        res = re.match(r'@\s*(?:\[(.*?)\])?\s*"(.*?)"\s*(.*)$', line)
     
    164165                        continue
    165166               
    166                 if (line.startswith('%')):
     167                if line.startswith('%'):
    167168                        # Name of the option
    168169                        name = line[1:].strip()
    169170                        continue
    170171               
    171                 if ((line.startswith('#')) or (line == '\n')):
     172                if line.startswith('#') or (line == '\n'):
    172173                        # Comment or empty line
    173174                        continue
     
    181182        "Return '*' if yes, ' ' if no"
    182183       
    183         if (default == 'y'):
     184        if default == 'y':
    184185                return '*'
    185186       
     
    199200        cnt = 0
    200201        for key, val in choices:
    201                 if ((default) and (key == default)):
     202                if (default) and (key == default):
    202203                        position = cnt
    203204               
     
    207208        (button, value) = xtui.choice_window(screen, name, 'Choose value', options, position)
    208209       
    209         if (button == 'cancel'):
     210        if button == 'cancel':
    210211                return None
    211212       
    212213        return choices[value][0]
    213214
    214 def check_choices(defaults, ask_names):
    215         "Check whether all accessible variables have a default"
    216        
    217         for varname, vartype, name, choices, cond in ask_names:
    218                 if ((cond) and (not check_condition(cond, defaults, ask_names))):
     215## Infer and verify configuration values.
     216#
     217# Augment @a config with values that can be inferred, purge invalid ones
     218# and verify that all variables have a value (previously specified or inferred).
     219#
     220# @param config Configuration to work on
     221# @param rules  Rules
     222#
     223# @return       True if configuration is complete and valid, False
     224#               otherwise.
     225#
     226def infer_verify_choices(config, rules):
     227        "Infer and verify configuration values."
     228       
     229        for rule in rules:
     230                varname, vartype, name, choices, cond = rule
     231
     232                if cond and (not check_condition(cond, config, rules)):
    219233                        continue
    220234               
    221                 if (not varname in defaults):
     235                if not varname in config:
     236                        value = None
     237                else:
     238                        value = config[varname]
     239
     240                if not rule_value_is_valid(rule, value):
     241                        value = None
     242
     243                default = rule_get_default(rule)
     244                if default != None:
     245                        config[varname] = default
     246
     247                if not varname in config:
    222248                        return False
    223249       
    224250        return True
    225251
    226 def create_output(mkname, mcname, defaults, ask_names):
     252## Get default value from a rule.
     253def rule_get_default(rule):
     254        varname, vartype, name, choices, cond = rule
     255
     256        default = None
     257
     258        if vartype == 'choice':
     259                # If there is just one option, use it
     260                if len(choices) == 1:
     261                        default = choices[0][0]
     262        elif vartype == 'y':
     263                default = '*'
     264        elif vartype == 'n':
     265                default = 'n'
     266        elif vartype == 'y/n':
     267                default = 'y'
     268        elif vartype == 'n/y':
     269                default = 'n'
     270        else:
     271                raise RuntimeError("Unknown variable type: %s" % vartype)
     272
     273        return default
     274
     275## Get option from a rule.
     276#
     277# @param rule   Rule for a variable
     278# @param value  Current value of the variable
     279#
     280# @return Option (string) to ask or None which means not to ask.
     281#
     282def rule_get_option(rule, value):
     283        varname, vartype, name, choices, cond = rule
     284
     285        option = None
     286
     287        if vartype == 'choice':
     288                # If there is just one option, don't ask
     289                if len(choices) != 1:
     290                        if (value == None):
     291                                option = "?     %s --> " % name
     292                        else:
     293                                option = "      %s [%s] --> " % (name, value)
     294        elif vartype == 'y':
     295                pass
     296        elif vartype == 'n':
     297                pass
     298        elif vartype == 'y/n':
     299                option = "  <%s> %s " % (yes_no(value), name)
     300        elif vartype == 'n/y':
     301                option ="  <%s> %s " % (yes_no(value), name)
     302        else:
     303                raise RuntimeError("Unknown variable type: %s" % vartype)
     304
     305        return option
     306
     307## Check if variable value is valid.
     308#
     309# @param rule   Rule for the variable
     310# @param value  Value of the variable
     311#
     312# @return       True if valid, False if not valid.
     313#
     314def rule_value_is_valid(rule, value):
     315        varname, vartype, name, choices, cond = rule
     316       
     317        if value == None:
     318                return True
     319
     320        if vartype == 'choice':
     321                if not value in [choice[0] for choice in choices]:
     322                        return False
     323        elif vartype == 'y':
     324                if value != 'y':
     325                        return False
     326        elif vartype == 'n':
     327                if value != 'n':
     328                        return False
     329        elif vartype == 'y/n':
     330                if not value in ['y', 'n']:
     331                        return False
     332        elif vartype == 'n/y':
     333                if not value in ['y', 'n']:
     334                        return False
     335        else:
     336                raise RuntimeError("Unknown variable type: %s" % vartype)
     337
     338        return True
     339
     340def create_output(mkname, mcname, config, rules):
    227341        "Create output configuration"
    228342       
     
    238352                sys.stderr.write("failed\n")
    239353       
    240         if (len(version) == 3):
     354        if len(version) == 3:
    241355                revision = version[1]
    242                 if (version[0] != 1):
     356                if version[0] != 1:
    243357                        revision += 'M'
    244358                revision += ' (%s)' % version[2]
     
    259373        defs = 'CONFIG_DEFS ='
    260374       
    261         for varname, vartype, name, choices, cond in ask_names:
    262                 if ((cond) and (not check_condition(cond, defaults, ask_names))):
     375        for varname, vartype, name, choices, cond in rules:
     376                if cond and (not check_condition(cond, config, rules)):
    263377                        continue
    264378               
    265                 if (not varname in defaults):
    266                         default = ''
     379                if not varname in config:
     380                        value = ''
    267381                else:
    268                         default = defaults[varname]
    269                         if (default == '*'):
    270                                 default = 'y'
    271                
    272                 outmk.write('# %s\n%s = %s\n\n' % (name, varname, default))
    273                
    274                 if ((vartype == "y") or (vartype == "n") or (vartype == "y/n") or (vartype == "n/y")):
    275                         if (default == "y"):
     382                        value = config[varname]
     383                        if (value == '*'):
     384                                value = 'y'
     385               
     386                outmk.write('# %s\n%s = %s\n\n' % (name, varname, value))
     387               
     388                if vartype in ["y", "n", "y/n", "n/y"]:
     389                        if value == "y":
    276390                                outmc.write('/* %s */\n#define %s\n\n' % (name, varname))
    277391                                defs += ' -D%s' % varname
    278392                else:
    279                         outmc.write('/* %s */\n#define %s %s\n#define %s_%s\n\n' % (name, varname, default, varname, default))
    280                         defs += ' -D%s=%s -D%s_%s' % (varname, default, varname, default)
    281        
    282         if (revision is not None):
     393                        outmc.write('/* %s */\n#define %s %s\n#define %s_%s\n\n' % (name, varname, value, varname, value))
     394                        defs += ' -D%s=%s -D%s_%s' % (varname, value, varname, value)
     395       
     396        if revision is not None:
    283397                outmk.write('REVISION = %s\n' % revision)
    284398                outmc.write('#define REVISION %s\n' % revision)
     
    299413        return list
    300414
    301 def read_preconfigured(root, fname, screen, defaults):
     415## Choose a profile and load configuration presets.
     416#
     417def load_presets(root, fname, screen, config):
    302418        options = []
    303419        opt2path = {}
     
    309425                canon = os.path.join(path, fname)
    310426               
    311                 if ((os.path.isdir(path)) and (os.path.exists(canon)) and (os.path.isfile(canon))):
     427                if os.path.isdir(path) and os.path.exists(canon) and os.path.isfile(canon):
    312428                        subprofile = False
    313429                       
     
    317433                                subcanon = os.path.join(subpath, fname)
    318434                               
    319                                 if ((os.path.isdir(subpath)) and (os.path.exists(subcanon)) and (os.path.isfile(subcanon))):
     435                                if os.path.isdir(subpath) and os.path.exists(subcanon) and os.path.isfile(subcanon):
    320436                                        subprofile = True
    321437                                        options.append("%s (%s)" % (name, subname))
     
    323439                                        cnt += 1
    324440                       
    325                         if (not subprofile):
     441                        if not subprofile:
    326442                                options.append(name)
    327443                                opt2path[cnt] = (canon, None)
     
    330446        (button, value) = xtui.choice_window(screen, 'Load preconfigured defaults', 'Choose configuration profile', options, None)
    331447       
    332         if (button == 'cancel'):
     448        if button == 'cancel':
    333449                return None
    334450       
    335         read_defaults(opt2path[value][0], defaults)
    336         if (opt2path[value][1] != None):
    337                 read_defaults(opt2path[value][1], defaults)
     451        read_config(opt2path[value][0], config)
     452        if opt2path[value][1] != None:
     453                read_config(opt2path[value][1], config)
    338454
    339455def main():
    340         defaults = {}
    341         ask_names = []
    342        
    343         # Parse configuration file
    344         parse_config(INPUT, ask_names)
    345        
    346         # Read defaults from previous run
     456        config = {}
     457        rules = []
     458       
     459        # Parse rules file
     460        parse_rules(RULES_FILE, rules)
     461       
     462        # Read configuration from previous run
    347463        if os.path.exists(MAKEFILE):
    348                 read_defaults(MAKEFILE, defaults)
    349        
    350         # Default mode: only check defaults and regenerate configuration
    351         if ((len(sys.argv) >= 3) and (sys.argv[2] == 'default')):
    352                 if (check_choices(defaults, ask_names)):
    353                         create_output(MAKEFILE, MACROS, defaults, ask_names)
     464                read_config(MAKEFILE, config)
     465       
     466        # Default mode: only check values and regenerate configuration files
     467        if (len(sys.argv) >= 3) and (sys.argv[2] == 'default'):
     468                if (infer_verify_choices(config, rules)):
     469                        create_output(MAKEFILE, MACROS, config, rules)
    354470                        return 0
    355471       
    356         # Check mode: only check defaults
    357         if ((len(sys.argv) >= 3) and (sys.argv[2] == 'check')):
    358                 if (check_choices(defaults, ask_names)):
     472        # Check mode: only check configuration
     473        if (len(sys.argv) >= 3) and (sys.argv[2] == 'check'):
     474                if infer_verify_choices(config, rules):
    359475                        return 0
    360476                return 1
     
    366482                while True:
    367483                       
    368                         # Cancel out all defaults which have to be deduced
    369                         for varname, vartype, name, choices, cond in ask_names:
    370                                 if ((vartype == 'y') and (varname in defaults) and (defaults[varname] == '*')):
    371                                         defaults[varname] = None
     484                        # Cancel out all values which have to be deduced
     485                        for varname, vartype, name, choices, cond in rules:
     486                                if (vartype == 'y') and (varname in config) and (config[varname] == '*'):
     487                                        config[varname] = None
    372488                       
    373489                        options = []
     
    377493                        options.append("  --- Load preconfigured defaults ... ")
    378494                       
    379                         for varname, vartype, name, choices, cond in ask_names:
    380                                
    381                                 if ((cond) and (not check_condition(cond, defaults, ask_names))):
     495                        for rule in rules:
     496                                varname, vartype, name, choices, cond = rule
     497                               
     498                                if cond and (not check_condition(cond, config, rules)):
    382499                                        continue
    383500                               
    384                                 if (varname == selname):
     501                                if varname == selname:
    385502                                        position = cnt
    386503                               
    387                                 if (not varname in defaults):
    388                                         default = None
     504                                if not varname in config:
     505                                        value = None
    389506                                else:
    390                                         default = defaults[varname]
    391                                
    392                                 if (vartype == 'choice'):
    393                                         # Check if the default is an acceptable value
    394                                         if ((default) and (not default in [choice[0] for choice in choices])):
    395                                                 default = None
    396                                                 defaults.pop(varname)
    397                                        
    398                                         # If there is just one option, use it
    399                                         if (len(choices) == 1):
    400                                                 defaults[varname] = choices[0][0]
    401                                                 continue
    402                                        
    403                                         if (default == None):
    404                                                 options.append("?     %s --> " % name)
    405                                         else:
    406                                                 options.append("      %s [%s] --> " % (name, default))
    407                                 elif (vartype == 'y'):
    408                                         defaults[varname] = '*'
    409                                         continue
    410                                 elif (vartype == 'n'):
    411                                         defaults[varname] = 'n'
    412                                         continue
    413                                 elif (vartype == 'y/n'):
    414                                         if (default == None):
    415                                                 default = 'y'
    416                                                 defaults[varname] = default
    417                                         options.append("  <%s> %s " % (yes_no(default), name))
    418                                 elif (vartype == 'n/y'):
    419                                         if (default == None):
    420                                                 default = 'n'
    421                                                 defaults[varname] = default
    422                                         options.append("  <%s> %s " % (yes_no(default), name))
    423                                 else:
    424                                         raise RuntimeError("Unknown variable type: %s" % vartype)
     507                                        value = config[varname]
     508                               
     509                                if not rule_value_is_valid(rule, value):
     510                                        value = None
     511
     512                                default = rule_get_default(rule)
     513                                if default != None:
     514                                        value = default
     515                                        config[varname] = default
     516
     517                                option = rule_get_option(rule, value)
     518                                if option != None:
     519                                        options.append(option)
    425520                               
    426521                                opt2row[cnt] = (varname, vartype, name, choices)
     
    433528                        (button, value) = xtui.choice_window(screen, 'HelenOS configuration', 'Choose configuration option', options, position)
    434529                       
    435                         if (button == 'cancel'):
     530                        if button == 'cancel':
    436531                                return 'Configuration canceled'
    437532                       
    438                         if (button == 'done'):
    439                                 if (check_choices(defaults, ask_names)):
     533                        if button == 'done':
     534                                if (infer_verify_choices(config, rules)):
    440535                                        break
    441536                                else:
     
    443538                                        continue
    444539                       
    445                         if (value == 0):
    446                                 read_preconfigured(PRECONF, MAKEFILE, screen, defaults)
     540                        if value == 0:
     541                                load_presets(PRESETS_DIR, MAKEFILE, screen, config)
    447542                                position = 1
    448543                                continue
    449544                       
    450545                        position = None
    451                         if (not value in opt2row):
     546                        if not value in opt2row:
    452547                                raise RuntimeError("Error selecting value: %s" % value)
    453548                       
    454549                        (selname, seltype, name, choices) = opt2row[value]
    455550                       
    456                         if (not selname in defaults):
    457                                         default = None
     551                        if not selname in config:
     552                                value = None
    458553                        else:
    459                                 default = defaults[selname]
    460                        
    461                         if (seltype == 'choice'):
    462                                 defaults[selname] = subchoice(screen, name, choices, default)
    463                         elif ((seltype == 'y/n') or (seltype == 'n/y')):
    464                                 if (defaults[selname] == 'y'):
    465                                         defaults[selname] = 'n'
     554                                value = config[selname]
     555                       
     556                        if seltype == 'choice':
     557                                config[selname] = subchoice(screen, name, choices, value)
     558                        elif (seltype == 'y/n') or (seltype == 'n/y'):
     559                                if config[selname] == 'y':
     560                                        config[selname] = 'n'
    466561                                else:
    467                                         defaults[selname] = 'y'
     562                                        config[selname] = 'y'
    468563        finally:
    469564                xtui.screen_done(screen)
    470565       
    471         create_output(MAKEFILE, MACROS, defaults, ask_names)
     566        create_output(MAKEFILE, MACROS, config, rules)
    472567        return 0
    473568
  • uspace/Makefile

    r4144630 r45e9cc6  
    118118        DIRS += drv/ns8250
    119119        DIRS += drv/uhci
     120        DIRS += drv/usbhub
    120121        DIRS += drv/usbkbd
    121122endif
  • uspace/drv/uhci/Makefile

    r4144630 r45e9cc6  
    3333
    3434SOURCES = \
    35         main.c
     35        main.c \
     36        transfers.c
    3637
    3738include $(USPACE_PREFIX)/Makefile.common
  • uspace/drv/uhci/main.c

    r4144630 r45e9cc6  
    2828#include <usb/hcdhubd.h>
    2929#include <errno.h>
     30#include "uhci.h"
    3031
    31 static int enqueue_transfer_out(usb_hc_device_t *hc,
    32     usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,
    33     void *buffer, size_t size,
    34     usb_hcd_transfer_callback_out_t callback, void *arg)
    35 {
    36         printf("UHCI: transfer OUT [%d.%d (%s); %u]\n",
    37             dev->address, endpoint->endpoint,
    38             usb_str_transfer_type(endpoint->transfer_type),
    39             size);
    40         return ENOTSUP;
    41 }
    42 
    43 static int enqueue_transfer_setup(usb_hc_device_t *hc,
    44     usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,
    45     void *buffer, size_t size,
    46     usb_hcd_transfer_callback_out_t callback, void *arg)
    47 {
    48         printf("UHCI: transfer SETUP [%d.%d (%s); %u]\n",
    49             dev->address, endpoint->endpoint,
    50             usb_str_transfer_type(endpoint->transfer_type),
    51             size);
    52         return ENOTSUP;
    53 }
    54 
    55 static int enqueue_transfer_in(usb_hc_device_t *hc,
    56     usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,
    57     void *buffer, size_t size,
    58     usb_hcd_transfer_callback_in_t callback, void *arg)
    59 {
    60         printf("UHCI: transfer IN [%d.%d (%s); %u]\n",
    61             dev->address, endpoint->endpoint,
    62             usb_str_transfer_type(endpoint->transfer_type),
    63             size);
    64         return ENOTSUP;
    65 }
    66 
    67 static usb_hcd_transfer_ops_t uhci_transfer_ops = {
    68         .transfer_out = enqueue_transfer_out,
    69         .transfer_in = enqueue_transfer_in,
    70         .transfer_setup = enqueue_transfer_setup
     32static device_ops_t uhci_ops = {
     33        .interfaces[USBHC_DEV_IFACE] = &uhci_iface,
    7134};
    7235
    73 static int uhci_add_hc(usb_hc_device_t *device)
     36static int uhci_add_device(device_t *device)
    7437{
    75         device->transfer_ops = &uhci_transfer_ops;
     38        device->ops = &uhci_ops;
    7639
    7740        /*
    7841         * We need to announce the presence of our root hub.
    79          * Commented out until the problem which causes the whole task to
    80          * block is solved.
    8142         */
    82         //usb_hcd_add_root_hub(device);
     43        usb_hcd_add_root_hub(device);
    8344
    8445        return EOK;
    8546}
    8647
    87 usb_hc_driver_t uhci_driver = {
    88         .name = "uhci",
    89         .add_hc = uhci_add_hc
     48static driver_ops_t uhci_driver_ops = {
     49        .add_device = uhci_add_device,
     50};
     51
     52static driver_t uhci_driver = {
     53        .name = NAME,
     54        .driver_ops = &uhci_driver_ops
    9055};
    9156
     
    9560         * Do some global initializations.
    9661         */
     62        sleep(5);
    9763
    98         return usb_hcd_main(&uhci_driver);
     64        return driver_main(&uhci_driver);
    9965}
  • uspace/drv/uhci/uhci.ma

    r4144630 r45e9cc6  
    1110 pci/ven=8086&dev=7020
    2 10 usb&hc=uhci
    3 10 usb&hc=uhci&hub
     2
  • uspace/drv/usbhub/utils.c

    r4144630 r45e9cc6  
    3333 * @brief Hub driver.
    3434 */
    35 #include <usb/hcdhubd.h>
     35#include <driver.h>
    3636#include <usb/devreq.h>
    3737#include <usbhc_iface.h>
     38#include <usb/usbdrv.h>
    3839#include <usb/descriptor.h>
    3940#include <driver.h>
     
    4142#include <errno.h>
    4243#include <usb/classes/hub.h>
    43 #include "hcdhubd_private.h"
     44#include "usbhub.h"
    4445
    4546static void check_hub_changes(void);
     
    108109//*********************************************
    109110
    110 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address);
    111 
    112111usb_hcd_hub_info_t * usb_create_hub_info(device_t * device) {
    113112        usb_hcd_hub_info_t* result = (usb_hcd_hub_info_t*) malloc(sizeof (usb_hcd_hub_info_t));
    114         //get parent device
    115         device_t * my_hcd = device;
    116         while (my_hcd->parent)
    117                 my_hcd = my_hcd->parent;
    118         //dev->
    119         printf("[hcdhubd]%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);
    120         //we add the hub into the first hc
    121         //link_t *link_hc = hc_list.next;
    122         //usb_hc_device_t *hc = list_get_instance(link_hc,
    123         //              usb_hc_device_t, link);
    124         //must get generic device info
    125 
    126113
    127114        return result;
     
    134121 */
    135122int usb_add_hub_device(device_t *dev) {
    136         //usb_hc_device_t *hc = list_get_instance(hc_list.next, usb_hc_device_t, link);
    137         assert(dev->parent);
    138         usb_hc_device_t *hc = (usb_hc_device_t*)dev->parent->driver_data;
    139         usb_address_t addr =usb_use_free_address(hc);
    140         if(addr<0){
    141                 printf("[hcdhubd] ERROR: cannot find an address \n");
    142         }
    143         set_hub_address(hc, addr);
     123        printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle);
    144124
    145125        check_hub_changes();
     
    150130         * connected devices.
    151131         */
    152         //insert hub into list
    153         //find owner hcd
    154         device_t * my_hcd = dev;
    155         while (my_hcd->parent)
    156                 my_hcd = my_hcd->parent;
    157         //dev->
    158         printf("[hcdhubd]%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);
    159         my_hcd = dev;
    160         while (my_hcd->parent)
    161                 my_hcd = my_hcd->parent;
    162         //dev->
    163 
    164         printf("[hcdhubd]%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);
    165132
    166133        //create the hub structure
    167134        usb_hcd_hub_info_t * hub_info = usb_create_hub_info(dev);
    168 
    169 
    170         //append into the list
    171         //we add the hub into the first hc
    172         list_append(&hub_info->link, &hc->hubs);
    173 
    174 
     135        (void)hub_info;
    175136
    176137        return EOK;
     
    178139}
    179140
    180 /** Sample usage of usb_hc_async functions.
    181  * This function sets hub address using standard SET_ADDRESS request.
    182  *
    183  * @warning This function shall be removed once you are familiar with
    184  * the usb_hc_ API.
    185  *
    186  * @param hc Host controller the hub belongs to.
    187  * @param address New hub address.
    188  */
    189 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address) {
    190         printf("[hcdhubd]%s: setting hub address to %d\n", hc->generic->name, address);
    191         usb_target_t target = {0, 0};
    192         usb_handle_t handle;
    193         int rc;
    194 
    195         usb_device_request_setup_packet_t setup_packet = {
    196                 .request_type = 0,
    197                 .request = USB_DEVREQ_SET_ADDRESS,
    198                 .index = 0,
    199                 .length = 0,
    200         };
    201         setup_packet.value = address;
    202 
    203         rc = usb_hc_async_control_write_setup(hc, target,
    204                         &setup_packet, sizeof (setup_packet), &handle);
    205         if (rc != EOK) {
    206                 return;
    207         }
    208 
    209         rc = usb_hc_async_wait_for(handle);
    210         if (rc != EOK) {
    211                 return;
    212         }
    213 
    214         rc = usb_hc_async_control_write_status(hc, target, &handle);
    215         if (rc != EOK) {
    216                 return;
    217         }
    218 
    219         rc = usb_hc_async_wait_for(handle);
    220         if (rc != EOK) {
    221                 return;
    222         }
    223 
    224         printf("[hcdhubd]%s: hub address changed successfully to %d\n",
    225                         hc->generic->name, address);
    226 }
    227141
    228142/** Check changes on all known hubs.
     
    230144static void check_hub_changes(void) {
    231145        /*
    232          * Iterate through all HCs.
     146         * Iterate through all hubs.
    233147         */
    234         link_t *link_hc;
    235         for (link_hc = hc_list.next;
    236                         link_hc != &hc_list;
    237                         link_hc = link_hc->next) {
    238                 usb_hc_device_t *hc = list_get_instance(link_hc,
    239                                 usb_hc_device_t, link);
    240                 /*
    241                  * Iterate through all their hubs.
    242                  */
    243                 link_t *link_hub;
    244                 for (link_hub = hc->hubs.next;
    245                                 link_hub != &hc->hubs;
    246                                 link_hub = link_hub->next) {
    247                         usb_hcd_hub_info_t *hub = list_get_instance(link_hub,
    248                                         usb_hcd_hub_info_t, link);
    249 
    250                         /*
    251                          * Check status change pipe of this hub.
    252                          */
    253                         usb_target_t target = {
    254                                 .address = hub->device->address,
    255                                 .endpoint = 1
    256                         };
    257 
    258                         // FIXME: count properly
    259                         size_t byte_length = (hub->port_count / 8) + 1;
    260 
    261                         void *change_bitmap = malloc(byte_length);
    262                         size_t actual_size;
    263                         usb_handle_t handle;
    264 
    265                         /*
    266                          * Send the request.
    267                          * FIXME: check returned value for possible errors
    268                          */
    269                         usb_hc_async_interrupt_in(hc, target,
    270                                         change_bitmap, byte_length, &actual_size,
    271                                         &handle);
    272 
    273                         usb_hc_async_wait_for(handle);
    274 
    275                         /*
    276                          * TODO: handle the changes.
    277                          */
     148        for (; false; ) {
     149                /*
     150                 * Check status change pipe of this hub.
     151                 */
     152                usb_target_t target = {
     153                        .address = 5,
     154                        .endpoint = 1
     155                };
     156
     157                size_t port_count = 7;
     158
     159                /*
     160                 * Connect to respective HC.
     161                 */
     162                int hc = usb_drv_hc_connect(NULL, 0);
     163                if (hc < 0) {
     164                        continue;
    278165                }
     166
     167                // FIXME: count properly
     168                size_t byte_length = (port_count / 8) + 1;
     169
     170                void *change_bitmap = malloc(byte_length);
     171                size_t actual_size;
     172                usb_handle_t handle;
     173
     174                /*
     175                 * Send the request.
     176                 * FIXME: check returned value for possible errors
     177                 */
     178                usb_drv_async_interrupt_in(hc, target,
     179                                change_bitmap, byte_length, &actual_size,
     180                                &handle);
     181
     182                usb_drv_async_wait_for(handle);
     183
     184                /*
     185                 * TODO: handle the changes.
     186                 */
     187
     188                /*
     189                 * WARNING: sample code, will not work out of the box.
     190                 * And does not contain code for checking for errors.
     191                 */
     192#if 0
     193                /*
     194                 * Before opening the port, we must acquire the default
     195                 * address.
     196                 */
     197                usb_drv_reserve_default_address(hc);
     198
     199                usb_address_t new_device_address = usb_drv_request_address(hc);
     200
     201                // TODO: open the port
     202
     203                // TODO: send request for setting address to new_device_address
     204
     205                /*
     206                 * Once new address is set, we can release the default
     207                 * address.
     208                 */
     209                usb_drv_release_default_address(hc);
     210
     211                /*
     212                 * Obtain descriptors and create match ids for devman.
     213                 */
     214
     215                // TODO: get device descriptors
     216
     217                // TODO: create match ids
     218
     219                // TODO: add child device
     220
     221                // child_device_register sets the device handle
     222                // TODO: store it here
     223                devman_handle_t new_device_handle = 0;
     224
     225                /*
     226                 * Inform the HC that the new device has devman handle
     227                 * assigned.
     228                 */
     229                usb_drv_bind_address(hc, new_device_address, new_device_handle);
     230
     231                /*
     232                 * That's all.
     233                 */
     234#endif
     235
     236
     237                /*
     238                 * Hang-up the HC-connected phone.
     239                 */
     240                ipc_hangup(hc);
    279241        }
    280242}
  • uspace/drv/vhc/Makefile

    r4144630 r45e9cc6  
    3939
    4040SOURCES = \
     41        addrmgm.c \
    4142        conndev.c \
    4243        connhost.c \
  • uspace/drv/vhc/conn.h

    r4144630 r45e9cc6  
    3838#include <usb/usb.h>
    3939#include <usb/hcdhubd.h>
     40#include <usbhc_iface.h>
    4041#include "vhcd.h"
    4142#include "devices.h"
     
    4445
    4546usb_hcd_transfer_ops_t vhc_transfer_ops;
     47usbhc_iface_t vhc_iface;
     48
     49void address_init(void);
     50int reserve_default_address(device_t *);
     51int release_default_address(device_t *);
     52int request_address(device_t *, usb_address_t *);
     53int release_address(device_t *, usb_address_t);
     54int bind_address(device_t *, usb_address_t, devman_handle_t);
     55
     56int tell_address(device_t *, devman_handle_t, usb_address_t *);
    4657
    4758void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);
  • uspace/drv/vhc/connhost.c

    r4144630 r45e9cc6  
    4343typedef struct {
    4444        usb_direction_t direction;
    45         usb_hcd_transfer_callback_out_t out_callback;
    46         usb_hcd_transfer_callback_in_t in_callback;
    47         usb_hc_device_t *hc;
     45        usbhc_iface_transfer_out_callback_t out_callback;
     46        usbhc_iface_transfer_in_callback_t in_callback;
     47        device_t *dev;
    4848        void *arg;
    4949} transfer_info_t;
     
    5656        switch (transfer->direction) {
    5757                case USB_DIRECTION_IN:
    58                         transfer->in_callback(transfer->hc,
     58                        transfer->in_callback(transfer->dev,
    5959                            size, outcome,
    6060                            transfer->arg);
    6161                        break;
    6262                case USB_DIRECTION_OUT:
    63                         transfer->out_callback(transfer->hc,
     63                        transfer->out_callback(transfer->dev,
    6464                            outcome,
    6565                            transfer->arg);
     
    7373}
    7474
    75 static transfer_info_t *create_transfer_info(usb_hc_device_t *hc,
     75static transfer_info_t *create_transfer_info(device_t *dev,
    7676    usb_direction_t direction, void *arg)
    7777{
     
    8282        transfer->out_callback = NULL;
    8383        transfer->arg = arg;
    84         transfer->hc = hc;
     84        transfer->dev = dev;
    8585
    8686        return transfer;
    8787}
    8888
    89 static int enqueue_transfer_out(usb_hc_device_t *hc,
    90     usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,
     89static int enqueue_transfer_out(device_t *dev,
     90    usb_target_t target, usb_transfer_type_t transfer_type,
    9191    void *buffer, size_t size,
    92     usb_hcd_transfer_callback_out_t callback, void *arg)
     92    usbhc_iface_transfer_out_callback_t callback, void *arg)
    9393{
    9494        printf(NAME ": transfer OUT [%d.%d (%s); %u]\n",
    95             dev->address, endpoint->endpoint,
    96             usb_str_transfer_type(endpoint->transfer_type),
     95            target.address, target.endpoint,
     96            usb_str_transfer_type(transfer_type),
    9797            size);
    9898
    9999        transfer_info_t *transfer
    100             = create_transfer_info(hc, USB_DIRECTION_OUT, arg);
     100            = create_transfer_info(dev, USB_DIRECTION_OUT, arg);
    101101        transfer->out_callback = callback;
    102 
    103         usb_target_t target = {
    104                 .address = dev->address,
    105                 .endpoint = endpoint->endpoint
    106         };
    107102
    108103        hc_add_transaction_to_device(false, target, buffer, size,
     
    112107}
    113108
    114 static int enqueue_transfer_setup(usb_hc_device_t *hc,
    115     usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,
     109static int enqueue_transfer_setup(device_t *dev,
     110    usb_target_t target, usb_transfer_type_t transfer_type,
    116111    void *buffer, size_t size,
    117     usb_hcd_transfer_callback_out_t callback, void *arg)
     112    usbhc_iface_transfer_out_callback_t callback, void *arg)
    118113{
    119114        printf(NAME ": transfer SETUP [%d.%d (%s); %u]\n",
    120             dev->address, endpoint->endpoint,
    121             usb_str_transfer_type(endpoint->transfer_type),
     115            target.address, target.endpoint,
     116            usb_str_transfer_type(transfer_type),
    122117            size);
    123118
    124119        transfer_info_t *transfer
    125             = create_transfer_info(hc, USB_DIRECTION_OUT, arg);
     120            = create_transfer_info(dev, USB_DIRECTION_OUT, arg);
    126121        transfer->out_callback = callback;
    127 
    128         usb_target_t target = {
    129                 .address = dev->address,
    130                 .endpoint = endpoint->endpoint
    131         };
    132122
    133123        hc_add_transaction_to_device(true, target, buffer, size,
     
    137127}
    138128
    139 static int enqueue_transfer_in(usb_hc_device_t *hc,
    140     usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,
     129static int enqueue_transfer_in(device_t *dev,
     130    usb_target_t target, usb_transfer_type_t transfer_type,
    141131    void *buffer, size_t size,
    142     usb_hcd_transfer_callback_in_t callback, void *arg)
     132    usbhc_iface_transfer_in_callback_t callback, void *arg)
    143133{
    144134        printf(NAME ": transfer IN [%d.%d (%s); %u]\n",
    145             dev->address, endpoint->endpoint,
    146             usb_str_transfer_type(endpoint->transfer_type),
     135            target.address, target.endpoint,
     136            usb_str_transfer_type(transfer_type),
    147137            size);
    148138
    149139        transfer_info_t *transfer
    150             = create_transfer_info(hc, USB_DIRECTION_IN, arg);
     140            = create_transfer_info(dev, USB_DIRECTION_IN, arg);
    151141        transfer->in_callback = callback;
    152 
    153         usb_target_t target = {
    154                 .address = dev->address,
    155                 .endpoint = endpoint->endpoint
    156         };
    157142
    158143        hc_add_transaction_from_device(target, buffer, size,
     
    163148
    164149
    165 usb_hcd_transfer_ops_t vhc_transfer_ops = {
    166         .transfer_out = enqueue_transfer_out,
    167         .transfer_in = enqueue_transfer_in,
    168         .transfer_setup = enqueue_transfer_setup
     150static int interrupt_out(device_t *dev, usb_target_t target,
     151    void *data, size_t size,
     152    usbhc_iface_transfer_out_callback_t callback, void *arg)
     153{
     154        return enqueue_transfer_out(dev, target, USB_TRANSFER_INTERRUPT,
     155            data, size,
     156            callback, arg);
     157}
     158
     159static int interrupt_in(device_t *dev, usb_target_t target,
     160    void *data, size_t size,
     161    usbhc_iface_transfer_in_callback_t callback, void *arg)
     162{
     163        return enqueue_transfer_in(dev, target, USB_TRANSFER_INTERRUPT,
     164            data, size,
     165            callback, arg);
     166}
     167
     168static int control_write_setup(device_t *dev, usb_target_t target,
     169    void *data, size_t size,
     170    usbhc_iface_transfer_out_callback_t callback, void *arg)
     171{
     172        return enqueue_transfer_setup(dev, target, USB_TRANSFER_CONTROL,
     173            data, size,
     174            callback, arg);
     175}
     176
     177static int control_write_data(device_t *dev, usb_target_t target,
     178    void *data, size_t size,
     179    usbhc_iface_transfer_out_callback_t callback, void *arg)
     180{
     181        return enqueue_transfer_out(dev, target, USB_TRANSFER_CONTROL,
     182            data, size,
     183            callback, arg);
     184}
     185
     186static int control_write_status(device_t *dev, usb_target_t target,
     187    usbhc_iface_transfer_in_callback_t callback, void *arg)
     188{
     189        return enqueue_transfer_in(dev, target, USB_TRANSFER_CONTROL,
     190            NULL, 0,
     191            callback, arg);
     192}
     193
     194static int control_read_setup(device_t *dev, usb_target_t target,
     195    void *data, size_t size,
     196    usbhc_iface_transfer_out_callback_t callback, void *arg)
     197{
     198        return enqueue_transfer_setup(dev, target, USB_TRANSFER_CONTROL,
     199            data, size,
     200            callback, arg);
     201}
     202
     203static int control_read_data(device_t *dev, usb_target_t target,
     204    void *data, size_t size,
     205    usbhc_iface_transfer_in_callback_t callback, void *arg)
     206{
     207        return enqueue_transfer_in(dev, target, USB_TRANSFER_CONTROL,
     208            data, size,
     209            callback, arg);
     210}
     211
     212static int control_read_status(device_t *dev, usb_target_t target,
     213    usbhc_iface_transfer_out_callback_t callback, void *arg)
     214{
     215        return enqueue_transfer_out(dev, target, USB_TRANSFER_CONTROL,
     216            NULL, 0,
     217            callback, arg);
     218}
     219
     220
     221usbhc_iface_t vhc_iface = {
     222        .tell_address = tell_address,
     223
     224        .reserve_default_address = reserve_default_address,
     225        .release_default_address = release_default_address,
     226        .request_address = request_address,
     227        .bind_address = bind_address,
     228        .release_address = release_address,
     229
     230        .interrupt_out = interrupt_out,
     231        .interrupt_in = interrupt_in,
     232
     233        .control_write_setup = control_write_setup,
     234        .control_write_data = control_write_data,
     235        .control_write_status = control_write_status,
     236
     237        .control_read_setup = control_read_setup,
     238        .control_read_data = control_read_data,
     239        .control_read_status = control_read_status
    169240};
    170241
  • uspace/drv/vhc/hcd.c

    r4144630 r45e9cc6  
    5252#include "conn.h"
    5353
     54static device_ops_t vhc_ops = {
     55        .interfaces[USBHC_DEV_IFACE] = &vhc_iface,
     56        .default_handler = default_connection_handler
     57};
    5458
    5559static int vhc_count = 0;
    56 static int vhc_add_device(usb_hc_device_t *dev)
     60static int vhc_add_device(device_t *dev)
    5761{
    5862        /*
     
    6569        vhc_count++;
    6670
    67         dev->transfer_ops = &vhc_transfer_ops;
    68         dev->generic->ops->default_handler = default_connection_handler;
     71        dev->ops = &vhc_ops;
     72
     73        /*
     74         * Initialize address management.
     75         */
     76        address_init();
    6977
    7078        /*
     
    7987}
    8088
    81 static usb_hc_driver_t vhc_driver = {
     89static driver_ops_t vhc_driver_ops = {
     90        .add_device = vhc_add_device,
     91};
     92
     93static driver_t vhc_driver = {
    8294        .name = NAME,
    83         .add_hc = &vhc_add_device
     95        .driver_ops = &vhc_driver_ops
    8496};
    8597
     
    114126        sleep(4);
    115127
    116         return usb_hcd_main(&vhc_driver);
     128        return driver_main(&vhc_driver);
    117129}
    118130
  • uspace/drv/vhc/vhc.ma

    r4144630 r45e9cc6  
    1110 usb&hc=vhc
    2 10 usb&hc=vhc&hub
     2
  • uspace/lib/block/libblock.c

    r4144630 r45e9cc6  
    6666        fibril_mutex_t lock;
    6767        size_t lblock_size;             /**< Logical block size. */
     68        unsigned blocks_cluster;        /**< Physical blocks per block_t */
    6869        unsigned block_count;           /**< Total number of blocks. */
    6970        unsigned blocks_cached;         /**< Number of cached blocks. */
     
    9091static int get_block_size(int dev_phone, size_t *bsize);
    9192static int get_num_blocks(int dev_phone, aoff64_t *nblocks);
     93static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba);
    9294
    9395static devcon_t *devcon_search(devmap_handle_t devmap_handle)
     
    259261{
    260262        block_t *b = hash_table_get_instance(item, block_t, hash_link);
    261         return b->boff == *key;
     263        return b->lba == *key;
    262264}
    263265
     
    292294        cache->mode = mode;
    293295
    294         /* No block size translation a.t.m. */
    295         assert(cache->lblock_size == devcon->pblock_size);
     296        /* Allow 1:1 or small-to-large block size translation */
     297        if (cache->lblock_size % devcon->pblock_size != 0)
     298                return ENOTSUP;
     299
     300        cache->blocks_cluster = cache->lblock_size / devcon->pblock_size;
    296301
    297302        if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 1,
     
    329334                if (b->dirty) {
    330335                        memcpy(devcon->comm_area, b->data, b->size);
    331                         rc = write_blocks(devcon, b->boff, 1);
     336                        rc = write_blocks(devcon, b->pba, cache->blocks_cluster);
    332337                        if (rc != EOK)
    333338                                return rc;
    334339                }
    335340
    336                 unsigned long key = b->boff;
     341                unsigned long key = b->lba;
    337342                hash_table_remove(&cache->block_hash, &key, 1);
    338343               
     
    375380 *                              block pointer on success.
    376381 * @param devmap_handle         Device handle of the block device.
    377  * @param boff                  Block offset.
     382 * @param ba                    Block address (logical).
    378383 * @param flags                 If BLOCK_FLAGS_NOREAD is specified, block_get()
    379384 *                              will not read the contents of the block from the
     
    382387 * @return                      EOK on success or a negative error code.
    383388 */
    384 int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t boff, int flags)
     389int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t ba, int flags)
    385390{
    386391        devcon_t *devcon;
     
    388393        block_t *b;
    389394        link_t *l;
    390         unsigned long key = boff;
     395        unsigned long key = ba;
    391396        int rc;
    392397       
     
    465470                                fibril_mutex_lock(&devcon->comm_area_lock);
    466471                                memcpy(devcon->comm_area, b->data, b->size);
    467                                 rc = write_blocks(devcon, b->boff, 1);
     472                                rc = write_blocks(devcon, b->pba,
     473                                    cache->blocks_cluster);
    468474                                fibril_mutex_unlock(&devcon->comm_area_lock);
    469475                                if (rc != EOK) {
     
    495501                         */
    496502                        list_remove(&b->free_link);
    497                         temp_key = b->boff;
     503                        temp_key = b->lba;
    498504                        hash_table_remove(&cache->block_hash, &temp_key, 1);
    499505                }
     
    502508                b->devmap_handle = devmap_handle;
    503509                b->size = cache->lblock_size;
    504                 b->boff = boff;
     510                b->lba = ba;
     511                b->pba = ba_ltop(devcon, b->lba);
    505512                hash_table_insert(&cache->block_hash, &key, &b->hash_link);
    506513
     
    519526                         */
    520527                        fibril_mutex_lock(&devcon->comm_area_lock);
    521                         rc = read_blocks(devcon, b->boff, 1);
     528                        rc = read_blocks(devcon, b->pba, cache->blocks_cluster);
    522529                        memcpy(b->data, devcon->comm_area, cache->lblock_size);
    523530                        fibril_mutex_unlock(&devcon->comm_area_lock);
     
    580587                fibril_mutex_lock(&devcon->comm_area_lock);
    581588                memcpy(devcon->comm_area, block->data, block->size);
    582                 rc = write_blocks(devcon, block->boff, 1);
     589                rc = write_blocks(devcon, block->pba, cache->blocks_cluster);
    583590                fibril_mutex_unlock(&devcon->comm_area_lock);
    584591                block->dirty = false;
     
    614621                         * Take the block out of the cache and free it.
    615622                         */
    616                         unsigned long key = block->boff;
     623                        unsigned long key = block->lba;
    617624                        hash_table_remove(&cache->block_hash, &key, 1);
    618625                        free(block);
     
    712719 *
    713720 * @param devmap_handle Device handle of the block device.
    714  * @param ba            Address of first block.
     721 * @param ba            Address of first block (physical).
    715722 * @param cnt           Number of blocks.
    716723 * @param src           Buffer for storing the data.
     
    740747 *
    741748 * @param devmap_handle Device handle of the block device.
    742  * @param ba            Address of first block.
     749 * @param ba            Address of first block (physical).
    743750 * @param cnt           Number of blocks.
    744751 * @param src           The data to be written.
     
    879886}
    880887
     888/** Convert logical block address to physical block address. */
     889static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba)
     890{
     891        assert(devcon->cache != NULL);
     892        return lba * devcon->cache->blocks_cluster;
     893}
     894
    881895/** @}
    882896 */
  • uspace/lib/block/libblock.h

    r4144630 r45e9cc6  
    7373        /** Handle of the device where the block resides. */
    7474        devmap_handle_t devmap_handle;
    75         /** Block offset on the block device. Counted in 'size'-byte blocks. */
    76         aoff64_t boff;
     75        /** Logical block address */
     76        aoff64_t lba;
     77        /** Physical block address */
     78        aoff64_t pba;
    7779        /** Size of the block. */
    7880        size_t size;
  • uspace/lib/drv/generic/remote_usbhc.c

    r4144630 r45e9cc6  
    5252static void remote_usbhc_control_read_data(device_t *, void *, ipc_callid_t, ipc_call_t *);
    5353static void remote_usbhc_control_read_status(device_t *, void *, ipc_callid_t, ipc_call_t *);
     54static void remote_usbhc_reserve_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
     55static void remote_usbhc_release_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
     56static void remote_usbhc_request_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
     57static void remote_usbhc_bind_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
     58static void remote_usbhc_release_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
    5459//static void remote_usbhc(device_t *, void *, ipc_callid_t, ipc_call_t *);
    5560
     
    5762static remote_iface_func_ptr_t remote_usbhc_iface_ops [] = {
    5863        remote_usbhc_get_address,
     64
    5965        remote_usbhc_get_buffer,
     66
     67        remote_usbhc_reserve_default_address,
     68        remote_usbhc_release_default_address,
     69
     70        remote_usbhc_request_address,
     71        remote_usbhc_bind_address,
     72        remote_usbhc_release_address,
     73
    6074        remote_usbhc_interrupt_out,
    6175        remote_usbhc_interrupt_in,
     76
    6277        remote_usbhc_control_write_setup,
    6378        remote_usbhc_control_write_data,
    6479        remote_usbhc_control_write_status,
     80
    6581        remote_usbhc_control_read_setup,
    6682        remote_usbhc_control_read_data,
     
    134150        free(trans->buffer);
    135151        free(trans);
     152}
     153
     154void remote_usbhc_reserve_default_address(device_t *device, void *iface,
     155    ipc_callid_t callid, ipc_call_t *call)
     156{
     157        usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
     158
     159        if (!usb_iface->reserve_default_address) {
     160                ipc_answer_0(callid, ENOTSUP);
     161                return;
     162        }
     163
     164        int rc = usb_iface->reserve_default_address(device);
     165
     166        ipc_answer_0(callid, rc);
     167}
     168
     169void remote_usbhc_release_default_address(device_t *device, void *iface,
     170    ipc_callid_t callid, ipc_call_t *call)
     171{
     172        usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
     173
     174        if (!usb_iface->release_default_address) {
     175                ipc_answer_0(callid, ENOTSUP);
     176                return;
     177        }
     178
     179        int rc = usb_iface->release_default_address(device);
     180
     181        ipc_answer_0(callid, rc);
     182}
     183
     184void remote_usbhc_request_address(device_t *device, void *iface,
     185    ipc_callid_t callid, ipc_call_t *call)
     186{
     187        usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
     188
     189        if (!usb_iface->request_address) {
     190                ipc_answer_0(callid, ENOTSUP);
     191                return;
     192        }
     193
     194        usb_address_t address;
     195        int rc = usb_iface->request_address(device, &address);
     196        if (rc != EOK) {
     197                ipc_answer_0(callid, rc);
     198        } else {
     199                ipc_answer_1(callid, EOK, (ipcarg_t) address);
     200        }
     201}
     202
     203void remote_usbhc_bind_address(device_t *device, void *iface,
     204    ipc_callid_t callid, ipc_call_t *call)
     205{
     206        usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
     207
     208        if (!usb_iface->bind_address) {
     209                ipc_answer_0(callid, ENOTSUP);
     210                return;
     211        }
     212
     213        usb_address_t address = (usb_address_t) IPC_GET_ARG1(*call);
     214        devman_handle_t handle = (devman_handle_t) IPC_GET_ARG2(*call);
     215
     216        int rc = usb_iface->bind_address(device, address, handle);
     217
     218        ipc_answer_0(callid, rc);
     219}
     220
     221void remote_usbhc_release_address(device_t *device, void *iface,
     222    ipc_callid_t callid, ipc_call_t *call)
     223{
     224        usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
     225
     226        if (!usb_iface->release_address) {
     227                ipc_answer_0(callid, ENOTSUP);
     228                return;
     229        }
     230
     231        usb_address_t address = (usb_address_t) IPC_GET_ARG1(*call);
     232
     233        int rc = usb_iface->release_address(device, address);
     234
     235        ipc_answer_0(callid, rc);
    136236}
    137237
  • uspace/lib/drv/include/usbhc_iface.h

    r4144630 r45e9cc6  
    111111
    112112
     113        /** Reserve usage of default address.
     114         * This call informs the host controller that the caller will be
     115         * using default USB address. It is duty of the HC driver to ensure
     116         * that only single entity will have it reserved.
     117         * The address is returned via IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS.
     118         * The caller can start using the address after receiving EOK
     119         * answer.
     120         */
     121        IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS,
     122
     123        /** Release usage of default address.
     124         * @see IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS
     125         */
     126        IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS,
     127
     128        /** Asks for address assignment by host controller.
     129         * Answer:
     130         * - ELIMIT - host controller run out of address
     131         * - EOK - address assigned
     132         * Answer arguments:
     133         * - assigned address
     134         *
     135         * The address must be released by via IPC_M_USBHC_RELEASE_ADDRESS.
     136         */
     137        IPC_M_USBHC_REQUEST_ADDRESS,
     138
     139        /** Bind USB address with devman handle.
     140         * Parameters:
     141         * - USB address
     142         * - devman handle
     143         * Answer:
     144         * - EOK - address binded
     145         * - ENOENT - address is not in use
     146         */
     147        IPC_M_USBHC_BIND_ADDRESS,
     148
     149        /** Release address in use.
     150         * Arguments:
     151         * - address to be released
     152         * Answer:
     153         * - ENOENT - address not in use
     154         * - EPERM - trying to release default USB address
     155         */
     156        IPC_M_USBHC_RELEASE_ADDRESS,
     157
     158
    113159        /** Send interrupt data to device.
    114160         * See explanation at usb_iface_funcs_t (OUT transaction).
     
    183229typedef struct {
    184230        int (*tell_address)(device_t *, devman_handle_t, usb_address_t *);
     231
     232        int (*reserve_default_address)(device_t *);
     233        int (*release_default_address)(device_t *);
     234        int (*request_address)(device_t *, usb_address_t *);
     235        int (*bind_address)(device_t *, usb_address_t, devman_handle_t);
     236        int (*release_address)(device_t *, usb_address_t);
    185237
    186238        usbhc_iface_transfer_out_t interrupt_out;
  • uspace/lib/usb/Makefile

    r4144630 r45e9cc6  
    3535        src/hcdhubd.c \
    3636        src/hcdrv.c \
    37         src/hubdrv.c \
    3837        src/localdrv.c \
    3938        src/remotedrv.c \
  • uspace/lib/usb/include/usb/hcdhubd.h

    r4144630 r45e9cc6  
    166166
    167167int usb_hcd_main(usb_hc_driver_t *);
    168 int usb_hcd_add_root_hub(usb_hc_device_t *dev);
     168int usb_hcd_add_root_hub(device_t *dev);
    169169
    170170/**
     
    191191 */
    192192
     193device_t *usb_hc_connect(device_t *);
    193194
    194195int usb_hc_async_interrupt_out(usb_hc_device_t *, usb_target_t,
  • uspace/lib/usb/include/usb/usbdrv.h

    r4144630 r45e9cc6  
    4141int usb_drv_hc_connect(device_t *, unsigned int);
    4242
     43int usb_drv_reserve_default_address(int);
     44int usb_drv_release_default_address(int);
     45usb_address_t usb_drv_request_address(int);
     46int usb_drv_bind_address(int, usb_address_t, devman_handle_t);
     47int usb_drv_release_address(int, usb_address_t);
     48
    4349usb_address_t usb_drv_get_my_address(int, device_t *);
    4450
  • uspace/lib/usb/src/hcdhubd.c

    r4144630 r45e9cc6  
    5151 */
    5252static int add_device(device_t *dev) {
    53         bool is_hc = str_cmp(dev->name, USB_HUB_DEVICE_NAME) != 0;
    54         printf("%s: add_device(name=\"%s\")\n", hc_driver->name, dev->name);
    55 
    56         if (is_hc) {
    57                 /*
    58                  * We are the HC itself.
    59                  */
    60                 return usb_add_hc_device(dev);
    61         } else {
    62                 /*
    63                  * We are some (maybe deeply nested) hub.
    64                  * Thus, assign our own operations and explore already
    65                  * connected devices.
    66                  */
    67                 return usb_add_hub_device(dev);
    68         }
     53        return ENOTSUP;
    6954}
    7055
     
    10590 * @return Error code.
    10691 */
    107 int usb_hcd_add_root_hub(usb_hc_device_t *dev) {
     92int usb_hcd_add_root_hub(device_t *dev)
     93{
    10894        char *id;
    109         int rc = asprintf(&id, "usb&hc=%s&hub", dev->generic->name);
     95        int rc = asprintf(&id, "usb&hub");
    11096        if (rc <= 0) {
    11197                return rc;
    11298        }
    11399
    114         rc = usb_hc_add_child_device(dev->generic, USB_HUB_DEVICE_NAME, id, true);
     100        rc = usb_hc_add_child_device(dev, USB_HUB_DEVICE_NAME, id, true);
    115101        if (rc != EOK) {
    116102                free(id);
     
    133119        int rc;
    134120
     121        async_usleep(1000);
     122
    135123        device_t *child = create_device();
    136124        match_id_t *match_id = NULL;
     
    196184        printf("%s: about to add child device `%s' (%s)\n", hc_driver->name,
    197185                        name, match_id);
     186
     187        /*
     188         * Seems that creating fibril which postpones the action
     189         * is the best solution.
     190         */
     191        create_fibril = true;
    198192
    199193        struct child_device_info *child_info
  • uspace/lib/usb/src/hcdhubd_private.h

    r4144630 r45e9cc6  
    4646usb_address_t usb_get_address_by_handle(devman_handle_t);
    4747int usb_add_hc_device(device_t *);
    48 int usb_add_hub_device(device_t *);
    4948
    5049/** lowest allowed usb address */
  • uspace/lib/usb/src/hcdrv.c

    r4144630 r45e9cc6  
    4747LIST_INITIALIZE(hc_list);
    4848
     49/* Fake driver to have the name item initialized. */
     50static usb_hc_driver_t hc_driver_fake = {
     51        .name = "HCD",
     52};
     53
    4954/** Our HC driver. */
    50 usb_hc_driver_t *hc_driver = NULL;
     55usb_hc_driver_t *hc_driver = &hc_driver_fake;
    5156
    5257int usb_lowest_address = 1;
     
    8691int usb_add_hc_device(device_t *dev)
    8792{
     93        return ENOTSUP;
    8894        usb_hc_device_t *hc_dev = usb_hc_device_create(dev);
    8995
  • uspace/lib/usb/src/localdrv.c

    r4144630 r45e9cc6  
    3939#include <errno.h>
    4040
     41/** Find host controller when handled by current task.
     42 *
     43 * @param dev Device asking for connection.
     44 * @return Device structure corresponding to parent host controller.
     45 * @retval NULL Corresponding host controller not found.
     46 */
     47device_t *usb_hc_connect(device_t *dev)
     48{
     49        /*
     50         * FIXME: this will not work when some hub on the path is
     51         * not driven by the same task.
     52         */
     53        device_t *parent = dev;
     54        while (parent->parent != NULL) {
     55                parent = parent->parent;
     56        }
     57       
     58        if (dev == parent) {
     59                printf("FIXME in %s:%d encountered!\n", __FILE__, __LINE__);
     60                parent = NULL;
     61        }
     62
     63        return parent;
     64}
     65
    4166/** Information about pending transaction on HC. */
    4267typedef struct {
  • uspace/lib/usb/src/usbdrv.c

    r4144630 r45e9cc6  
    5555/** Connect to host controller the device is physically attached to.
    5656 *
    57  * @param handle Device handle.
     57 * @param dev Device asking for connection.
    5858 * @param flags Connection flags (blocking connection).
    5959 * @return Phone to corresponding HC or error code.
     
    9898
    9999        return (usb_address_t) address;
     100}
     101
     102/** Tell HC to reserve default address.
     103 *
     104 * @param phone Open phone to host controller driver.
     105 * @return Error code.
     106 */
     107int usb_drv_reserve_default_address(int phone)
     108{
     109        return async_req_0_0(phone, IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS);
     110}
     111
     112/** Tell HC to release default address.
     113 *
     114 * @param phone Open phone to host controller driver.
     115 * @return Error code.
     116 */
     117int usb_drv_release_default_address(int phone)
     118{
     119        return async_req_0_0(phone, IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS);
     120}
     121
     122/** Ask HC for free address assignment.
     123 *
     124 * @param phone Open phone to host controller driver.
     125 * @return Assigned USB address or negative error code.
     126 */
     127usb_address_t usb_drv_request_address(int phone)
     128{
     129        ipcarg_t address;
     130        int rc = async_req_0_1(phone, IPC_M_USBHC_REQUEST_ADDRESS, &address);
     131        if (rc != EOK) {
     132                return rc;
     133        } else {
     134                return (usb_address_t) address;
     135        }
     136}
     137
     138/** Inform HC about binding address with devman handle.
     139 *
     140 * @param phone Open phone to host controller driver.
     141 * @param address Address to be binded.
     142 * @param handle Devman handle of the device.
     143 * @return Error code.
     144 */
     145int usb_drv_bind_address(int phone, usb_address_t address,
     146    devman_handle_t handle)
     147{
     148        int rc = async_req_2_0(phone, IPC_M_USBHC_BIND_ADDRESS,
     149            address, handle);
     150
     151        return rc;
     152}
     153
     154/** Inform HC about address release.
     155 *
     156 * @param phone Open phone to host controller driver.
     157 * @param address Address to be released.
     158 * @return Error code.
     159 */
     160int usb_drv_release_address(int phone, usb_address_t address)
     161{
     162        return async_req_1_0(phone, IPC_M_USBHC_RELEASE_ADDRESS, address);
    100163}
    101164
  • uspace/srv/bd/file_bd/file_bd.c

    r4144630 r45e9cc6  
    5656#define NAME "file_bd"
    5757
    58 static const size_t block_size = 512;
     58#define DEFAULT_BLOCK_SIZE 512
     59
     60static size_t block_size;
    5961static aoff64_t num_blocks;
    6062static FILE *img;
     
    6365static fibril_mutex_t dev_lock;
    6466
     67static void print_usage(void);
    6568static int file_bd_init(const char *fname);
    6669static void file_bd_connection(ipc_callid_t iid, ipc_call_t *icall);
     
    7174{
    7275        int rc;
     76        char *image_name;
     77        char *device_name;
    7378
    7479        printf(NAME ": File-backed block device driver\n");
    7580
    76         if (argc != 3) {
    77                 printf("Expected two arguments (image name, device name).\n");
     81        block_size = DEFAULT_BLOCK_SIZE;
     82
     83        ++argv; --argc;
     84        while (*argv != NULL && (*argv)[0] == '-') {
     85                /* Option */
     86                if (str_cmp(*argv, "-b") == 0) {
     87                        if (argc < 2) {
     88                                printf("Argument missing.\n");
     89                                print_usage();
     90                                return -1;
     91                        }
     92
     93                        rc = str_size_t(argv[1], NULL, 10, true, &block_size);
     94                        if (rc != EOK || block_size == 0) {
     95                                printf("Invalid block size '%s'.\n", argv[1]);
     96                                print_usage();
     97                                return -1;
     98                        }
     99                        ++argv; --argc;
     100                } else {
     101                        printf("Invalid option '%s'.\n", *argv);
     102                        print_usage();
     103                        return -1;
     104                }
     105                ++argv; --argc;
     106        }
     107
     108        if (argc < 2) {
     109                printf("Missing arguments.\n");
     110                print_usage();
    78111                return -1;
    79112        }
    80113
    81         if (file_bd_init(argv[1]) != EOK)
     114        image_name = argv[0];
     115        device_name = argv[1];
     116
     117        if (file_bd_init(image_name) != EOK)
    82118                return -1;
    83119
    84         rc = devmap_device_register(argv[2], &devmap_handle);
     120        rc = devmap_device_register(device_name, &devmap_handle);
    85121        if (rc != EOK) {
    86122                devmap_hangup_phone(DEVMAP_DRIVER);
    87                 printf(NAME ": Unable to register device %s.\n",
    88                         argv[2]);
     123                printf(NAME ": Unable to register device '%s'.\n",
     124                        device_name);
    89125                return rc;
    90126        }
     
    96132        /* Not reached */
    97133        return 0;
     134}
     135
     136static void print_usage(void)
     137{
     138        printf("Usage: " NAME " [-b <block_size>] <image_file> <device_name>\n");
    98139}
    99140
Note: See TracChangeset for help on using the changeset viewer.