• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 Implementation for SMBus DXE driver entry point and SMBus Host
3 Controller protocol.
4 
5 Copyright (c) 2013-2015 Intel Corporation.
6 
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution.  The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11 
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 
15 **/
16 #include "CommonHeader.h"
17 
18 #include "DxeQNCSmbus.h"
19 
20 //
21 // Interface defintion of SMBUS Host Controller Protocol.
22 //
23 EFI_SMBUS_HC_PROTOCOL mSmbusHc = {
24   SmbusExecute,
25   SmbusArpDevice,
26   SmbusGetArpMap,
27   SmbusNotify
28 };
29 
30 //
31 // Handle to install SMBus Host Controller protocol.
32 //
33 EFI_HANDLE                   mSmbusHcHandle = NULL;
34 UINT8                        mDeviceMapEntries = 0;
35 EFI_SMBUS_DEVICE_MAP         mDeviceMap[MAX_SMBUS_DEVICES];
36 UINT8                        mPlatformNumRsvd = 0;
37 UINT8                        *mPlatformAddrRsvd = NULL;
38 
39 //
40 // These addresses are reserved by the SMBus 2.0 specification
41 //
42 UINT8    mReservedAddress[SMBUS_NUM_RESERVED] = {
43   0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x18, 0x50, 0x6E, 0xC2,
44   0xF0, 0xF2, 0xF4, 0xF6, 0xF8, 0xFA, 0xFC, 0xFE
45 };
46 
47 
48 /**
49   Gets Io port base address of Smbus Host Controller.
50 
51   This internal function depends on a feature flag named PcdIchSmbusFixedIoPortBaseAddress
52   to retrieve Smbus Io port base. If that feature flag is true, it will get Smbus Io port base
53   address from a preset Pcd entry named PcdIchSmbusIoPortBaseAddress; otherwise, it will always
54   read Pci configuration space to get that value in each Smbus bus transaction.
55 
56   @return The Io port base address of Smbus host controller.
57 
58 **/
59 UINTN
GetSmbusIoPortBaseAddress(VOID)60 GetSmbusIoPortBaseAddress (
61   VOID
62   )
63 {
64   UINTN     IoPortBaseAddress;
65 
66   if (FeaturePcdGet (PcdSmbaIoBaseAddressFixed)) {
67     IoPortBaseAddress = (UINTN) PcdGet16 (PcdSmbaIoBaseAddress);
68   } else {
69     IoPortBaseAddress = (UINTN) LpcPciCfg32 (R_QNC_LPC_SMBUS_BASE) & B_QNC_LPC_SMBUS_BASE_MASK;
70   }
71 
72   //
73   // Make sure that the IO port base address has been properly set.
74   //
75   ASSERT (IoPortBaseAddress != 0);
76 
77   return IoPortBaseAddress;
78 }
79 
80 
81 VOID
InitializeInternal()82 InitializeInternal (
83   )
84 {
85   UINTN     IoPortBaseAddress;
86 
87   IoPortBaseAddress = GetSmbusIoPortBaseAddress ();
88 
89   //
90   // Step1: Enable QNC SMBUS I/O space.
91   //
92   LpcPciCfg32Or(R_QNC_LPC_SMBUS_BASE, B_QNC_LPC_SMBUS_BASE_EN);
93 
94   //
95   // Step2: Clear Status Register before anyone uses the interfaces.
96   //
97   IoWrite8 (IoPortBaseAddress + R_QNC_SMBUS_HSTS, B_QNC_SMBUS_HSTS_ALL);
98 
99   //
100   // Step3: Program the correct smbus clock
101   //
102   IoWrite8 (IoPortBaseAddress + R_QNC_SMBUS_HCLK, V_QNC_SMBUS_HCLK_100KHZ);
103 }
104 
105 
106 
107 
108 BOOLEAN
IsAddressAvailable(IN EFI_SMBUS_DEVICE_ADDRESS SlaveAddress)109 IsAddressAvailable (
110   IN      EFI_SMBUS_DEVICE_ADDRESS  SlaveAddress
111   )
112 {
113   UINT8         Index;
114 
115   //
116   // See if we have already assigned this address to a device
117   //
118   for (Index = 0; Index < mDeviceMapEntries; Index++) {
119     if (SlaveAddress.SmbusDeviceAddress ==
120          mDeviceMap[Index].SmbusDeviceAddress.SmbusDeviceAddress) {
121       return FALSE;
122     }
123   }
124 
125   //
126   // See if this address is claimed by a platform non-ARP-capable device
127   //
128   for (Index = 0; Index < mPlatformNumRsvd; Index++) {
129     if ((SlaveAddress.SmbusDeviceAddress << 1) == mPlatformAddrRsvd[Index]) {
130       return FALSE;
131     }
132   }
133 
134   //
135   // See if this is a reserved address
136   //
137   for (Index = 0; Index < SMBUS_NUM_RESERVED; Index++) {
138     if (SlaveAddress.SmbusDeviceAddress == (UINTN) mReservedAddress[Index]) {
139       return FALSE;
140     }
141   }
142 
143   return TRUE;
144 }
145 
146 
147 EFI_STATUS
GetNextAvailableAddress(IN EFI_SMBUS_DEVICE_ADDRESS * SlaveAddress)148 GetNextAvailableAddress (
149   IN EFI_SMBUS_DEVICE_ADDRESS  *SlaveAddress
150   )
151 {
152   for (SlaveAddress->SmbusDeviceAddress = 0x03;
153     SlaveAddress->SmbusDeviceAddress < 0x7F;
154     SlaveAddress->SmbusDeviceAddress++
155     ) {
156     if (IsAddressAvailable (*SlaveAddress)) {
157       return EFI_SUCCESS;
158     }
159   }
160 
161   return EFI_OUT_OF_RESOURCES;
162 }
163 
164 EFI_STATUS
SmbusPrepareToArp()165 SmbusPrepareToArp (
166   )
167 {
168   EFI_SMBUS_DEVICE_ADDRESS  SlaveAddress;
169   EFI_STATUS                Status;
170   UINTN                     Length;
171   UINT8                     Buffer;
172 
173   SlaveAddress.SmbusDeviceAddress = SMBUS_ADDRESS_ARP;
174   Length = 1;
175   Buffer = SMBUS_DATA_PREPARE_TO_ARP;
176 
177   Status = Execute (
178              SlaveAddress,
179              0,
180              EfiSmbusSendByte,
181              TRUE,
182              &Length,
183              &Buffer
184              );
185   return Status;
186 }
187 
188 EFI_STATUS
SmbusGetUdidGeneral(IN OUT EFI_SMBUS_DEVICE_MAP * DeviceMap)189 SmbusGetUdidGeneral (
190   IN OUT  EFI_SMBUS_DEVICE_MAP  *DeviceMap
191   )
192 {
193   EFI_SMBUS_DEVICE_ADDRESS      SlaveAddress;
194   EFI_STATUS                    Status;
195   UINTN                         Length;
196   UINT8                         Buffer[SMBUS_GET_UDID_LENGTH];
197 
198   SlaveAddress.SmbusDeviceAddress = SMBUS_ADDRESS_ARP;
199   Length = SMBUS_GET_UDID_LENGTH;
200 
201   Status = Execute (
202              SlaveAddress,
203              SMBUS_DATA_GET_UDID_GENERAL,
204              EfiSmbusReadBlock,
205              TRUE,
206              &Length,
207              Buffer
208              );
209 
210   if (!EFI_ERROR(Status)) {
211     if (Length == SMBUS_GET_UDID_LENGTH) {
212       DeviceMap->SmbusDeviceUdid.DeviceCapabilities = Buffer[0];
213       DeviceMap->SmbusDeviceUdid.VendorRevision = Buffer[1];
214       DeviceMap->SmbusDeviceUdid.VendorId = (UINT16)((Buffer[2] << 8) + Buffer[3]);
215       DeviceMap->SmbusDeviceUdid.DeviceId = (UINT16)((Buffer[4] << 8) + Buffer[5]);
216       DeviceMap->SmbusDeviceUdid.Interface = (UINT16)((Buffer[6] << 8) + Buffer[7]);
217       DeviceMap->SmbusDeviceUdid.SubsystemVendorId = (UINT16)((Buffer[8] << 8) + Buffer[9]);
218       DeviceMap->SmbusDeviceUdid.SubsystemDeviceId = (UINT16)((Buffer[10] << 8) + Buffer[11]);
219       DeviceMap->SmbusDeviceUdid.VendorSpecificId = (UINT32)((Buffer[12] << 24) + (Buffer[13] << 16) + (Buffer[14] << 8) + Buffer[15]);
220       DeviceMap->SmbusDeviceAddress.SmbusDeviceAddress = (UINT8)(Buffer[16] >> 1);
221     } else {
222       Status = EFI_DEVICE_ERROR;
223     }
224   }
225 
226   return Status;
227 }
228 
229 EFI_STATUS
SmbusAssignAddress(IN OUT EFI_SMBUS_DEVICE_MAP * DeviceMap)230 SmbusAssignAddress (
231   IN OUT  EFI_SMBUS_DEVICE_MAP  *DeviceMap
232   )
233 {
234   EFI_SMBUS_DEVICE_ADDRESS      SlaveAddress;
235   EFI_STATUS                    Status;
236   UINTN                         Length;
237   UINT8                         Buffer[SMBUS_GET_UDID_LENGTH];
238 
239   Buffer[0] = DeviceMap->SmbusDeviceUdid.DeviceCapabilities;
240   Buffer[1] = DeviceMap->SmbusDeviceUdid.VendorRevision;
241   Buffer[2] = (UINT8)(DeviceMap->SmbusDeviceUdid.VendorId >> 8);
242   Buffer[3] = (UINT8)(DeviceMap->SmbusDeviceUdid.VendorId);
243   Buffer[4] = (UINT8)(DeviceMap->SmbusDeviceUdid.DeviceId >> 8);
244   Buffer[5] = (UINT8)(DeviceMap->SmbusDeviceUdid.DeviceId);
245   Buffer[6] = (UINT8)(DeviceMap->SmbusDeviceUdid.Interface >> 8);
246   Buffer[7] = (UINT8)(DeviceMap->SmbusDeviceUdid.Interface);
247   Buffer[8] = (UINT8)(DeviceMap->SmbusDeviceUdid.SubsystemVendorId >> 8);
248   Buffer[9] = (UINT8)(DeviceMap->SmbusDeviceUdid.SubsystemVendorId);
249   Buffer[10] = (UINT8)(DeviceMap->SmbusDeviceUdid.SubsystemDeviceId >> 8);
250   Buffer[11] = (UINT8)(DeviceMap->SmbusDeviceUdid.SubsystemDeviceId);
251   Buffer[12] = (UINT8)(DeviceMap->SmbusDeviceUdid.VendorSpecificId >> 24);
252   Buffer[13] = (UINT8)(DeviceMap->SmbusDeviceUdid.VendorSpecificId >> 16);
253   Buffer[14] = (UINT8)(DeviceMap->SmbusDeviceUdid.VendorSpecificId >> 8);
254   Buffer[15] = (UINT8)(DeviceMap->SmbusDeviceUdid.VendorSpecificId);
255   Buffer[16] = (UINT8)(DeviceMap->SmbusDeviceAddress.SmbusDeviceAddress << 1);
256 
257   SlaveAddress.SmbusDeviceAddress = SMBUS_ADDRESS_ARP;
258   Length = SMBUS_GET_UDID_LENGTH;
259 
260   Status = Execute (
261              SlaveAddress,
262              SMBUS_DATA_ASSIGN_ADDRESS,
263              EfiSmbusWriteBlock,
264              TRUE,
265              &Length,
266              Buffer
267              );
268   return Status;
269 }
270 
271 
272 EFI_STATUS
SmbusFullArp()273 SmbusFullArp (
274   )
275 {
276   EFI_STATUS              Status;
277   EFI_SMBUS_DEVICE_MAP    *CurrentDeviceMap;
278 
279   Status = SmbusPrepareToArp ();
280   if (EFI_ERROR(Status)) {
281     if (Status == EFI_DEVICE_ERROR) {
282       //
283       //  ARP is complete
284       //
285       return EFI_SUCCESS;
286     } else {
287       return Status;
288     }
289   }
290 
291   //
292   //  Main loop to ARP all ARP-capable devices
293   //
294   do {
295     CurrentDeviceMap = &mDeviceMap[mDeviceMapEntries];
296     Status = SmbusGetUdidGeneral (CurrentDeviceMap);
297     if (EFI_ERROR(Status)) {
298       break;
299     }
300 
301     if (CurrentDeviceMap->SmbusDeviceAddress.SmbusDeviceAddress == (0xFF >> 1)) {
302       //
303       // If address is unassigned, assign it
304       //
305       Status = GetNextAvailableAddress (
306                  &CurrentDeviceMap->SmbusDeviceAddress
307                  );
308       if (EFI_ERROR(Status)) {
309         return EFI_OUT_OF_RESOURCES;
310       }
311     } else if (((CurrentDeviceMap->SmbusDeviceUdid.DeviceCapabilities) & 0xC0) != 0) {
312       //
313       // if address is not fixed, check if the current address is available
314       //
315       if (!IsAddressAvailable (
316              CurrentDeviceMap->SmbusDeviceAddress
317              )) {
318         //
319         // if currently assigned address is already used, get a new one
320         //
321         Status = GetNextAvailableAddress (
322                    &CurrentDeviceMap->SmbusDeviceAddress
323                    );
324         if (EFI_ERROR(Status)) {
325           return EFI_OUT_OF_RESOURCES;
326         }
327       }
328     }
329 
330     Status = SmbusAssignAddress (CurrentDeviceMap);
331     if (EFI_ERROR(Status)) {
332       //
333       // If there was a device error, just continue on and try again.
334       // Other errors should be reported.
335       //
336       if (Status != EFI_DEVICE_ERROR) {
337         return Status;
338       }
339     } else {
340       //
341       // If there was no error, the address was assigned and we must update our
342       // records.
343       //
344       mDeviceMapEntries++;
345     }
346 
347   } while (mDeviceMapEntries < MAX_SMBUS_DEVICES);
348 
349   return EFI_SUCCESS;
350 }
351 
352 
353 EFI_STATUS
SmbusDirectedArp(IN EFI_SMBUS_UDID * SmbusUdid,IN OUT EFI_SMBUS_DEVICE_ADDRESS * SlaveAddress)354 SmbusDirectedArp (
355   IN      EFI_SMBUS_UDID            *SmbusUdid,
356   IN OUT  EFI_SMBUS_DEVICE_ADDRESS  *SlaveAddress
357   )
358 {
359   EFI_STATUS                        Status;
360   EFI_SMBUS_DEVICE_MAP              *CurrentDeviceMap;
361 
362   if (mDeviceMapEntries >= MAX_SMBUS_DEVICES) {
363     return EFI_OUT_OF_RESOURCES;
364   }
365 
366   CurrentDeviceMap = &mDeviceMap[mDeviceMapEntries];
367 
368   //
369   // Find an available address to assign
370   //
371   Status = GetNextAvailableAddress (
372              &CurrentDeviceMap->SmbusDeviceAddress
373              );
374   if (EFI_ERROR(Status)) {
375     return EFI_OUT_OF_RESOURCES;
376   }
377 
378   CurrentDeviceMap->SmbusDeviceUdid.DeviceCapabilities  = SmbusUdid->DeviceCapabilities;
379   CurrentDeviceMap->SmbusDeviceUdid.DeviceId            = SmbusUdid->DeviceId;
380   CurrentDeviceMap->SmbusDeviceUdid.Interface           = SmbusUdid->Interface;
381   CurrentDeviceMap->SmbusDeviceUdid.SubsystemDeviceId   = SmbusUdid->SubsystemDeviceId;
382   CurrentDeviceMap->SmbusDeviceUdid.SubsystemVendorId   = SmbusUdid->SubsystemVendorId;
383   CurrentDeviceMap->SmbusDeviceUdid.VendorId            = SmbusUdid->VendorId;
384   CurrentDeviceMap->SmbusDeviceUdid.VendorRevision      = SmbusUdid->VendorRevision;
385   CurrentDeviceMap->SmbusDeviceUdid.VendorSpecificId    = SmbusUdid->VendorSpecificId;
386 
387   Status = SmbusAssignAddress (CurrentDeviceMap);
388   if (EFI_ERROR(Status)) {
389     return Status;
390   }
391 
392   mDeviceMapEntries++;
393   SlaveAddress->SmbusDeviceAddress = CurrentDeviceMap->SmbusDeviceAddress.SmbusDeviceAddress;
394 
395   return EFI_SUCCESS;
396 }
397 
398 
399 
400 /**
401   Executes an SMBus operation to an SMBus controller. Returns when either the command has been
402   executed or an error is encountered in doing the operation.
403 
404   The Execute() function provides a standard way to execute an operation as defined in the System
405   Management Bus (SMBus) Specification. The resulting transaction will be either that the SMBus
406   slave devices accept this transaction or that this function returns with error.
407 
408   @param  This                    A pointer to the EFI_SMBUS_HC_PROTOCOL instance.
409   @param  SlaveAddress            The SMBus slave address of the device with which to communicate.
410   @param  Command                 This command is transmitted by the SMBus host controller to the
411                                   SMBus slave device and the interpretation is SMBus slave device
412                                   specific. It can mean the offset to a list of functions inside an
413                                   SMBus slave device. Not all operations or slave devices support
414                                   this command's registers.
415   @param  Operation               Signifies which particular SMBus hardware protocol instance that
416                                   it will use to execute the SMBus transactions. This SMBus
417                                   hardware protocol is defined by the SMBus Specification and is
418                                   not related to EFI.
419   @param  PecCheck                Defines if Packet Error Code (PEC) checking is required for this
420                                   operation.
421   @param  Length                  Signifies the number of bytes that this operation will do. The
422                                   maximum number of bytes can be revision specific and operation
423                                   specific. This field will contain the actual number of bytes that
424                                   are executed for this operation. Not all operations require this
425                                   argument.
426   @param  Buffer                  Contains the value of data to execute to the SMBus slave device.
427                                   Not all operations require this argument. The length of this
428                                   buffer is identified by Length.
429 
430   @retval EFI_SUCCESS             The last data that was returned from the access matched the poll
431                                   exit criteria.
432   @retval EFI_CRC_ERROR           Checksum is not correct (PEC is incorrect).
433   @retval EFI_TIMEOUT             Timeout expired before the operation was completed. Timeout is
434                                   determined by the SMBus host controller device.
435   @retval EFI_OUT_OF_RESOURCES    The request could not be completed due to a lack of resources.
436   @retval EFI_DEVICE_ERROR        The request was not completed because a failure that was
437                                   reflected in the Host Status Register bit. Device errors are a
438                                   result of a transaction collision, illegal command field,
439                                   unclaimed cycle (host initiated), or bus errors (collisions).
440   @retval EFI_INVALID_PARAMETER   Operation is not defined in EFI_SMBUS_OPERATION.
441   @retval EFI_INVALID_PARAMETER   Length/Buffer is NULL for operations except for EfiSmbusQuickRead
442                                   and EfiSmbusQuickWrite. Length is outside the range of valid
443                                   values.
444   @retval EFI_UNSUPPORTED         The SMBus operation or PEC is not supported.
445   @retval EFI_BUFFER_TOO_SMALL    Buffer is not sufficient for this operation.
446 
447 **/
448 EFI_STATUS
449 EFIAPI
SmbusExecute(IN CONST EFI_SMBUS_HC_PROTOCOL * This,IN CONST EFI_SMBUS_DEVICE_ADDRESS SlaveAddress,IN CONST EFI_SMBUS_DEVICE_COMMAND Command,IN CONST EFI_SMBUS_OPERATION Operation,IN CONST BOOLEAN PecCheck,IN OUT UINTN * Length,IN OUT VOID * Buffer)450 SmbusExecute (
451   IN CONST  EFI_SMBUS_HC_PROTOCOL     *This,
452   IN CONST  EFI_SMBUS_DEVICE_ADDRESS  SlaveAddress,
453   IN CONST  EFI_SMBUS_DEVICE_COMMAND  Command,
454   IN CONST  EFI_SMBUS_OPERATION       Operation,
455   IN CONST  BOOLEAN                   PecCheck,
456   IN OUT    UINTN                     *Length,
457   IN OUT    VOID                      *Buffer
458   )
459 {
460   InitializeInternal ();
461   return Execute (
462            SlaveAddress,
463            Command,
464            Operation,
465            PecCheck,
466            Length,
467            Buffer
468            );
469 }
470 
471 /**
472   Sets the SMBus slave device addresses for the device with a given unique ID or enumerates the
473   entire bus.
474 
475   The ArpDevice() function provides a standard way for a device driver to enumerate the entire
476   SMBus or specific devices on the bus.
477 
478   @param  This                    A pointer to the EFI_SMBUS_HC_PROTOCOL instance.
479   @param  ArpAll                  A Boolean expression that indicates if the host drivers need to
480                                   enumerate all the devices or enumerate only the device that is
481                                   identified by SmbusUdid. If ArpAll is TRUE, SmbusUdid and
482                                   SlaveAddress are optional. If ArpAll is FALSE, ArpDevice will
483                                   enumerate SmbusUdid and the address will be at SlaveAddress.
484   @param  SmbusUdid               The Unique Device Identifier (UDID) that is associated with this
485                                   device.
486   @param  SlaveAddress            The SMBus slave address that is associated with an SMBus UDID.
487 
488   @retval EFI_SUCCESS             The last data that was returned from the access matched the poll
489                                   exit criteria.
490   @retval EFI_CRC_ERROR           Checksum is not correct (PEC is incorrect).
491   @retval EFI_TIMEOUT             Timeout expired before the operation was completed. Timeout is
492                                   determined by the SMBus host controller device.
493   @retval EFI_OUT_OF_RESOURCES    The request could not be completed due to a lack of resources.
494   @retval EFI_DEVICE_ERROR        The request was not completed because a failure that was
495                                   reflected in the Host Status Register bit. Device errors are a
496                                   result of a transaction collision, illegal command field,
497                                   unclaimed cycle (host initiated), or bus errors (collisions).
498   @retval EFI_UNSUPPORTED         The corresponding SMBus operation is not supported.
499 
500 **/
501 EFI_STATUS
502 EFIAPI
SmbusArpDevice(IN CONST EFI_SMBUS_HC_PROTOCOL * This,IN BOOLEAN ArpAll,IN EFI_SMBUS_UDID * SmbusUdid,OPTIONAL IN OUT EFI_SMBUS_DEVICE_ADDRESS * SlaveAddress OPTIONAL)503 SmbusArpDevice (
504   IN CONST  EFI_SMBUS_HC_PROTOCOL     *This,
505   IN        BOOLEAN                   ArpAll,
506   IN        EFI_SMBUS_UDID            *SmbusUdid,   OPTIONAL
507   IN OUT    EFI_SMBUS_DEVICE_ADDRESS  *SlaveAddress OPTIONAL
508   )
509 {
510     InitializeInternal ();
511 
512     if (ArpAll) {
513     return SmbusFullArp ();
514   } else {
515     if ((SmbusUdid == NULL) || (SlaveAddress == NULL)) {
516       return EFI_INVALID_PARAMETER;
517     }
518     return SmbusDirectedArp ((EFI_SMBUS_UDID *)SmbusUdid, SlaveAddress);
519   }
520 }
521 
522 /**
523   Returns a pointer to the Address Resolution Protocol (ARP) map that contains the ID/address pair
524   of the slave devices that were enumerated by the SMBus host controller driver.
525 
526   The GetArpMap() function returns the mapping of all the SMBus devices that were enumerated by the
527   SMBus host driver.
528 
529   @param  This                    A pointer to the EFI_SMBUS_HC_PROTOCOL instance.
530   @param  Length                  Size of the buffer that contains the SMBus device map.
531   @param  SmbusDeviceMap          The pointer to the device map as enumerated by the SMBus
532                                   controller driver.
533 
534   @retval EFI_SUCCESS             The SMBus returned the current device map.
535   @retval EFI_UNSUPPORTED         The corresponding operation is not supported.
536 
537 **/
538 EFI_STATUS
539 EFIAPI
SmbusGetArpMap(IN CONST EFI_SMBUS_HC_PROTOCOL * This,IN OUT UINTN * Length,IN OUT EFI_SMBUS_DEVICE_MAP ** SmbusDeviceMap)540 SmbusGetArpMap (
541   IN CONST  EFI_SMBUS_HC_PROTOCOL   *This,
542   IN OUT    UINTN                   *Length,
543   IN OUT    EFI_SMBUS_DEVICE_MAP    **SmbusDeviceMap
544   )
545 {
546   *Length = mDeviceMapEntries;
547   *SmbusDeviceMap = mDeviceMap;
548   return EFI_SUCCESS;
549 }
550 
551 
552 /**
553   Allows a device driver to register for a callback when the bus driver detects a state that it
554   needs to propagate to other drivers that are registered for a callback.
555 
556   The Notify() function registers all the callback functions to allow the bus driver to call these
557   functions when the SlaveAddress/Data pair happens.
558   If NotifyFunction is NULL, then ASSERT ().
559 
560   @param  This                    A pointer to the EFI_SMBUS_HC_PROTOCOL instance.
561   @param  SlaveAddress            The SMBUS hardware address to which the SMBUS device is
562                                   preassigned or allocated.
563   @param  Data                    Data of the SMBus host notify command that the caller wants to be
564                                   called.
565   @param  NotifyFunction          The function to call when the bus driver detects the SlaveAddress
566                                   and Data pair.
567 
568   @retval EFI_SUCCESS             NotifyFunction was registered.
569   @retval EFI_UNSUPPORTED         The corresponding operation is not supported.
570 
571 **/
572 EFI_STATUS
573 EFIAPI
SmbusNotify(IN CONST EFI_SMBUS_HC_PROTOCOL * This,IN CONST EFI_SMBUS_DEVICE_ADDRESS SlaveAddress,IN CONST UINTN Data,IN CONST EFI_SMBUS_NOTIFY_FUNCTION NotifyFunction)574 SmbusNotify (
575   IN CONST  EFI_SMBUS_HC_PROTOCOL     *This,
576   IN CONST  EFI_SMBUS_DEVICE_ADDRESS  SlaveAddress,
577   IN CONST  UINTN                     Data,
578   IN CONST  EFI_SMBUS_NOTIFY_FUNCTION NotifyFunction
579   )
580 {
581   return EFI_UNSUPPORTED;
582 }
583 
584 /**
585   Entry point to the DXE Driver that produces the SMBus Host Controller Protocol.
586 
587   @param  ImageHandle      ImageHandle of the loaded driver.
588   @param  SystemTable      Pointer to the EFI System Table.
589 
590   @retval EFI_SUCCESS      The entry point of SMBus DXE driver is executed successfully.
591   @retval !EFI_SUCESS      Some error occurs in the entry point of SMBus DXE driver.
592 
593 **/
594 EFI_STATUS
595 EFIAPI
InitializeQNCSmbus(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)596 InitializeQNCSmbus (
597   IN EFI_HANDLE            ImageHandle,
598   IN EFI_SYSTEM_TABLE      *SystemTable
599   )
600 {
601   EFI_STATUS    Status;
602 
603   mPlatformNumRsvd = (UINT8)PcdGet32 (PcdPlatformSmbusAddrNum);
604   mPlatformAddrRsvd = (UINT8 *)(UINTN) PcdGet64 (PcdPlatformSmbusAddrTable);
605 
606   //
607   // Install SMBus Host Controller protocol interface.
608   //
609   Status = gBS->InstallMultipleProtocolInterfaces (
610                   &mSmbusHcHandle,
611                   &gEfiSmbusHcProtocolGuid,
612                   &mSmbusHc,
613                   NULL
614                   );
615   ASSERT_EFI_ERROR (Status);
616 
617   return Status;
618 }
619