Decimal value of the Per Process MMIO space length.
 Users:         https://github.com/ibm-capi/libcxl
 
-What:           /sys/class/cxl/<afu>m/pp_mmio_off
+What:           /sys/class/cxl/<afu>m/pp_mmio_off (not in a guest)
 Date:           September 2014
 Contact:        linuxppc-dev@lists.ozlabs.org
 Description:    read only
                 Identifies the revision level of the PSL.
 Users:         https://github.com/ibm-capi/libcxl
 
-What:           /sys/class/cxl/<card>/base_image
+What:           /sys/class/cxl/<card>/base_image (not in a guest)
 Date:           September 2014
 Contact:        linuxppc-dev@lists.ozlabs.org
 Description:    read only
                 during the initial program load.
 Users:         https://github.com/ibm-capi/libcxl
 
-What:           /sys/class/cxl/<card>/image_loaded
+What:           /sys/class/cxl/<card>/image_loaded (not in a guest)
 Date:           September 2014
 Contact:        linuxppc-dev@lists.ozlabs.org
 Description:    read only
                 onto the card.
 Users:         https://github.com/ibm-capi/libcxl
 
-What:           /sys/class/cxl/<card>/load_image_on_perst
+What:           /sys/class/cxl/<card>/load_image_on_perst (not in a guest)
 Date:           December 2014
 Contact:        linuxppc-dev@lists.ozlabs.org
 Description:    read/write
                 to reload the FPGA depending on load_image_on_perst.
 Users:         https://github.com/ibm-capi/libcxl
 
-What:          /sys/class/cxl/<card>/perst_reloads_same_image
+What:          /sys/class/cxl/<card>/perst_reloads_same_image (not in a guest)
 Date:          July 2015
 Contact:       linuxppc-dev@lists.ozlabs.org
 Description:   read/write
 
        return 0;
 }
 
