Subversion Repositories HelenOS

Rev

Rev 4504 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2009 Jakub Jermar
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup fhc
  30.  * @{
  31.  */
  32.  
  33. /**
  34.  * @file    fhc.c
  35.  * @brief   FHC bus controller driver.
  36.  */
  37.  
  38. #include <ipc/ipc.h>
  39. #include <ipc/services.h>
  40. #include <ipc/bus.h>
  41. #include <ipc/ns.h>
  42. #include <sysinfo.h>
  43. #include <as.h>
  44. #include <ddi.h>
  45. #include <align.h>
  46. #include <bool.h>
  47. #include <errno.h>
  48. #include <async.h>
  49. #include <align.h>
  50. #include <async.h>
  51. #include <stdio.h>
  52. #include <ipc/devmap.h>
  53.  
  54. #define NAME "fhc"
  55.  
  56. #define FHC_UART_INR    0x39   
  57.  
  58. #define FHC_UART_IMAP   0x0
  59. #define FHC_UART_ICLR   0x4
  60.  
  61. static void *fhc_uart_phys;
  62. static volatile uint32_t *fhc_uart_virt;
  63. static size_t fhc_uart_size;
  64.  
  65. /** Handle one connection to fhc.
  66.  *
  67.  * @param iid       Hash of the request that opened the connection.
  68.  * @param icall     Call data of the request that opened the connection.
  69.  */
  70. static void fhc_connection(ipc_callid_t iid, ipc_call_t *icall)
  71. {
  72.     ipc_callid_t callid;
  73.     ipc_call_t call;
  74.  
  75.     /*
  76.      * Answer the first IPC_M_CONNECT_ME_TO call.
  77.      */
  78.     ipc_answer_0(iid, EOK);
  79.  
  80.     while (1) {
  81.         int inr;
  82.    
  83.         callid = async_get_call(&call);
  84.         switch (IPC_GET_METHOD(call)) {
  85.         case BUS_CLEAR_INTERRUPT:
  86.             inr = IPC_GET_ARG1(call);
  87.             switch (inr) {
  88.             case FHC_UART_INR:
  89.                 fhc_uart_virt[FHC_UART_ICLR] = 0;
  90.                 ipc_answer_0(callid, EOK);
  91.                 break;
  92.             default:
  93.                 ipc_answer_0(callid, ENOTSUP);
  94.                 break;
  95.             }
  96.             break;
  97.         default:
  98.             ipc_answer_0(callid, EINVAL);
  99.             break;
  100.         }
  101.     }
  102. }
  103.  
  104. /** Initialize the FHC driver.
  105.  *
  106.  * So far, the driver heavily depends on information provided by the kernel via
  107.  * sysinfo. In the future, there should be a standalone FHC driver.
  108.  */
  109. static bool fhc_init(void)
  110. {
  111.     ipcarg_t phonead;
  112.  
  113.     fhc_uart_size = sysinfo_value("fhc.uart.size");
  114.     fhc_uart_phys = (void *) sysinfo_value("fhc.uart.physical");
  115.    
  116.     if (!fhc_uart_size) {
  117.         printf(NAME ": no FHC UART registers found\n");
  118.         return false;
  119.     }
  120.  
  121.     fhc_uart_virt = as_get_mappable_page(fhc_uart_size);
  122.    
  123.     int flags = AS_AREA_READ | AS_AREA_WRITE;
  124.     int retval = physmem_map(fhc_uart_phys, (void *) fhc_uart_virt,
  125.         ALIGN_UP(fhc_uart_size, PAGE_SIZE) >> PAGE_WIDTH, flags);
  126.    
  127.     if (retval < 0) {
  128.         printf(NAME ": Error mapping FHC UART registers\n");
  129.         return false;
  130.     }
  131.    
  132.     printf(NAME ": FHC UART registers at %p, %d bytes\n", fhc_uart_phys,
  133.         fhc_uart_size);
  134.  
  135.     async_set_client_connection(fhc_connection);
  136.     ipc_connect_to_me(PHONE_NS, SERVICE_FHC, 0, 0, &phonead);
  137.    
  138.     return true;
  139. }
  140.  
  141. int main(int argc, char **argv)
  142. {
  143.     printf(NAME ": HelenOS FHC bus controller driver\n");
  144.    
  145.     if (!fhc_init())
  146.         return -1;
  147.    
  148.     printf(NAME ": Accepting connections\n");
  149.     async_manager();
  150.  
  151.     /* Never reached */
  152.     return 0;
  153. }
  154.  
  155. /**
  156.  * @}
  157.  */
  158.