LCOV - code coverage report
Current view: top level - core/test - run-pci-quirk.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 19 27 70.4 %
Date: 2024-01-02 21:04:04 Functions: 2 6 33.3 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
       2                 :            : /*
       3                 :            :  * Copyright 2018 IBM Corp
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <assert.h>
       7                 :            : #include <stdint.h>
       8                 :            : #include <compiler.h>
       9                 :            : #include <stdbool.h>
      10                 :            : 
      11                 :            : /* Stubs for quirk_astbmc_vga() */
      12                 :            : 
      13                 :            : struct dt_property;
      14                 :            : struct dt_node;
      15                 :            : 
      16                 :            : static struct bmc_platform fake_bmc;
      17                 :            : const struct bmc_platform *bmc_platform = &fake_bmc;
      18                 :            : 
      19                 :          0 : static int ast_sio_is_enabled(void)
      20                 :            : {
      21                 :          0 :         return 0;
      22                 :            : }
      23                 :            : 
      24                 :          0 : static uint32_t ast_ahb_readl(uint32_t reg)
      25                 :            : {
      26                 :          0 :         return reg;
      27                 :            : }
      28                 :            : 
      29                 :          0 : static struct dt_property *__dt_add_property_cells(
      30                 :            :                 struct dt_node *node __unused, const char *name __unused,
      31                 :            :                 int count __unused, ...)
      32                 :            : {
      33                 :          0 :         return (void *)0;
      34                 :            : }
      35                 :            : 
      36                 :            : struct pci_device;
      37                 :            : struct pci_cfg_reg_filter;
      38                 :            : typedef int64_t (*pci_cfg_reg_func)(void *dev,
      39                 :            :                                     struct pci_cfg_reg_filter *pcrf,
      40                 :            :                                     uint32_t offset, uint32_t len,
      41                 :            :                                     uint32_t *data, bool write);
      42                 :            : 
      43                 :            : 
      44                 :          0 : static struct pci_cfg_reg_filter *pci_add_cfg_reg_filter(
      45                 :            :         struct pci_device *pd __unused,
      46                 :            :         uint32_t start __unused,
      47                 :            :         uint32_t len __unused,
      48                 :            :         uint32_t flags __unused,
      49                 :            :         pci_cfg_reg_func func __unused)
      50                 :            : {
      51                 :          0 :         return NULL;
      52                 :            : }
      53                 :            : 
      54                 :            : #include "../pci-quirk.c"
      55                 :            : 
      56                 :            : struct pci_device test_pd;
      57                 :            : int test_fixup_ran;
      58                 :            : 
      59                 :          1 : static void test_fixup(struct phb *phb __unused, struct pci_device *pd __unused)
      60                 :            : {
      61                 :          1 :         assert(PCI_VENDOR_ID(pd->vdid) == 0x1a03);
      62                 :          1 :         assert(PCI_DEVICE_ID(pd->vdid) == 0x2000);
      63                 :          1 :         test_fixup_ran = 1;
      64                 :          1 : }
      65                 :            : 
      66                 :            : /* Quirks are: {fixup function, vendor ID, (device ID or PCI_ANY_ID)} */
      67                 :            : static const struct pci_quirk test_quirk_table[] = {
      68                 :            :         /* ASPEED 2400 VGA device */
      69                 :            :         { 0x1a03, 0x2000, &test_fixup },
      70                 :            :         { 0, 0, NULL }
      71                 :            : };
      72                 :            : 
      73                 :            : #define PCI_COMPOSE_VDID(vendor, device) (((device) << 16) | (vendor))
      74                 :            : 
      75                 :          1 : int main(void)
      76                 :            : {
      77                 :            :         /* Unrecognised vendor and device ID */
      78                 :          1 :         test_pd.vdid = PCI_COMPOSE_VDID(0xabcd, 0xef01);
      79                 :          1 :         __pci_handle_quirk(NULL, &test_pd, test_quirk_table);
      80                 :          1 :         assert(test_fixup_ran == 0);
      81                 :            : 
      82                 :            :         /* Unrecognised vendor ID, matching device ID */
      83                 :          1 :         test_pd.vdid = PCI_COMPOSE_VDID(0xabcd, 0x2000);
      84                 :          1 :         __pci_handle_quirk(NULL, &test_pd, test_quirk_table);
      85                 :          1 :         assert(test_fixup_ran == 0);
      86                 :            : 
      87                 :            :         /* Matching vendor ID, unrecognised device ID */
      88                 :          1 :         test_pd.vdid = PCI_COMPOSE_VDID(0x1a03, 0xef01);
      89                 :          1 :         __pci_handle_quirk(NULL, &test_pd, test_quirk_table);
      90                 :          1 :         assert(test_fixup_ran == 0);
      91                 :            : 
      92                 :            :         /* Matching vendor and device ID */
      93                 :          1 :         test_pd.vdid = PCI_COMPOSE_VDID(0x1a03, 0x2000);
      94                 :          1 :         __pci_handle_quirk(NULL, &test_pd, test_quirk_table);
      95                 :          1 :         assert(test_fixup_ran == 1);
      96                 :            : 
      97                 :          1 :         return 0;
      98                 :            : }

Generated by: LCOV version 1.14