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 (2303B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  */
      7 
      8 #include <gmodule.h>
      9 #include <shbde.h>
     10 #include <shbde_iproc.h>
     11 #include "linux_shbde.h"
     12 
     13 /* Hardware abstractions for shared BDE functions */
     14 
     15 static unsigned short
     16 linux_pcic16_read(void *pci_dev, unsigned int addr)
     17 {
     18     u16 data = 0;
     19 
     20     pci_read_config_word((struct pci_dev *)pci_dev, addr, &data);
     21 
     22     return data;
     23 }
     24 
     25 static void
     26 linux_pcic16_write(void *pci_dev, unsigned int addr, unsigned short data)
     27 {
     28     pci_write_config_word((struct pci_dev *)pci_dev, addr, (u16)data);
     29 }
     30 
     31 static unsigned int
     32 linux_pcic32_read(void *pci_dev, unsigned int addr)
     33 {
     34     u32 data = 0;
     35 
     36     pci_read_config_dword((struct pci_dev *)pci_dev, addr, &data);
     37 
     38     return data;
     39 }
     40 
     41 static void
     42 linux_pcic32_write(void *pci_dev, unsigned int addr, unsigned int data)
     43 {
     44     pci_write_config_dword((struct pci_dev *)pci_dev, addr, (u32)data);
     45 }
     46 
     47 static unsigned int
     48 linux_io32_read(void *addr)
     49 {
     50     return *((volatile u32 *)addr);
     51 }
     52 
     53 static void
     54 linux_io32_write(void *addr, unsigned int data)
     55 {
     56     *((volatile u32 *)addr) = data;
     57 }
     58 
     59 static void
     60 linux_usleep(int usec)
     61 {
     62     udelay(usec);
     63 }
     64 
     65 
     66 /* To get the PCI parent device under linux, from only the device pointer */
     67 static void *
     68 linux_pci_parent_device_get(void *pci_dev)
     69 {
     70     return (void *)(((struct pci_dev *)pci_dev)->bus->self);
     71 }
     72 
     73 
     74 /*
     75  * Function:
     76  *      linux_shbde_hal_init
     77  * Purpose:
     78  *      Initialize hardware abstraction module for Linux kernel.
     79  * Parameters:
     80  *      shbde - pointer to uninitialized hardware abstraction module
     81  *      log_func - optional log output function
     82  * Returns:
     83  *      Always 0
     84  */
     85 int
     86 linux_shbde_hal_init(shbde_hal_t *shbde, shbde_log_func_t log_func)
     87 {
     88     memset(shbde, 0, sizeof(*shbde));
     89 
     90     shbde->log_func = log_func;
     91 
     92     shbde->pcic16_read = linux_pcic16_read;
     93     shbde->pcic16_write = linux_pcic16_write;
     94     shbde->pcic32_read = linux_pcic32_read;
     95     shbde->pcic32_write = linux_pcic32_write;
     96 
     97     shbde->io32_read = linux_io32_read;
     98     shbde->io32_write = linux_io32_write;
     99 
    100     shbde->usleep = linux_usleep;
    101 
    102     shbde->pci_parent_device_get = linux_pci_parent_device_get;
    103 
    104     return 0;
    105 }