openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

linux_shbde.c (2809B)


      1 /*
      2  * Copyright 2017 Broadcom
      3  * 
      4  * This program is free software; you can redistribute it and/or modify
      5  * it under the terms of the GNU General Public License, version 2, as
      6  * published by the Free Software Foundation (the "GPL").
      7  * 
      8  * This program is distributed in the hope that it will be useful, but
      9  * WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     11  * General Public License version 2 (GPLv2) for more details.
     12  * 
     13  * You should have received a copy of the GNU General Public License
     14  * version 2 (GPLv2) along with this source code.
     15  */
     16 /*
     17  * $Id: $
     18  * $Copyright: (c) 2014 Broadcom Corp.
     19  * All Rights Reserved.$
     20  *
     21  */
     22 
     23 #include <gmodule.h>
     24 #include <shbde.h>
     25 #include <shbde_iproc.h>
     26 #include "linux_shbde.h"
     27 
     28 /* Hardware abstractions for shared BDE functions */
     29 
     30 static unsigned short
     31 linux_pcic16_read(void *pci_dev, unsigned int addr)
     32 {
     33     u16 data = 0;
     34 
     35     pci_read_config_word((struct pci_dev *)pci_dev, addr, &data);
     36 
     37     return data;
     38 }
     39 
     40 static void
     41 linux_pcic16_write(void *pci_dev, unsigned int addr, unsigned short data)
     42 {
     43     pci_write_config_word((struct pci_dev *)pci_dev, addr, (u16)data);
     44 }
     45 
     46 static unsigned int
     47 linux_pcic32_read(void *pci_dev, unsigned int addr)
     48 {
     49     u32 data = 0;
     50 
     51     pci_read_config_dword((struct pci_dev *)pci_dev, addr, &data);
     52 
     53     return data;
     54 }
     55 
     56 static void
     57 linux_pcic32_write(void *pci_dev, unsigned int addr, unsigned int data)
     58 {
     59     pci_write_config_dword((struct pci_dev *)pci_dev, addr, (u32)data);
     60 }
     61 
     62 static unsigned int
     63 linux_io32_read(void *addr)
     64 {
     65     return *((volatile u32 *)addr);
     66 }
     67 
     68 static void
     69 linux_io32_write(void *addr, unsigned int data)
     70 {
     71     *((volatile u32 *)addr) = data;
     72 }
     73 
     74 static void
     75 linux_usleep(int usec)
     76 {
     77     udelay(usec);
     78 }
     79 
     80 
     81 /* To get the PCI parent device under linux, from only the device pointer */
     82 static void *
     83 linux_pci_parent_device_get(void *pci_dev)
     84 {
     85     return (void *)(((struct pci_dev *)pci_dev)->bus->self);
     86 }
     87 
     88 
     89 /*
     90  * Function:
     91  *      linux_shbde_hal_init
     92  * Purpose:
     93  *      Initialize hardware abstraction module for Linux kernel.
     94  * Parameters:
     95  *      shbde - pointer to uninitialized hardware abstraction module
     96  *      log_func - optional log output function
     97  * Returns:
     98  *      Always 0
     99  */
    100 int
    101 linux_shbde_hal_init(shbde_hal_t *shbde, shbde_log_func_t log_func)
    102 {
    103     memset(shbde, 0, sizeof(*shbde));
    104 
    105     shbde->log_func = log_func;
    106 
    107     shbde->pcic16_read = linux_pcic16_read;
    108     shbde->pcic16_write = linux_pcic16_write;
    109     shbde->pcic32_read = linux_pcic32_read;
    110     shbde->pcic32_write = linux_pcic32_write;
    111 
    112     shbde->io32_read = linux_io32_read;
    113     shbde->io32_write = linux_io32_write;
    114 
    115     shbde->usleep = linux_usleep;
    116 
    117     shbde->pci_parent_device_get = linux_pci_parent_device_get;
    118 
    119     return 0;
    120 }