⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 amcclib.c

📁 详细介绍了一篇关于pci开发的接口芯片
💻 C
📖 第 1 页 / 共 4 页
字号:

   /* First check if CARRY FLAG Set, if so, error has occurred */
   if ((flags & CARRY_FLAG) == 0) {

      /* Get Return code from BIOS */
      ret_status = HIGH_BYTE(ax);
      if (ret_status == SUCCESSFUL) {

         /* Assign Bus Number, Device & Function if successful */
         if (bus_number != NULL) {
            *bus_number = HIGH_BYTE(bx);
         }
         if (device_and_function != NULL) {
            *device_and_function = LOW_BYTE(bx);
         }
      }
   }
   else {
     ret_status = NOT_SUCCESSFUL;
   }

   return (ret_status);
}

/****************************************************************************/
/*                                                                          */
/*  FIND_PCI_CLASS_CODE                                                     */
/*                                                                          */
/* Purpose: Returns the location of PCI devices that have a specific Class  */
/*          Code.                                                           */
/*                                                                          */
/* Inputs:                                                                  */
/*                                                                          */
/*    word class_code                                                       */
/*       Class Code of PCI device desired                                   */
/*                                                                          */
/*    word index                                                            */
/*       Device number to find (0 - (N-1))                                  */
/*                                                                          */
/* Outputs:                                                                 */
/*                                                                          */
/*    byte *bus_number                                                      */
/*       PCI Bus in which this device is found                              */
/*                                                                          */
/*    byte *device_and_function                                             */
/*       Device Number in upper 5 bits, Function Number in lower 3 bits     */
/*                                                                          */
/*    Return Value - Indicates presence of device                           */
/*       SUCCESSFUL - Device found                                          */
/*       NOT_SUCCESSFUL - BIOS error                                        */
/*       DEVICE_NOT_FOUND - Device not found                                */
/*                                                                          */
/****************************************************************************/

int find_pci_class_code(dword class_code,
                    word index,
                    byte *bus_number,
                    byte *device_and_function)
{
   int ret_status;     /* Function Return Status */
   word ax, bx, flags; /* Temporary variables to hold register values */
   SWI_REGS regs;

   /* Load entry registers for PCI BIOS */

   regs.ecx = class_code;
   regs.esi = index;
   regs.eax = (PCI_FUNCTION_ID << 8) | FIND_PCI_CLASS_CODE;

   /* Call PCI BIOS Int 1Ah interface */
   _dx_real_int(0x1a, &regs);

   /* Save registers before overwritten by compiler usage of registers */
   ax = regs.eax & 0xffff;
   bx = regs.ebx & 0xffff;
   flags = regs.flags;

   /* First check if CARRY FLAG Set, if so, error has occurred */
   if ((flags & CARRY_FLAG) == 0) {

      /* Get Return code from BIOS */
      ret_status = HIGH_BYTE(ax);
      if (ret_status == SUCCESSFUL) {

         /* Assign Bus Number, Device & Function if successful */
         if (bus_number != NULL) {
            *bus_number = HIGH_BYTE(bx);
         }
         if (device_and_function != NULL) {
            *device_and_function = LOW_BYTE(bx);
         }
      }
   }
   else {
      ret_status = NOT_SUCCESSFUL;
   }

   return (ret_status);
}

/****************************************************************************/
/*                                                                          */
/*  GENERATE_SPECIAL_CYCLE                                                  */
/*                                                                          */
/* Purpose: Generates a PCI special cycle                                   */
/*                                                                          */
/* Inputs:                                                                  */
/*                                                                          */
/*    byte bus_number                                                       */
/*       PCI bus to generate cycle on                                       */
/*                                                                          */
/*    dword special_cycle_data                                              */
/*       Special Cycle Data to be generated                                 */
/*                                                                          */
/* Outputs:                                                                 */
/*                                                                          */
/*    Return Value - Indicates presence of device                           */
/*       SUCCESSFUL - Device found                                          */
/*       DEVICE_NOT_FOUND - Device not found                                */
/*                                                                          */
/****************************************************************************/