+static bool guest_support_attributes(const char *attr_name,
+                                    enum cxl_attrs type)
+{
+       switch (type) {
+       case CXL_ADAPTER_ATTRS:
+               if ((strcmp(attr_name, "base_image") == 0) ||
+                       (strcmp(attr_name, "load_image_on_perst") == 0) ||
+                       (strcmp(attr_name, "perst_reloads_same_image") == 0) ||
+                       (strcmp(attr_name, "image_loaded") == 0))
+                       return false;
+               break;
+       case CXL_AFU_MASTER_ATTRS:
+               if ((strcmp(attr_name, "pp_mmio_off") == 0))
+                       return false;
+               break;
+       case CXL_AFU_ATTRS:
+               break;
+       default:
+               break;
+       }
+
+       return true;
+}
+
 static int activate_afu_directed(struct cxl_afu *afu)
 {
        int rc;
        .ack_irq = guest_ack_irq,
        .attach_process = guest_attach_process,
        .detach_process = guest_detach_process,
+       .support_attributes = guest_support_attributes,
        .link_ok = guest_link_ok,
        .release_afu = guest_release_afu,
        .afu_read_err_buffer = guest_afu_read_err_buffer,
 
        if (irqs_max < afu->pp_irqs)
                return -EINVAL;
 
-       if (irqs_max > afu->adapter->user_irqs)
-               return -EINVAL;
+       if (cpu_has_feature(CPU_FTR_HVMODE)) {
+               if (irqs_max > afu->adapter->user_irqs)
+                       return -EINVAL;
+       } else {
+               /* pHyp sets a per-AFU limit */
+               if (irqs_max > afu->guest->max_ints)
+                       return -EINVAL;
+       }
 
        afu->irqs_max = irqs_max;
        return count;
 
 int cxl_sysfs_adapter_add(struct cxl *adapter)
 {
+       struct device_attribute *dev_attr;
        int i, rc;
 
        for (i = 0; i < ARRAY_SIZE(adapter_attrs); i++) {
-               if ((rc = device_create_file(&adapter->dev, &adapter_attrs[i])))
-                       goto err;
+               dev_attr = &adapter_attrs[i];
+               if (cxl_ops->support_attributes(dev_attr->attr.name,
+                                               CXL_ADAPTER_ATTRS)) {
+                       if ((rc = device_create_file(&adapter->dev, dev_attr)))
+                               goto err;
+               }
        }
        return 0;
 err:
-       for (i--; i >= 0; i--)
-               device_remove_file(&adapter->dev, &adapter_attrs[i]);
+       for (i--; i >= 0; i--) {
+               dev_attr = &adapter_attrs[i];
+               if (cxl_ops->support_attributes(dev_attr->attr.name,
+                                               CXL_ADAPTER_ATTRS))
+                       device_remove_file(&adapter->dev, dev_attr);
+       }
        return rc;
 }
+
 void cxl_sysfs_adapter_remove(struct cxl *adapter)
 {
+       struct device_attribute *dev_attr;
        int i;
 
-       for (i = 0; i < ARRAY_SIZE(adapter_attrs); i++)
-               device_remove_file(&adapter->dev, &adapter_attrs[i]);
+       for (i = 0; i < ARRAY_SIZE(adapter_attrs); i++) {
+               dev_attr = &adapter_attrs[i];
+               if (cxl_ops->support_attributes(dev_attr->attr.name,
+                                               CXL_ADAPTER_ATTRS))
+                       device_remove_file(&adapter->dev, dev_attr);
+       }
 }
 
 struct afu_config_record {
        /*
         * Export raw AFU PCIe like config record. For now this is read only by
         * root - we can expand that later to be readable by non-root and maybe
-        * even writable provided we have a good use-case. Once we suport
+        * even writable provided we have a good use-case. Once we support
         * exposing AFUs through a virtual PHB they will get that for free from
         * Linux' PCI infrastructure, but until then it's not clear that we
         * need it for anything since the main use case is just identifying
 
 void cxl_sysfs_afu_remove(struct cxl_afu *afu)
 {
+       struct device_attribute *dev_attr;
        struct afu_config_record *cr, *tmp;
        int i;
 
        if (afu->eb_len)
                device_remove_bin_file(&afu->dev, &afu->attr_eb);
 
-       for (i = 0; i < ARRAY_SIZE(afu_attrs); i++)
-               device_remove_file(&afu->dev, &afu_attrs[i]);
+       for (i = 0; i < ARRAY_SIZE(afu_attrs); i++) {
+               dev_attr = &afu_attrs[i];
+               if (cxl_ops->support_attributes(dev_attr->attr.name,
+                                               CXL_AFU_ATTRS))
+                       device_remove_file(&afu->dev, &afu_attrs[i]);
+       }
 
        list_for_each_entry_safe(cr, tmp, &afu->crs, list) {
                sysfs_remove_bin_file(&cr->kobj, &cr->config_attr);
 
 int cxl_sysfs_afu_add(struct cxl_afu *afu)
 {
+       struct device_attribute *dev_attr;
        struct afu_config_record *cr;
        int i, rc;
 
        INIT_LIST_HEAD(&afu->crs);
 
        for (i = 0; i < ARRAY_SIZE(afu_attrs); i++) {
-               if ((rc = device_create_file(&afu->dev, &afu_attrs[i])))
-                       goto err;
+               dev_attr = &afu_attrs[i];
+               if (cxl_ops->support_attributes(dev_attr->attr.name,
+                                               CXL_AFU_ATTRS)) {
+                       if ((rc = device_create_file(&afu->dev, &afu_attrs[i])))
+                               goto err;
+               }
        }
 
        /* conditionally create the add the binary file for error info buffer */
        /* reset the eb_len as we havent created the bin attr */
        afu->eb_len = 0;
 
-       for (i--; i >= 0; i--)
+       for (i--; i >= 0; i--) {
+               dev_attr = &afu_attrs[i];
+               if (cxl_ops->support_attributes(dev_attr->attr.name,
+                                               CXL_AFU_ATTRS))
                device_remove_file(&afu->dev, &afu_attrs[i]);
+       }
        return rc;
 }
 
 int cxl_sysfs_afu_m_add(struct cxl_afu *afu)
 {
+       struct device_attribute *dev_attr;
        int i, rc;
 
        for (i = 0; i < ARRAY_SIZE(afu_master_attrs); i++) {
-               if ((rc = device_create_file(afu->chardev_m, &afu_master_attrs[i])))
-                       goto err;
+               dev_attr = &afu_master_attrs[i];
+               if (cxl_ops->support_attributes(dev_attr->attr.name,
+                                               CXL_AFU_MASTER_ATTRS)) {
+                       if ((rc = device_create_file(afu->chardev_m, &afu_master_attrs[i])))
+                               goto err;
+               }
        }
 
        return 0;
 
 err:
-       for (i--; i >= 0; i--)
-               device_remove_file(afu->chardev_m, &afu_master_attrs[i]);
+       for (i--; i >= 0; i--) {
+               dev_attr = &afu_master_attrs[i];
+               if (cxl_ops->support_attributes(dev_attr->attr.name,
+                                               CXL_AFU_MASTER_ATTRS))
+                       device_remove_file(afu->chardev_m, &afu_master_attrs[i]);
+       }
        return rc;
 }
 
 void cxl_sysfs_afu_m_remove(struct cxl_afu *afu)
 {
+       struct device_attribute *dev_attr;
        int i;
 
-       for (i = 0; i < ARRAY_SIZE(afu_master_attrs); i++)
-               device_remove_file(afu->chardev_m, &afu_master_attrs[i]);
+       for (i = 0; i < ARRAY_SIZE(afu_master_attrs); i++) {
+               dev_attr = &afu_master_attrs[i];
+               if (cxl_ops->support_attributes(dev_attr->attr.name,
+                                               CXL_AFU_MASTER_ATTRS))
+                       device_remove_file(afu->chardev_m, &afu_master_attrs[i]);
+       }
 }