int generate_special_cycle(byte bus_number,
                           dword special_cycle_data)
{
   int ret_status; /* Function Return Status */
   word ax, flags; /* Temporary variables to hold register values */
   SWI_REGS regs;

   /* Load entry registers for PCI BIOS */
   regs.ebx = (bus_number << 8);
   regs.edx = special_cycle_data;
   regs.eax = (PCI_FUNCTION_ID << 8) | FIND_PCI_CLASS_CODE;

   /* Call PCI BIOS Int 1Ah interface */
   _dx_real_int(0x1a, &regs);

   /* Save registers before overwritten by compiler usage of registers */
   ax = regs.eax & 0xffff;
   flags = regs.flags;

   /* First check if CARRY FLAG Set, if so, error has occurred */
   if ((flags & CARRY_FLAG) == 0) {

      /* Get Return code from BIOS */
      ret_status = HIGH_BYTE(ax);
   }
   else {
      ret_status = NOT_SUCCESSFUL;
   }

   return (ret_status);
}

/****************************************************************************/
/*                                                                          */
/*  READ_CONFIGURATION_BYTE                                                 */
/*                                                                          */
/* Purpose: Reads a byte from the configuration space of a specific device  */
/*                                                                          */
/* Inputs:                                                                  */
/*                                                                          */
/*    byte bus_number                                                       */
/*       PCI bus to read configuration data from                            */
/*                                                                          */
/*    byte device_and_function                                              */
/*       Device Number in upper 5 bits, Function Number in lower 3 bits     */
/*                                                                          */
/*    byte register_number                                                  */
/*       Register Number of configuration space to read                     */
/*                                                                          */
/* Outputs:                                                                 */
/*                                                                          */
/*    byte *byte_read                                                       */
/*       Byte read from Configuration Space                                 */
/*                                                                          */
/*    Return Value - Indicates presence of device                           */
/*       SUCCESSFUL - Device found                                          */
/*       NOT_SUCCESSFUL - BIOS error                                        */
/*       BAD_REGISTER_NUMBER - Invalid Register Number                      */
/*                                                                          */
/****************************************************************************/

int read_configuration_byte(byte bus_number,
                            byte device_and_function,
                            byte register_number,
                            byte *byte_read)
{
   int ret_status; /* Function Return Status */
   dword data;

   /* Call read_configuration_area function with byte data */
   ret_status = read_configuration_area(READ_CONFIG_BYTE,
                                        bus_number,
                                        device_and_function,
                                        register_number,
                                        &data);
   if (ret_status == SUCCESSFUL) {

      /* Extract byte */
      *byte_read = data & 0xff;
   }

   return (ret_status);
}


/****************************************************************************/
/*                                                                          */
/*  READ_CONFIGURATION_WORD                                                 */
/*                                                                          */
/* Purpose: Reads a word from the configuration space of a specific device  */
/*                                                                          */
/* Inputs:                                                                  */
/*                                                                          */
/*    byte bus_number                                                       */
/*       PCI bus to read configuration data from                            */
/*                                                                          */
/*    byte device_and_function                                              */
/*       Device Number in upper 5 bits, Function Number in lower 3 bits     */
/*                                                                          */
/*    byte register_number                                                  */
/*       Register Number of configuration space to read                     */
/*                                                                          */
/* Outputs:                                                                 */
/*                                                                          */
/*    word *word_read                                                       */
/*       Word read from Configuration Space                                 */
/*                                                                          */
/*    Return Value - Indicates presence of device                           */
/*       SUCCESSFUL - Device found                                          */
/*       NOT_SUCCESSFUL - BIOS error                                        */
/*       BAD_REGISTER_NUMBER - Invalid Register Number                      */
/*                                                                          */
/****************************************************************************/

int read_configuration_word(byte bus_number,
                            byte device_and_function,
                            byte register_number,
                            word *word_read)
{
   int ret_status; /* Function Return Status */
   dword data;

   /* Call read_configuration_area function with word data */
   ret_status = read_configuration_area(READ_CONFIG_WORD,
                                        bus_number,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -